Permalink
Browse files

add comments. remove extra line verbosity.

  • Loading branch information...
1 parent dea975e commit ccecb702f77f3bd4a3ebccfb642f93c735bafd5c @trevnorris committed Apr 2, 2012
Showing with 8 additions and 14 deletions.
  1. +8 −14 src/jquery.jqml.js
View
22 src/jquery.jqml.js
@@ -4,49 +4,43 @@
* MIT License: http://www.opensource.org/licenses/mit-license.php */
(function( $, document ) {
+
function createObj( elem ) {
var fragment = document.createDocumentFragment(),
i = 0, selector;
-
// check if is an element or array of elements
if ( typeof elem[0] == 'string' ) {
selector = document.createElement( elem[0] );
i = 1;
};
-
+ // loop through all elements in array
for ( ; i < elem.length; i++ ) {
-
// if array create new element
- if ( $.isArray( elem[i] ) ) {
- fragment.appendChild( createObj( elem[i] ) );
-
+ if ( $.isArray( elem[i] )) {
+ fragment.appendChild( createObj( elem[i] ));
// if object set element attributes
- } else if ( $.isPlainObject( elem[i] ) ) {
+ } else if ( $.isPlainObject( elem[i] )) {
+ // trick to have jQuery assign attributes without creating a new jQuery object
$.fn.attr.call( [selector], elem[i], true );
-
// if string or number insert text node
} else if ( typeof elem[i] == 'number' || typeof elem[i] == 'string' ) {
- fragment.appendChild( document.createTextNode( elem[i] ) );
-
+ fragment.appendChild( document.createTextNode( elem[i] ));
// if is an element append to fragment
} else if ( elem[i].nodeType ) {
fragment.appendChild( elem[i] );
};
};
-
// if a selector is set append children and return
if ( selector ) {
selector.appendChild( fragment );
return selector;
};
-
// otherwise return children of fragment
return fragment.childNodes;
};
$.jqml = function( arg ) {
-
// return new jQuery object of elements
- return $( createObj( arg ) );
+ return $( createObj( arg ));
};
})( jQuery, document );

0 comments on commit ccecb70

Please sign in to comment.