Permalink
Browse files

fix spacing and add comments

  • Loading branch information...
1 parent 0fe96de commit ff02cf1159390d18757402ad6a128896d9280b0e @trevnorris committed Mar 23, 2011
Showing with 31 additions and 18 deletions.
  1. +31 −18 src/core.js
View
@@ -3,37 +3,50 @@
* This document is licensed as free software under the terms of the
* MIT License: http://www.opensource.org/licenses/mit-license.php */
-(function($, document) {
- function createObj(elem) {
+(function( $, document ) {
+ function createObj( elem ) {
var fragment = document.createDocumentFragment(),
i = 0, selector;
- if (typeof elem[0] == 'string') {
- selector = document.createElement(elem[0]);
+ // check if is an element or array of elements
+ if ( typeof elem[0] == 'string' ) {
+ selector = document.createElement( elem[0] );
i = 1;
};
- for (; i < elem.length; i++) {
- if ($.isArray(elem[i])) {
- fragment.appendChild(createObj(elem[i]));
- } else if ($.isPlainObject(elem[i])) {
- $.fn.attr.call([selector], elem[i], true );
- } else if (typeof elem[i] == 'number' || typeof elem[i] == 'string') {
- fragment.appendChild(document.createTextNode(elem[i]));
- } else if (elem[i].nodeType) {
- fragment.appendChild(elem[i]);
+ for ( ; i < elem.length; i++ ) {
+
+ // if array create new element
+ if ( $.isArray( elem[i] ) ) {
+ fragment.appendChild( createObj( elem[i] ) );
+
+ // if object set element attributes
+ } else if ( $.isPlainObject( elem[i] ) ) {
+ $.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] ) );
+
+ // if is an element append to fragment
+ } else if ( elem[i].nodeType ) {
+ fragment.appendChild( elem[i] );
};
};
- if (selector) {
- selector.appendChild(fragment);
+ // 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 $(createObj(arg));
+ $.jqml = function( arg ) {
+
+ // return new jQuery object of elements
+ return $( createObj( arg ) );
};
-})(jQuery, document);
+})( jQuery, document );

0 comments on commit ff02cf1

Please sign in to comment.