I just invented PSEUDO Query!
var objects = $.pquery([
'##pquery##', // Initialize as PSEUDO Query Object
[document.body, 'css', [{'background-color':'#f00'}], 'append',
['##pquery##', // Helps distinguish array needing parsing from array of arguments
'<div />', 'text', 'LOL!']
],
['textarea', 'css', ['background-color', '#0f0']]
]);
...Is equivalent to:
var objects = [
$(document.body).css({background-color: '#f00'}).append($('<div />').text('LOL!')),
$('textarea').css('background-color', '#0f0')
];
Example image:
The point?
The point of this is in no way for added readability, but rather to provide a means to execute jQuery via PHP outputted JSON through Ajax. I believe this is going to make possible a nicely structured, and well defined output class for PHP, with very little code.
Ultimately, my goal is to have all clients long polling the server, to accept new Javascript and commands at any given moment. I plan to use jQuery for exactly what it is, as a framework, and extend any common commands/routines directly to it as extensions. Eventually I'll revise the structure to support $.method()
calls, without having to have a selector. I might need some ideas for the best way to go about that, without causing problems.
What are some concerns with this?
I wanted to avoid it, but I think I'm going to have to eval the Ajax array, for setting callback functions. Or I'll just pass it to a new <script />
element, and delete it after parse. Another option is to add some method to detect function structures, and pass the quoted code through new Function
. The last option I can think of, is to only allow predefined functions, which I've already extended to jQuery. I've heard it is bad to pass Javascript through through JSON, however I feel it is necessary if I'm going to be constructing new objects with bound events. I also feel that maybe this whole thing may be a little redundant if I'm going to just eval the code, but there's still the factor of easy output with PHP, which makes me want to continue with this extension. This is the area that I could really use the most advice and opinions about.
Any structural/general ideas or concerns about this? Or possibly some suggestions to just scrap the whole thing, and start with a different approach to the madness?