Highlight
Eval
/* Object to store things from dom elements */ var result = {} ; /* Function called on each element in jQuery stack, to collect attributes or style properties */ function collector() { var names = arguments , id_ = function ( el ) { return el.tagName + (el.id ? "#" + el.id : "") ; }, set_ = function ( obj ) { return obj || {} ; }, for_each_name = function ( callback ) { for ( var j = 0, l = names.length ; j < l ; j++ ) callback( names[j], j ) ; } ; /* the "plug" function called by MetaSocket parameter 'P' contains names and values for a single element, as mentioned in one or more '[]' in the current selector. MetaSocket is making 'P' for every element from the jQuery stack. object 'this', is instance of the single element, from the jQuery 'stack' */ return function ( P ) { var id = id_(this); for_each_name( function( name, idx ) { /* name is a single css property or attribute, mentioned in the selector if names given as arguments are wrong we stop here */ if ( undefined === P.nvo[name] ) return; result[id] = set_( result[id]); result[id][name] = P.nvo[name].value ; }); return false; /* signal to MetaSocket NOT to change the state of 'this' element */ } } /* select all elements having attribute "id" and "bottom" and "width!=auto" and "height!=auto" what is not mentioned in '[]' brackets will not be sent to the plug function in its 'P' argument */ $('[id][~bottom][~width!=auto][~height!=auto]', document.body ) /* give to MetaSocket, one plugin function, which is a collector for css properties we used in selector*/ .S( collector('bottom','width','height') ) ; if ( window.JSON ) show_ = JSON.stringify(result); /* this trivial example plug changes the elements matched */ var selector = "#specimen[~right]"; $(selector).css("right",10); $(selector).S( function (P) { show_ = "#" + this.id + ", right:" + P.let("right", 400) ; return true; // signal that values in P are to be 'mapped back' to 'this' element }); show_;
id="specimen"