From fd2af63bcab60693c79d482724db6ca291132e2a Mon Sep 17 00:00:00 2001 From: Oleg Date: Wed, 19 Dec 2012 20:26:49 +0400 Subject: [PATCH 01/51] Remove createSafeFragment helper --- src/manipulation.js | 63 ++++++++++----------------------------------- src/support.js | 10 +------ 2 files changed, 15 insertions(+), 58 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 5fec948cb..32b5b5f81 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -1,22 +1,4 @@ -function createSafeFragment( document ) { - var list = nodeNames.split( "|" ), - safeFrag = document.createDocumentFragment(); - - if ( safeFrag.createElement ) { - while ( list.length ) { - safeFrag.createElement( - list.pop() - ); - } - } - return safeFrag; -} - -var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|" + - "header|hgroup|mark|meter|nav|output|progress|section|summary|time|video", - rinlinejQuery = / jQuery\d+="(?:null|\d+)"/g, - rnoshimcache = new RegExp("<(?:" + nodeNames + ")[\\s/>]", "i"), - rleadingWhitespace = /^\s+/, +var rleadingWhitespace = /^\s+/, rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi, rtagName = /<([\w:]+)/, rtbody = /" ], col: [ 2, "", "
" ], td: [ 3, "" ], - - // IE6-8 can't serialize link, script, style, or any html5 (NoScope) tags, - // unless wrapped in a div with non-breaking characters in front of it. - _default: jQuery.support.htmlSerialize ? [ 0, "" ] : [ 1, "X
" ] - }, - safeFragment = createSafeFragment( document ), - fragmentDiv = safeFragment.appendChild( document.createElement("div") ); + _default: [ 0, "" ] + }; wrapMap.optgroup = wrapMap.option; wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead; @@ -213,14 +190,11 @@ jQuery.fn.extend({ l = this.length; if ( value === undefined ) { - return elem.nodeType === 1 ? - elem.innerHTML.replace( rinlinejQuery, "" ) : - undefined; + return elem.nodeType === 1 ? elem.innerHTML: undefined; } // See if we can take a shortcut and just use innerHTML if ( typeof value === "string" && !rnoInnerhtml.test( value ) && - ( jQuery.support.htmlSerialize || !rnoshimcache.test( value ) ) && ( jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value ) ) && !wrapMap[ ( rtagName.exec( value ) || ["", ""] )[1].toLowerCase() ] ) { @@ -559,18 +533,11 @@ function fixDefaultChecked( elem ) { jQuery.extend({ clone: function( elem, dataAndEvents, deepDataAndEvents ) { - var destElements, srcElements, node, i, clone, - inPage = jQuery.contains( elem.ownerDocument, elem ); - - if ( jQuery.support.html5Clone || jQuery.isXMLDoc(elem) || !rnoshimcache.test( "<" + elem.nodeName + ">" ) ) { + var destElements, srcElements, node, i, + inPage = jQuery.contains( elem.ownerDocument, elem ), clone = elem.cloneNode( true ); // IE<=8 does not properly clone detached, unknown element nodes - } else { - fragmentDiv.innerHTML = elem.outerHTML; - fragmentDiv.removeChild( clone = fragmentDiv.firstChild ); - } - if ( (!jQuery.support.noCloneEvent || !jQuery.support.noCloneChecked) && (elem.nodeType === 1 || elem.nodeType === 11) && !jQuery.isXMLDoc(elem) ) { @@ -616,7 +583,7 @@ jQuery.extend({ clean: function( elems, context, fragment, scripts, selection ) { var elem, i, j, tmp, tag, wrap, tbody, ret = [], - safe = context === document && safeFragment; + container = context === document && fragment; // Ensure that context is a document if ( !context || typeof context.createDocumentFragment === "undefined" ) { @@ -636,8 +603,8 @@ jQuery.extend({ // Convert html into DOM nodes } else { // Ensure a safe container - safe = safe || createSafeFragment( context ); - tmp = tmp || safe.appendChild( context.createElement("div") ); + container = container || context.createDocumentFragment(); + tmp = tmp || container.appendChild( context.createElement("div") ); // Deserialize a standard representation tag = ( rtagName.exec( elem ) || ["", ""] )[1].toLowerCase(); @@ -686,14 +653,14 @@ jQuery.extend({ } // Remember the top-level container for proper cleanup - tmp = safe.lastChild; + tmp = container.lastChild; } } } - // Fix #11356: Clear elements from safeFragment + // Fix #11356: Clear elements from fragment if ( tmp ) { - safe.removeChild( tmp ); + container.removeChild( tmp ); } // Reset defaultChecked for any radios and checkboxes @@ -704,7 +671,7 @@ jQuery.extend({ if ( fragment ) { for ( i = 0; (elem = ret[i]) != null; i++ ) { - safe = jQuery.contains( elem.ownerDocument, elem ); + container = jQuery.contains( elem.ownerDocument, elem ); // Append to fragment // #4087 - If origin and destination elements are the same, and this is @@ -715,7 +682,7 @@ jQuery.extend({ tmp = getAll( elem, "script" ); // Preserve script evaluation history - if ( safe ) { + if ( container ) { setGlobalEval( tmp ); } @@ -730,8 +697,6 @@ jQuery.extend({ } } - elem = tmp = safe = null; - return ret; }, diff --git a/src/support.js b/src/support.js index c99bb3922..25ce0298e 100644 --- a/src/support.js +++ b/src/support.js @@ -5,7 +5,7 @@ jQuery.support = (function() { // Setup div.setAttribute( "className", "t" ); - div.innerHTML = "
a"; + div.innerHTML = "
a"; // Support tests won't run in some limited or non-browser environments all = div.getElementsByTagName("*"); @@ -31,10 +31,6 @@ jQuery.support = (function() { // IE will insert them into empty tables tbody: !div.getElementsByTagName("tbody").length, - // Make sure that link elements get serialized correctly by innerHTML - // This requires a wrapper element in IE - htmlSerialize: !!div.getElementsByTagName("link").length, - // Get the style information from getAttribute // (IE uses .cssText instead) style: /top/.test( a.getAttribute("style") ), @@ -62,10 +58,6 @@ jQuery.support = (function() { // Tests for enctype support on a form (#6743) enctype: !!document.createElement("form").enctype, - // Makes sure cloning an html5 element does not cause problems - // Where outerHTML is undefined, this still works - html5Clone: document.createElement("nav").cloneNode( true ).outerHTML !== "<:nav>", - // jQuery.support.boxModel DEPRECATED in 1.8 since we don't support Quirks Mode boxModel: document.compatMode === "CSS1Compat", From c1c97b474ea7123fabd3e5f0b2192e967c48eb84 Mon Sep 17 00:00:00 2001 From: Oleg Date: Wed, 19 Dec 2012 20:27:42 +0400 Subject: [PATCH 02/51] Remove leading white space check --- src/manipulation.js | 9 +-------- src/support.js | 5 +---- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 32b5b5f81..e933ba08f 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -1,5 +1,4 @@ -var rleadingWhitespace = /^\s+/, - rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi, +var rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi, rtagName = /<([\w:]+)/, rtbody = /" ); @@ -617,11 +615,6 @@ jQuery.extend({ tmp = tmp.lastChild; } - // Manually add leading whitespace removed by IE - if ( !jQuery.support.leadingWhitespace && rleadingWhitespace.test( elem ) ) { - ret.push( context.createTextNode( rleadingWhitespace.exec( elem )[0] ) ); - } - // Remove IE's autoinserted from table fragments if ( !jQuery.support.tbody ) { diff --git a/src/support.js b/src/support.js index 25ce0298e..953564013 100644 --- a/src/support.js +++ b/src/support.js @@ -5,7 +5,7 @@ jQuery.support = (function() { // Setup div.setAttribute( "className", "t" ); - div.innerHTML = "
a"; + div.innerHTML = "
a"; // Support tests won't run in some limited or non-browser environments all = div.getElementsByTagName("*"); @@ -24,9 +24,6 @@ jQuery.support = (function() { // Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7) getSetAttribute: div.className !== "t", - // IE strips leading whitespace when .innerHTML is used - leadingWhitespace: div.firstChild.nodeType === 3, - // Make sure that tbody elements aren't automatically inserted // IE will insert them into empty tables tbody: !div.getElementsByTagName("tbody").length, From 7a2a82ba62c42a55302d5b938b31672b34ae390d Mon Sep 17 00:00:00 2001 From: Oleg Date: Wed, 19 Dec 2012 20:30:13 +0400 Subject: [PATCH 03/51] Remove tbody check --- src/manipulation.js | 20 -------------------- src/support.js | 2 +- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index e933ba08f..d2f17b87d 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -615,26 +615,6 @@ jQuery.extend({ tmp = tmp.lastChild; } - // Remove IE's autoinserted from table fragments - if ( !jQuery.support.tbody ) { - - // String was a , *may* have spurious - elem = tag === "table" && !rtbody.test( elem ) ? - tmp.firstChild : - - // String was a bare or - wrap[1] === "
" && !rtbody.test( elem ) ? - tmp : - 0; - - j = elem && elem.childNodes.length; - while ( j-- ) { - if ( jQuery.nodeName( (tbody = elem.childNodes[j]), "tbody" ) && !tbody.childNodes.length ) { - elem.removeChild( tbody ); - } - } - } - jQuery.merge( ret, tmp.childNodes ); // Fix #12392 for WebKit and IE > 9 diff --git a/src/support.js b/src/support.js index 953564013..f55cc6ae8 100644 --- a/src/support.js +++ b/src/support.js @@ -5,7 +5,7 @@ jQuery.support = (function() { // Setup div.setAttribute( "className", "t" ); - div.innerHTML = "
a"; + div.innerHTML = "a"; // Support tests won't run in some limited or non-browser environments all = div.getElementsByTagName("*"); From eac4e8e2510485c452af3614ddb8042ceec1fc34 Mon Sep 17 00:00:00 2001 From: Oleg Date: Wed, 19 Dec 2012 20:31:36 +0400 Subject: [PATCH 04/51] Remove removal of container children through removeChild method --- src/manipulation.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index d2f17b87d..4b33e64c6 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -620,11 +620,6 @@ jQuery.extend({ // Fix #12392 for WebKit and IE > 9 tmp.textContent = ""; - // Fix #12392 for oldIE - while ( tmp.firstChild ) { - tmp.removeChild( tmp.firstChild ); - } - // Remember the top-level container for proper cleanup tmp = container.lastChild; } From 28f6fcb763266ecd476274f430cce0ef625f8b16 Mon Sep 17 00:00:00 2001 From: Oleg Date: Wed, 19 Dec 2012 20:34:08 +0400 Subject: [PATCH 05/51] Remove unused variables --- src/manipulation.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 4b33e64c6..d3bc7d027 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -1,6 +1,5 @@ var rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi, rtagName = /<([\w:]+)/, - rtbody = / Date: Wed, 19 Dec 2012 22:33:55 +0400 Subject: [PATCH 06/51] Code style changes --- src/manipulation.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index d3bc7d027..9a60d1089 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -64,8 +64,8 @@ jQuery.fn.extend({ wrapInner: function( html ) { if ( jQuery.isFunction( html ) ) { - return this.each(function(i) { - jQuery(this).wrapInner( html.call(this, i) ); + return this.each(function( i ) { + jQuery( this ).wrapInner( html.call(this, i) ); }); } @@ -83,10 +83,10 @@ jQuery.fn.extend({ }, wrap: function( html ) { - var isFunction = jQuery.isFunction( html ); + var isFunc = jQuery.isFunction( html ); - return this.each(function(i) { - jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html ); + return this.each(function( i ) { + jQuery( this ).wrapAll( isFunc ? html.call(this, i) : html ); }); }, @@ -132,10 +132,9 @@ jQuery.fn.extend({ // keepData is for internal use only--do not document remove: function( selector, keepData ) { - var elem, - i = 0; + var elem, i = 0; - for ( ; (elem = this[i]) != null; i++ ) { + for ( ; ( elem = this[ i ] ) != null; i++ ) { if ( !selector || jQuery.filter( selector, [ elem ] ).length > 0 ) { if ( !keepData && elem.nodeType === 1 ) { jQuery.cleanData( getAll( elem ) ); From 8c4b9f082bee05218f7e218b5a0db12e5e333ef4 Mon Sep 17 00:00:00 2001 From: Oleg Date: Wed, 19 Dec 2012 22:42:07 +0400 Subject: [PATCH 07/51] Simplify jQuery#wrap --- src/manipulation.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 9a60d1089..e0edab197 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -156,15 +156,14 @@ jQuery.fn.extend({ var elem, i = 0; - for ( ; (elem = this[i]) != null; i++ ) { - // Remove element nodes and prevent memory leaks + for ( ; ( elem = this[ i ] ) != null; i++ ) { if ( elem.nodeType === 1 ) { - jQuery.cleanData( getAll( elem, false ) ); - } - // Remove any remaining nodes - while ( elem.firstChild ) { - elem.removeChild( elem.firstChild ); + // Remove element nodes and prevent memory leaks + jQuery.cleanData( getAll( elem, false ) ); + + // Remove any remaining nodes + elem.textContent = ""; } } From 76bde01be89ab8d985c5af91a023e2db65e85867 Mon Sep 17 00:00:00 2001 From: Oleg Date: Wed, 19 Dec 2012 22:59:16 +0400 Subject: [PATCH 08/51] Code style changes --- src/manipulation.js | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index e0edab197..47fa09f71 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -191,14 +191,14 @@ jQuery.fn.extend({ // See if we can take a shortcut and just use innerHTML if ( typeof value === "string" && !rnoInnerhtml.test( value ) && - !wrapMap[ ( rtagName.exec( value ) || ["", ""] )[1].toLowerCase() ] ) { + !wrapMap[ ( rtagName.exec( value ) || ["", ""] )[ 1 ].toLowerCase() ] ) { value = value.replace( rxhtmlTag, "<$1>" ); try { for (; i < l; i++ ) { // Remove element nodes and prevent memory leaks - elem = this[i] || {}; + elem = this[ i ] || {}; if ( elem.nodeType === 1 ) { jQuery.cleanData( getAll( elem, false ) ); elem.innerHTML = value; @@ -301,9 +301,9 @@ jQuery.fn.extend({ } callback.call( - table && jQuery.nodeName( this[i], "table" ) ? - findOrAppend( this[i], "tbody" ) : - this[i], + table && jQuery.nodeName( this[ i ], "table" ) ? + findOrAppend( this[ i ], "tbody" ) : + this[ i ], node, i ); @@ -360,7 +360,7 @@ function disableScript( elem ) { function restoreScript( elem ) { var match = rscriptTypeMasked.exec( elem.type ); if ( match ) { - elem.type = match[1]; + elem.type = match[ 1 ]; } else { elem.removeAttribute("type"); } @@ -371,8 +371,8 @@ function restoreScript( elem ) { function setGlobalEval( elems, refElements ) { var elem, i = 0; - for ( ; (elem = elems[i]) != null; i++ ) { - jQuery._data( elem, "globalEval", !refElements || jQuery._data( refElements[i], "globalEval" ) ); + for ( ; (elem = elems[ i ]) != null; i++ ) { + jQuery._data( elem, "globalEval", !refElements || jQuery._data( refElements[ i ], "globalEval" ) ); } } @@ -487,7 +487,7 @@ jQuery.each({ for ( ; i <= last; i++ ) { elems = i === last ? this : this.clone(true); - jQuery( insert[i] )[ original ]( elems ); + jQuery( insert[ i ] )[ original ]( elems ); // Modern browsers can apply jQuery collections as arrays, but oldIE needs a .get() core_push.apply( ret, elems.get() ); @@ -505,7 +505,7 @@ function getAll( context, tag ) { undefined; if ( !found ) { - for ( found = [], elems = context.childNodes || context; (elem = elems[i]) != null; i++ ) { + for ( found = [], elems = context.childNodes || context; (elem = elems[ i ]) != null; i++ ) { if ( !tag || jQuery.nodeName( elem, tag ) ) { found.push( elem ); } else { @@ -541,10 +541,10 @@ jQuery.extend({ srcElements = getAll( elem ); // Fix all IE cloning issues - for ( i = 0; (node = srcElements[i]) != null; ++i ) { + for ( i = 0; (node = srcElements[ i ]) != null; ++i ) { // Ensure that the destination node is not null; Fixes #9587 - if ( destElements[i] ) { - fixCloneNodeIssues( node, destElements[i] ); + if ( destElements[ i ] ) { + fixCloneNodeIssues( node, destElements[ i ] ); } } } @@ -555,8 +555,8 @@ jQuery.extend({ srcElements = srcElements || getAll( elem ); destElements = destElements || getAll( clone ); - for ( i = 0; (node = srcElements[i]) != null; i++ ) { - cloneCopyEvent( node, destElements[i] ); + for ( i = 0; (node = srcElements[ i ]) != null; i++ ) { + cloneCopyEvent( node, destElements[ i ] ); } } else { cloneCopyEvent( elem, clone ); @@ -585,7 +585,7 @@ jQuery.extend({ context = document; } - for ( i = 0; (elem = elems[i]) != null; i++ ) { + for ( i = 0; (elem = elems[ i ]) != null; i++ ) { if ( elem || elem === 0 ) { // Add nodes directly if ( jQuery.type( elem ) === "object" ) { @@ -602,9 +602,9 @@ jQuery.extend({ tmp = tmp || container.appendChild( context.createElement("div") ); // Deserialize a standard representation - tag = ( rtagName.exec( elem ) || ["", ""] )[1].toLowerCase(); + tag = ( rtagName.exec( elem ) || ["", ""] )[ 1 ].toLowerCase(); wrap = wrapMap[ tag ] || wrapMap._default; - tmp.innerHTML = wrap[1] + elem.replace( rxhtmlTag, "<$1>" ) + ( wrap[2] || "" ); + tmp.innerHTML = wrap[ 1 ] + elem.replace( rxhtmlTag, "<$1>" ) + ( wrap[ 2 ] || "" ); // Descend through wrappers to the right content j = wrap[0]; @@ -635,7 +635,7 @@ jQuery.extend({ } if ( fragment ) { - for ( i = 0; (elem = ret[i]) != null; i++ ) { + for ( i = 0; (elem = ret[ i ]) != null; i++ ) { container = jQuery.contains( elem.ownerDocument, elem ); // Append to fragment @@ -653,7 +653,7 @@ jQuery.extend({ // Capture executables if ( scripts ) { - for ( j = 0; (elem = tmp[j]) != null; j++ ) { + for ( j = 0; (elem = tmp[ j ]) != null; j++ ) { if ( rscriptType.test( elem.type || "" ) ) { scripts.push( elem ); } @@ -673,7 +673,7 @@ jQuery.extend({ deleteExpando = jQuery.support.deleteExpando, special = jQuery.event.special; - for ( ; (elem = elems[i]) != null; i++ ) { + for ( ; (elem = elems[ i ]) != null; i++ ) { if ( acceptData || jQuery.acceptData( elem ) ) { From e9ea6679b250429f430ff5ece6dab3cde71bc11d Mon Sep 17 00:00:00 2001 From: Oleg Date: Wed, 19 Dec 2012 23:35:25 +0400 Subject: [PATCH 09/51] Change "isFunc" variable to "isFunction" --- src/manipulation.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 47fa09f71..3a3dff165 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -83,10 +83,10 @@ jQuery.fn.extend({ }, wrap: function( html ) { - var isFunc = jQuery.isFunction( html ); + var isFunction = jQuery.isFunction( html ); return this.each(function( i ) { - jQuery( this ).wrapAll( isFunc ? html.call(this, i) : html ); + jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html ); }); }, @@ -197,7 +197,6 @@ jQuery.fn.extend({ try { for (; i < l; i++ ) { - // Remove element nodes and prevent memory leaks elem = this[ i ] || {}; if ( elem.nodeType === 1 ) { jQuery.cleanData( getAll( elem, false ) ); @@ -208,7 +207,7 @@ jQuery.fn.extend({ elem = 0; // If using innerHTML throws an exception, use the fallback method - } catch(e) {} + } catch( e ) {} } if ( elem ) { @@ -218,11 +217,11 @@ jQuery.fn.extend({ }, replaceWith: function( value ) { - var isFunc = jQuery.isFunction( value ); + var isFunction = jQuery.isFunction( value ); // Make sure that the elements are removed from the DOM before they are inserted // this can help fix replacing a parent with child elements - if ( !isFunc && typeof value !== "string" ) { + if ( !isFunction && typeof value !== "string" ) { value = jQuery( value ).not( this ).detach(); } From 329d5e1d0328a5e638d4041e913fe1faccd919f3 Mon Sep 17 00:00:00 2001 From: Oleg Date: Wed, 19 Dec 2012 23:40:24 +0400 Subject: [PATCH 10/51] Remove memory fix --- src/manipulation.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 3a3dff165..5abb8a519 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -324,7 +324,6 @@ jQuery.fn.extend({ // Hope ajax is available... jQuery.ajax({ url: node.src, - type: "GET", dataType: "script", async: false, global: false, @@ -336,9 +335,6 @@ jQuery.fn.extend({ } } } - - // Fix #11809: Avoid leaking memory - fragment = first = null; } } @@ -568,8 +564,6 @@ jQuery.extend({ setGlobalEval( destElements, !inPage && getAll( elem, "script" ) ); } - destElements = srcElements = node = null; - // Return the cloned set return clone; }, From 7a5000a39eaa3d3126722d4946fb2ed680383b87 Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 20 Dec 2012 00:52:39 +0400 Subject: [PATCH 11/51] Simplify fixCloneNodeIssues helper --- src/manipulation.js | 50 ++++++++------------------------------------- 1 file changed, 8 insertions(+), 42 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 5abb8a519..5b987aa53 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -400,7 +400,7 @@ function cloneCopyEvent( src, dest ) { } function fixCloneNodeIssues( src, dest ) { - var nodeName, data, e; + var nodeName; // We do not need to do anything for non-Elements if ( dest.nodeType !== 1 ) { @@ -409,26 +409,7 @@ function fixCloneNodeIssues( src, dest ) { nodeName = dest.nodeName.toLowerCase(); - // IE6-8 copies events bound via attachEvent when using cloneNode. - if ( !jQuery.support.noCloneEvent && dest[ jQuery.expando ] ) { - data = jQuery._data( dest ); - - for ( e in data.events ) { - jQuery.removeEvent( dest, e, data.handle ); - } - - // Event data gets referenced instead of copied if the expando gets copied too - dest.removeAttribute( jQuery.expando ); - } - - // IE blanks contents when cloning scripts, and tries to evaluate newly-set text - if ( nodeName === "script" && dest.text !== src.text ) { - disableScript( dest ).text = src.text; - restoreScript( dest ); - - // IE6-10 improperly clones children of object elements using classid. - // IE10 throws NoModificationAllowedError if parent is null, #12132. - } else if ( nodeName === "object" ) { + if ( nodeName === "object" ) { if ( dest.parentNode ) { dest.outerHTML = src.outerHTML; } @@ -437,30 +418,16 @@ function fixCloneNodeIssues( src, dest ) { // element in IE9, the outerHTML strategy above is not sufficient. // If the src has innerHTML and the destination does not, // copy the src.innerHTML into the dest.innerHTML. #10324 - if ( jQuery.support.html5Clone && ( src.innerHTML && !jQuery.trim(dest.innerHTML) ) ) { + if ( src.innerHTML && !jQuery.trim( dest.innerHTML ) ) { dest.innerHTML = src.innerHTML; } + // IE9-10 fails to persist the checked state of a cloned checkbox or radio button. } else if ( nodeName === "input" && manipulation_rcheckableType.test( src.type ) ) { - // IE6-8 fails to persist the checked state of a cloned checkbox - // or radio button. Worse, IE6-7 fail to give the cloned element - // a checked appearance if the defaultChecked value isn't also set + dest.checked = src.checked; - dest.defaultChecked = dest.checked = src.checked; - - // IE6-7 get confused and end up setting the value of a cloned - // checkbox/radio button to an empty string instead of "on" - if ( dest.value !== src.value ) { - dest.value = src.value; - } - - // IE6-8 fails to return the selected option to the default selected + // IE9-10 fails to return the selected option to the default selected // state when cloning options - } else if ( nodeName === "option" ) { - dest.defaultSelected = dest.selected = src.defaultSelected; - - // IE6-8 fails to set the defaultValue to the correct value when - // cloning other types of input fields } else if ( nodeName === "input" || nodeName === "textarea" ) { dest.defaultValue = src.defaultValue; } @@ -528,14 +495,13 @@ jQuery.extend({ clone = elem.cloneNode( true ); // IE<=8 does not properly clone detached, unknown element nodes - if ( (!jQuery.support.noCloneEvent || !jQuery.support.noCloneChecked) && - (elem.nodeType === 1 || elem.nodeType === 11) && !jQuery.isXMLDoc(elem) ) { + if ( !jQuery.support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) && !jQuery.isXMLDoc( elem ) ) { // We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2 destElements = getAll( clone ); srcElements = getAll( elem ); - // Fix all IE cloning issues + // Fix IE cloning issues for ( i = 0; (node = srcElements[ i ]) != null; ++i ) { // Ensure that the destination node is not null; Fixes #9587 if ( destElements[ i ] ) { From 61d01c8d3567e2cae27fa89749ea2602bd0509bb Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 20 Dec 2012 01:08:24 +0400 Subject: [PATCH 12/51] Simplify getAll helper --- src/manipulation.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 5b987aa53..2289d44df 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -448,11 +448,10 @@ jQuery.each({ last = insert.length - 1; for ( ; i <= last; i++ ) { - elems = i === last ? this : this.clone(true); + elems = i === last ? this : this.clone( true ); jQuery( insert[ i ] )[ original ]( elems ); - // Modern browsers can apply jQuery collections as arrays, but oldIE needs a .get() - core_push.apply( ret, elems.get() ); + core_push.apply( ret, elems ); } return this.pushStack( ret ); @@ -462,23 +461,22 @@ jQuery.each({ function getAll( context, tag ) { var elems, elem, i = 0, - found = typeof context.getElementsByTagName !== "undefined" ? context.getElementsByTagName( tag || "*" ) : + ret = typeof context.getElementsByTagName !== "undefined" ? context.getElementsByTagName( tag || "*" ) : typeof context.querySelectorAll !== "undefined" ? context.querySelectorAll( tag || "*" ) : undefined; - if ( !found ) { - for ( found = [], elems = context.childNodes || context; (elem = elems[ i ]) != null; i++ ) { - if ( !tag || jQuery.nodeName( elem, tag ) ) { - found.push( elem ); - } else { - jQuery.merge( found, getAll( elem, tag ) ); - } + if ( !ret ) { + for ( ret = [], elems = context.childNodes || context; (elem = elems[ i ]) != null; i++ ) { + core_push.apply( ret, + !tag || jQuery.nodeName( elem, tag ) ? + getAll( elem, tag ) : + elems ); } } return tag === undefined || tag && jQuery.nodeName( context, tag ) ? - jQuery.merge( [ context ], found ) : - found; + jQuery.merge( [ context ], ret ) : + ret; } // Used in clean, fixes the defaultChecked property From a10dd521df44032065b95c482f8aee1f5d505375 Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 20 Dec 2012 01:10:20 +0400 Subject: [PATCH 13/51] Remove fixDefaultChecked helper --- src/manipulation.js | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 2289d44df..6aed45744 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -467,8 +467,7 @@ function getAll( context, tag ) { if ( !ret ) { for ( ret = [], elems = context.childNodes || context; (elem = elems[ i ]) != null; i++ ) { - core_push.apply( ret, - !tag || jQuery.nodeName( elem, tag ) ? + core_push.apply( ret, !tag || jQuery.nodeName( elem, tag ) ? getAll( elem, tag ) : elems ); } @@ -479,13 +478,6 @@ function getAll( context, tag ) { ret; } -// Used in clean, fixes the defaultChecked property -function fixDefaultChecked( elem ) { - if ( manipulation_rcheckableType.test( elem.type ) ) { - elem.defaultChecked = elem.checked; - } -} - jQuery.extend({ clone: function( elem, dataAndEvents, deepDataAndEvents ) { var destElements, srcElements, node, i, @@ -585,12 +577,6 @@ jQuery.extend({ container.removeChild( tmp ); } - // Reset defaultChecked for any radios and checkboxes - // about to be appended to the DOM in IE 6/7 (#8060) - if ( !jQuery.support.appendChecked ) { - jQuery.grep( getAll( ret, "input" ), fixDefaultChecked ); - } - if ( fragment ) { for ( i = 0; (elem = ret[ i ]) != null; i++ ) { container = jQuery.contains( elem.ownerDocument, elem ); From 1043fa897156c077b96de8109c7869bf5b8381ab Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 20 Dec 2012 01:13:54 +0400 Subject: [PATCH 14/51] Move all helpers to the end of the module --- src/manipulation.js | 222 ++++++++++++++++++++++---------------------- 1 file changed, 111 insertions(+), 111 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 6aed45744..b31ee03f9 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -342,97 +342,6 @@ jQuery.fn.extend({ } }); -function findOrAppend( elem, tag ) { - return elem.getElementsByTagName( tag )[0] || elem.appendChild( elem.ownerDocument.createElement( tag ) ); -} - -// Replace/restore the type attribute of script elements for safe DOM manipulation -function disableScript( elem ) { - var attr = elem.getAttributeNode("type"); - elem.type = ( attr && attr.specified ) + "/" + elem.type; - return elem; -} -function restoreScript( elem ) { - var match = rscriptTypeMasked.exec( elem.type ); - if ( match ) { - elem.type = match[ 1 ]; - } else { - elem.removeAttribute("type"); - } - return elem; -} - -// Mark scripts as having already been evaluated -function setGlobalEval( elems, refElements ) { - var elem, - i = 0; - for ( ; (elem = elems[ i ]) != null; i++ ) { - jQuery._data( elem, "globalEval", !refElements || jQuery._data( refElements[ i ], "globalEval" ) ); - } -} - -function cloneCopyEvent( src, dest ) { - - if ( dest.nodeType !== 1 || !jQuery.hasData( src ) ) { - return; - } - - var type, i, l, - oldData = jQuery._data( src ), - curData = jQuery._data( dest, oldData ), - events = oldData.events; - - if ( events ) { - delete curData.handle; - curData.events = {}; - - for ( type in events ) { - for ( i = 0, l = events[ type ].length; i < l; i++ ) { - jQuery.event.add( dest, type, events[ type ][ i ] ); - } - } - } - - // make the cloned public data object a copy from the original - if ( curData.data ) { - curData.data = jQuery.extend( {}, curData.data ); - } -} - -function fixCloneNodeIssues( src, dest ) { - var nodeName; - - // We do not need to do anything for non-Elements - if ( dest.nodeType !== 1 ) { - return; - } - - nodeName = dest.nodeName.toLowerCase(); - - if ( nodeName === "object" ) { - if ( dest.parentNode ) { - dest.outerHTML = src.outerHTML; - } - - // This path appears unavoidable for IE9. When cloning an object - // element in IE9, the outerHTML strategy above is not sufficient. - // If the src has innerHTML and the destination does not, - // copy the src.innerHTML into the dest.innerHTML. #10324 - if ( src.innerHTML && !jQuery.trim( dest.innerHTML ) ) { - dest.innerHTML = src.innerHTML; - } - - // IE9-10 fails to persist the checked state of a cloned checkbox or radio button. - } else if ( nodeName === "input" && manipulation_rcheckableType.test( src.type ) ) { - dest.checked = src.checked; - - // IE9-10 fails to return the selected option to the default selected - // state when cloning options - } else if ( nodeName === "input" || nodeName === "textarea" ) { - dest.defaultValue = src.defaultValue; - } -} - jQuery.each({ appendTo: "append", prependTo: "prepend", @@ -458,26 +367,6 @@ jQuery.each({ }; }); -function getAll( context, tag ) { - var elems, elem, - i = 0, - ret = typeof context.getElementsByTagName !== "undefined" ? context.getElementsByTagName( tag || "*" ) : - typeof context.querySelectorAll !== "undefined" ? context.querySelectorAll( tag || "*" ) : - undefined; - - if ( !ret ) { - for ( ret = [], elems = context.childNodes || context; (elem = elems[ i ]) != null; i++ ) { - core_push.apply( ret, !tag || jQuery.nodeName( elem, tag ) ? - getAll( elem, tag ) : - elems ); - } - } - - return tag === undefined || tag && jQuery.nodeName( context, tag ) ? - jQuery.merge( [ context ], ret ) : - ret; -} - jQuery.extend({ clone: function( elem, dataAndEvents, deepDataAndEvents ) { var destElements, srcElements, node, i, @@ -661,3 +550,114 @@ jQuery.extend({ } } }); + +function findOrAppend( elem, tag ) { + return elem.getElementsByTagName( tag )[ 0 ] || elem.appendChild( elem.ownerDocument.createElement( tag ) ); +} + +// Replace/restore the type attribute of script elements for safe DOM manipulation +function disableScript( elem ) { + var attr = elem.getAttributeNode("type"); + elem.type = ( attr && attr.specified ) + "/" + elem.type; + return elem; +} +function restoreScript( elem ) { + var match = rscriptTypeMasked.exec( elem.type ); + if ( match ) { + elem.type = match[ 1 ]; + } else { + elem.removeAttribute("type"); + } + return elem; +} + +// Mark scripts as having already been evaluated +function setGlobalEval( elems, refElements ) { + var elem, + i = 0; + for ( ; (elem = elems[ i ]) != null; i++ ) { + jQuery._data( elem, "globalEval", !refElements || jQuery._data( refElements[ i ], "globalEval" ) ); + } +} + +function cloneCopyEvent( src, dest ) { + + if ( dest.nodeType !== 1 || !jQuery.hasData( src ) ) { + return; + } + + var type, i, l, + oldData = jQuery._data( src ), + curData = jQuery._data( dest, oldData ), + events = oldData.events; + + if ( events ) { + delete curData.handle; + curData.events = {}; + + for ( type in events ) { + for ( i = 0, l = events[ type ].length; i < l; i++ ) { + jQuery.event.add( dest, type, events[ type ][ i ] ); + } + } + } + + // make the cloned public data object a copy from the original + if ( curData.data ) { + curData.data = jQuery.extend( {}, curData.data ); + } +} + +function fixCloneNodeIssues( src, dest ) { + var nodeName; + + // We do not need to do anything for non-Elements + if ( dest.nodeType !== 1 ) { + return; + } + + nodeName = dest.nodeName.toLowerCase(); + + if ( nodeName === "object" ) { + if ( dest.parentNode ) { + dest.outerHTML = src.outerHTML; + } + + // This path appears unavoidable for IE9. When cloning an object + // element in IE9, the outerHTML strategy above is not sufficient. + // If the src has innerHTML and the destination does not, + // copy the src.innerHTML into the dest.innerHTML. #10324 + if ( src.innerHTML && !jQuery.trim( dest.innerHTML ) ) { + dest.innerHTML = src.innerHTML; + } + + // IE9-10 fails to persist the checked state of a cloned checkbox or radio button. + } else if ( nodeName === "input" && manipulation_rcheckableType.test( src.type ) ) { + dest.checked = src.checked; + + // IE9-10 fails to return the selected option to the default selected + // state when cloning options + } else if ( nodeName === "input" || nodeName === "textarea" ) { + dest.defaultValue = src.defaultValue; + } +} + +function getAll( context, tag ) { + var elems, elem, + i = 0, + ret = typeof context.getElementsByTagName !== "undefined" ? context.getElementsByTagName( tag || "*" ) : + typeof context.querySelectorAll !== "undefined" ? context.querySelectorAll( tag || "*" ) : + undefined; + + if ( !ret ) { + for ( ret = [], elems = context.childNodes || context; (elem = elems[ i ]) != null; i++ ) { + core_push.apply( ret, !tag || jQuery.nodeName( elem, tag ) ? + getAll( elem, tag ) : + elems ); + } + } + + return tag === undefined || tag && jQuery.nodeName( context, tag ) ? + jQuery.merge( [ context ], ret ) : + ret; +} From c334878871b2fa71a445054d9442a3fd12b742d7 Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 20 Dec 2012 01:15:21 +0400 Subject: [PATCH 15/51] Simplify wrapMap --- src/manipulation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/manipulation.js b/src/manipulation.js index b31ee03f9..513c4cfd2 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -15,7 +15,7 @@ var rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^> param: [ 1, "" ], thead: [ 1, "" ], tr: [ 2, "
" ], - col: [ 2, "
", "
" ], + col: [ 2, "" ], td: [ 3, "
" ], _default: [ 0, "" ] }; From d552b94463010b6abeeed5227f67c00c06ff31ff Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 20 Dec 2012 02:27:45 +0400 Subject: [PATCH 16/51] Simplify jQuery.expando --- src/manipulation.js | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 513c4cfd2..134b3a800 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -502,7 +502,6 @@ jQuery.extend({ i = 0, internalKey = jQuery.expando, cache = jQuery.cache, - deleteExpando = jQuery.support.deleteExpando, special = jQuery.event.special; for ( ; (elem = elems[ i ]) != null; i++ ) { @@ -513,37 +512,20 @@ jQuery.extend({ data = id && cache[ id ]; if ( data ) { - if ( data.events ) { - for ( type in data.events ) { - if ( special[ type ] ) { - jQuery.event.remove( elem, type ); + for ( type in data.events ) { + if ( special[ type ] ) { + jQuery.event.remove( elem, type ); - // This is a shortcut to avoid jQuery.event.remove's overhead - } else { - jQuery.removeEvent( elem, type, data.handle ); - } + // This is a shortcut to avoid jQuery.event.remove's overhead + } else { + jQuery.removeEvent( elem, type, data.handle ); } } // Remove cache only if it was not already removed by jQuery.event.remove if ( cache[ id ] ) { - delete cache[ id ]; - - // IE does not allow us to delete expando properties from nodes, - // nor does it have a removeAttribute function on Document nodes; - // we must handle all of these cases - if ( deleteExpando ) { - delete elem[ internalKey ]; - - } else if ( elem.removeAttribute ) { - elem.removeAttribute( internalKey ); - - } else { - elem[ internalKey ] = null; - } - - core_deletedIds.push( id ); + delete elem[ internalKey ]; } } } From d086aa16b3aa862185684b69dc3e27ee5dbc32fc Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 20 Dec 2012 02:32:54 +0400 Subject: [PATCH 17/51] Use jQuery.merge only if it really necessary --- src/manipulation.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 134b3a800..f7d0f81f7 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -295,7 +295,7 @@ jQuery.fn.extend({ // Keep references to cloned scripts for later restoration if ( hasScripts ) { - jQuery.merge( scripts, getAll( node, "script" ) ); + core_push.apply( scripts, getAll( node, "script" ) ); } } @@ -427,7 +427,7 @@ jQuery.extend({ if ( elem || elem === 0 ) { // Add nodes directly if ( jQuery.type( elem ) === "object" ) { - jQuery.merge( ret, elem.nodeType ? [ elem ] : elem ); + core_push.apply( ret, elem.nodeType ? [ elem ] : elem ); // Convert non-html into a text node } else if ( !rhtml.test( elem ) ) { @@ -450,7 +450,7 @@ jQuery.extend({ tmp = tmp.lastChild; } - jQuery.merge( ret, tmp.childNodes ); + core_push.apply( ret, tmp.childNodes ); // Fix #12392 for WebKit and IE > 9 tmp.textContent = ""; From f07e6758ae42f8f73251be9b434aedfa4c42ec85 Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 20 Dec 2012 02:35:52 +0400 Subject: [PATCH 18/51] Simplify execution of script element if it processed without src attribute --- src/manipulation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/manipulation.js b/src/manipulation.js index f7d0f81f7..af2d8b8a6 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -330,7 +330,7 @@ jQuery.fn.extend({ "throws": true }); } else { - jQuery.globalEval( ( node.text || node.textContent || node.innerHTML || "" ).replace( rcleanScript, "" ) ); + jQuery.globalEval( node.textContent.replace( rcleanScript, "" ) ); } } } From bc70e0c718e3c517e4551dddffd31663b53337b7 Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 20 Dec 2012 02:45:22 +0400 Subject: [PATCH 19/51] Speed up iteration in jQuery#domManip if it called with function inside first argument --- src/manipulation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/manipulation.js b/src/manipulation.js index af2d8b8a6..aff90bd4a 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -264,7 +264,7 @@ jQuery.fn.extend({ return this.each(function( index ) { var self = set.eq( index ); if ( isFunction ) { - args[0] = value.call( this, index, table ? self.html() : undefined ); + args[ 0 ] = value.call( this, index, table ? self.html() : undefined ); } self.domManip( args, table, callback ); }); From 8958f7cd9db57864a5a4d155cc6c9471756cd34a Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 20 Dec 2012 03:16:02 +0400 Subject: [PATCH 20/51] More simplifications fore jQuery#html --- src/manipulation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index aff90bd4a..269b1d043 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -185,8 +185,8 @@ jQuery.fn.extend({ i = 0, l = this.length; - if ( value === undefined ) { - return elem.nodeType === 1 ? elem.innerHTML: undefined; + if ( value === undefined && elem.nodeType === 1 ) { + return elem.innerHTML; } // See if we can take a shortcut and just use innerHTML From a8b38b0e6b66edab2993e7a517ac37968dc1de92 Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 20 Dec 2012 03:17:05 +0400 Subject: [PATCH 21/51] Remove couple of spaces --- src/manipulation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 269b1d043..633a68b49 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -115,7 +115,7 @@ jQuery.fn.extend({ }, before: function() { - return this.domManip( arguments, false, function( elem ) { + return this.domManip(arguments, false, function( elem ) { if ( this.parentNode ) { this.parentNode.insertBefore( elem, this ); } @@ -123,7 +123,7 @@ jQuery.fn.extend({ }, after: function() { - return this.domManip( arguments, false, function( elem ) { + return this.domManip(arguments, false, function( elem ) { if ( this.parentNode ) { this.parentNode.insertBefore( elem, this.nextSibling ); } From 32cfbd6d671dc2827562e39c5d3cd7c7565550d1 Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 20 Dec 2012 03:26:55 +0400 Subject: [PATCH 22/51] Add additional test --- test/unit/manipulation.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 86b26e040..004424cd9 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -2245,4 +2245,5 @@ test( "Index for function argument should be received (#13094)", 2, function() { jQuery("
").before(function( index ) { equal( index, i++, "Index should be correct" ); }); + }); From 3eb1f64966a869b84e40606932e049063376c3a0 Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 20 Dec 2012 03:40:48 +0400 Subject: [PATCH 23/51] Use GET method in jQuery#domManip --- src/manipulation.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/manipulation.js b/src/manipulation.js index 633a68b49..c8d673d56 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -324,6 +324,7 @@ jQuery.fn.extend({ // Hope ajax is available... jQuery.ajax({ url: node.src, + type: "GET", dataType: "script", async: false, global: false, From 0d16158f699b715d137094aa427378381e827aec Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 20 Dec 2012 03:56:33 +0400 Subject: [PATCH 24/51] Revert changes in support module --- src/support.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/support.js b/src/support.js index f55cc6ae8..c99bb3922 100644 --- a/src/support.js +++ b/src/support.js @@ -5,7 +5,7 @@ jQuery.support = (function() { // Setup div.setAttribute( "className", "t" ); - div.innerHTML = "a"; + div.innerHTML = "
a"; // Support tests won't run in some limited or non-browser environments all = div.getElementsByTagName("*"); @@ -24,10 +24,17 @@ jQuery.support = (function() { // Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7) getSetAttribute: div.className !== "t", + // IE strips leading whitespace when .innerHTML is used + leadingWhitespace: div.firstChild.nodeType === 3, + // Make sure that tbody elements aren't automatically inserted // IE will insert them into empty tables tbody: !div.getElementsByTagName("tbody").length, + // Make sure that link elements get serialized correctly by innerHTML + // This requires a wrapper element in IE + htmlSerialize: !!div.getElementsByTagName("link").length, + // Get the style information from getAttribute // (IE uses .cssText instead) style: /top/.test( a.getAttribute("style") ), @@ -55,6 +62,10 @@ jQuery.support = (function() { // Tests for enctype support on a form (#6743) enctype: !!document.createElement("form").enctype, + // Makes sure cloning an html5 element does not cause problems + // Where outerHTML is undefined, this still works + html5Clone: document.createElement("nav").cloneNode( true ).outerHTML !== "<:nav>", + // jQuery.support.boxModel DEPRECATED in 1.8 since we don't support Quirks Mode boxModel: document.compatMode === "CSS1Compat", From ec75705f88dd4b44ec133d5167b69e88c175bb24 Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 20 Dec 2012 04:06:44 +0400 Subject: [PATCH 25/51] Remove needless expression --- src/manipulation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/manipulation.js b/src/manipulation.js index c8d673d56..7bccca901 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -443,7 +443,7 @@ jQuery.extend({ // Deserialize a standard representation tag = ( rtagName.exec( elem ) || ["", ""] )[ 1 ].toLowerCase(); wrap = wrapMap[ tag ] || wrapMap._default; - tmp.innerHTML = wrap[ 1 ] + elem.replace( rxhtmlTag, "<$1>" ) + ( wrap[ 2 ] || "" ); + tmp.innerHTML = wrap[ 1 ] + elem.replace( rxhtmlTag, "<$1>" ); // Descend through wrappers to the right content j = wrap[0]; From a3ddcc5fcea200ed43188438c4a500005fc7b68f Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 20 Dec 2012 20:50:00 +0400 Subject: [PATCH 26/51] Add additional test --- test/unit/manipulation.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 004424cd9..2f67ff06d 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -2247,3 +2247,12 @@ test( "Index for function argument should be received (#13094)", 2, function() { }); }); + +test( "Make sure jQuery.fn.remove can work on elements in documentFragment", 1, function() { + var fragment = document.createDocumentFragment(), + div = fragment.appendChild( document.createElement("div") ); + + $( div ).remove(); + + equal( fragment.childNodes.length, 0, "div element was removed from documentFragment" ); +}); From 3c1b42805df4f932bcd49e5140c5e8b320ee2984 Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 20 Dec 2012 20:51:22 +0400 Subject: [PATCH 27/51] Take care of comments --- src/manipulation.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 7bccca901..79ef956ac 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -159,7 +159,7 @@ jQuery.fn.extend({ for ( ; ( elem = this[ i ] ) != null; i++ ) { if ( elem.nodeType === 1 ) { - // Remove element nodes and prevent memory leaks + // Prevent memory leaks jQuery.cleanData( getAll( elem, false ) ); // Remove any remaining nodes @@ -198,6 +198,8 @@ jQuery.fn.extend({ try { for (; i < l; i++ ) { elem = this[ i ] || {}; + + // Remove element nodes and prevent memory leaks if ( elem.nodeType === 1 ) { jQuery.cleanData( getAll( elem, false ) ); elem.innerHTML = value; @@ -374,14 +376,13 @@ jQuery.extend({ inPage = jQuery.contains( elem.ownerDocument, elem ), clone = elem.cloneNode( true ); - // IE<=8 does not properly clone detached, unknown element nodes + // Fix IE cloning issues if ( !jQuery.support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) && !jQuery.isXMLDoc( elem ) ) { // We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2 destElements = getAll( clone ); srcElements = getAll( elem ); - // Fix IE cloning issues for ( i = 0; (node = srcElements[ i ]) != null; ++i ) { // Ensure that the destination node is not null; Fixes #9587 if ( destElements[ i ] ) { From d41ac85ca3773f1be5dd91d59060fc064ac22673 Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 20 Dec 2012 21:06:06 +0400 Subject: [PATCH 28/51] Save one byte --- src/manipulation.js | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 79ef956ac..f24f1e9b1 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -592,6 +592,26 @@ function cloneCopyEvent( src, dest ) { } } +function getAll( context, tag ) { + var elems, elem, + i = 0, + ret = typeof context.getElementsByTagName !== "undefined" ? context.getElementsByTagName( tag || "*" ) : + typeof context.querySelectorAll !== "undefined" ? context.querySelectorAll( tag || "*" ) : + undefined; + + if ( !ret ) { + for ( ret = [], elems = context.childNodes || context; (elem = elems[ i ]) != null; i++ ) { + core_push.apply( ret, !tag || jQuery.nodeName( elem, tag ) ? + getAll( elem, tag ) : + elems ); + } + } + + return tag === undefined || tag && jQuery.nodeName( context, tag ) ? + jQuery.merge( [ context ], ret ) : + ret; +} + function fixCloneNodeIssues( src, dest ) { var nodeName; @@ -625,23 +645,3 @@ function fixCloneNodeIssues( src, dest ) { dest.defaultValue = src.defaultValue; } } - -function getAll( context, tag ) { - var elems, elem, - i = 0, - ret = typeof context.getElementsByTagName !== "undefined" ? context.getElementsByTagName( tag || "*" ) : - typeof context.querySelectorAll !== "undefined" ? context.querySelectorAll( tag || "*" ) : - undefined; - - if ( !ret ) { - for ( ret = [], elems = context.childNodes || context; (elem = elems[ i ]) != null; i++ ) { - core_push.apply( ret, !tag || jQuery.nodeName( elem, tag ) ? - getAll( elem, tag ) : - elems ); - } - } - - return tag === undefined || tag && jQuery.nodeName( context, tag ) ? - jQuery.merge( [ context ], ret ) : - ret; -} From 9e703a2a19c0b248f4efb8cf8343d317c3a557f1 Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 20 Dec 2012 21:11:13 +0400 Subject: [PATCH 29/51] Code style changes Save one byte --- src/manipulation.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index f24f1e9b1..665e53b61 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -132,7 +132,8 @@ jQuery.fn.extend({ // keepData is for internal use only--do not document remove: function( selector, keepData ) { - var elem, i = 0; + var elem, + i = 0; for ( ; ( elem = this[ i ] ) != null; i++ ) { if ( !selector || jQuery.filter( selector, [ elem ] ).length > 0 ) { @@ -191,12 +192,12 @@ jQuery.fn.extend({ // See if we can take a shortcut and just use innerHTML if ( typeof value === "string" && !rnoInnerhtml.test( value ) && - !wrapMap[ ( rtagName.exec( value ) || ["", ""] )[ 1 ].toLowerCase() ] ) { + !wrapMap[ ( rtagName.exec( value ) || [ "", "" ] )[ 1 ].toLowerCase() ] ) { value = value.replace( rxhtmlTag, "<$1>" ); try { - for (; i < l; i++ ) { + for ( ; i < l; i++ ) { elem = this[ i ] || {}; // Remove element nodes and prevent memory leaks @@ -397,7 +398,7 @@ jQuery.extend({ srcElements = srcElements || getAll( elem ); destElements = destElements || getAll( clone ); - for ( i = 0; (node = srcElements[ i ]) != null; i++ ) { + for ( i = 0; ( node = srcElements[ i ] ) != null; i++ ) { cloneCopyEvent( node, destElements[ i ] ); } } else { @@ -425,7 +426,7 @@ jQuery.extend({ context = document; } - for ( i = 0; (elem = elems[ i ]) != null; i++ ) { + for ( i = 0; ( elem = elems[ i ] ) != null; i++ ) { if ( elem || elem === 0 ) { // Add nodes directly if ( jQuery.type( elem ) === "object" ) { @@ -469,7 +470,7 @@ jQuery.extend({ } if ( fragment ) { - for ( i = 0; (elem = ret[ i ]) != null; i++ ) { + for ( i = 0; ( elem = ret[ i ] ) != null; i++ ) { container = jQuery.contains( elem.ownerDocument, elem ); // Append to fragment @@ -487,7 +488,7 @@ jQuery.extend({ // Capture executables if ( scripts ) { - for ( j = 0; (elem = tmp[ j ]) != null; j++ ) { + for ( j = 0; ( elem = tmp[ j ] ) != null; j++ ) { if ( rscriptType.test( elem.type || "" ) ) { scripts.push( elem ); } @@ -506,7 +507,7 @@ jQuery.extend({ cache = jQuery.cache, special = jQuery.event.special; - for ( ; (elem = elems[ i ]) != null; i++ ) { + for ( ; ( elem = elems[ i ] ) != null; i++ ) { if ( acceptData || jQuery.acceptData( elem ) ) { @@ -536,7 +537,7 @@ jQuery.extend({ }); function findOrAppend( elem, tag ) { - return elem.getElementsByTagName( tag )[ 0 ] || elem.appendChild( elem.ownerDocument.createElement( tag ) ); + return elem.getElementsByTagName( tag )[ 0 ] || elem.appendChild( elem.ownerDocument.createElement(tag) ); } // Replace/restore the type attribute of script elements for safe DOM manipulation @@ -549,9 +550,11 @@ function restoreScript( elem ) { var match = rscriptTypeMasked.exec( elem.type ); if ( match ) { elem.type = match[ 1 ]; + } else { elem.removeAttribute("type"); } + return elem; } @@ -559,7 +562,7 @@ function restoreScript( elem ) { function setGlobalEval( elems, refElements ) { var elem, i = 0; - for ( ; (elem = elems[ i ]) != null; i++ ) { + for ( ; ( elem = elems[ i ] ) != null; i++ ) { jQuery._data( elem, "globalEval", !refElements || jQuery._data( refElements[ i ], "globalEval" ) ); } } @@ -570,7 +573,7 @@ function cloneCopyEvent( src, dest ) { return; } - var type, i, l, + var type, l, i, oldData = jQuery._data( src ), curData = jQuery._data( dest, oldData ), events = oldData.events; From 2dd2e4886b394a85b86da9fbd433706a8af9b7cd Mon Sep 17 00:00:00 2001 From: Oleg Date: Sun, 23 Dec 2012 20:51:07 +0400 Subject: [PATCH 30/51] Use tabs instead of spaces "$" => "jQuery" --- test/unit/manipulation.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 2f67ff06d..b8b5e1724 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -2242,9 +2242,9 @@ test( "insertAfter, insertBefore, etc do not work when destination is original e test( "Index for function argument should be received (#13094)", 2, function() { var i = 0; - jQuery("
").before(function( index ) { - equal( index, i++, "Index should be correct" ); - }); + jQuery("
").before(function( index ) { + equal( index, i++, "Index should be correct" ); + }); }); @@ -2252,7 +2252,7 @@ test( "Make sure jQuery.fn.remove can work on elements in documentFragment", 1, var fragment = document.createDocumentFragment(), div = fragment.appendChild( document.createElement("div") ); - $( div ).remove(); + jQuery( div ).remove(); equal( fragment.childNodes.length, 0, "div element was removed from documentFragment" ); }); From 9256ba5380fca27ebc70e4d1e798fa45cb30e3a2 Mon Sep 17 00:00:00 2001 From: Oleg Date: Sun, 23 Dec 2012 20:52:46 +0400 Subject: [PATCH 31/51] Simplify check for empty set in jQuery#domManip --- src/manipulation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 665e53b61..bc07aef02 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -273,8 +273,8 @@ jQuery.fn.extend({ }); } - if ( this[0] ) { - doc = this[0].ownerDocument; + if ( l ) { + doc = this[ 0 ].ownerDocument; fragment = doc.createDocumentFragment(); jQuery.clean( args, doc, fragment, undefined, this ); first = fragment.firstChild; From 87a7690afa8c56d2aee2f902b49e3932bb3a2449 Mon Sep 17 00:00:00 2001 From: Oleg Date: Sun, 23 Dec 2012 21:10:59 +0400 Subject: [PATCH 32/51] Use correct comments --- src/manipulation.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index bc07aef02..85807a550 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -377,14 +377,15 @@ jQuery.extend({ inPage = jQuery.contains( elem.ownerDocument, elem ), clone = elem.cloneNode( true ); - // Fix IE cloning issues + // Support: IE >=9 + // Fix Cloning issues if ( !jQuery.support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) && !jQuery.isXMLDoc( elem ) ) { // We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2 destElements = getAll( clone ); srcElements = getAll( elem ); - for ( i = 0; (node = srcElements[ i ]) != null; ++i ) { + for ( i = 0; ( node = srcElements[ i ] ) != null; ++i ) { // Ensure that the destination node is not null; Fixes #9587 if ( destElements[ i ] ) { fixCloneNodeIssues( node, destElements[ i ] ); @@ -438,6 +439,7 @@ jQuery.extend({ // Convert html into DOM nodes } else { + // Ensure a safe container container = container || context.createDocumentFragment(); tmp = tmp || container.appendChild( context.createElement("div") ); @@ -455,7 +457,7 @@ jQuery.extend({ core_push.apply( ret, tmp.childNodes ); - // Fix #12392 for WebKit and IE > 9 + // Fix #12392 - remove childNodes parent tmp.textContent = ""; // Remember the top-level container for proper cleanup @@ -630,20 +632,21 @@ function fixCloneNodeIssues( src, dest ) { dest.outerHTML = src.outerHTML; } - // This path appears unavoidable for IE9. When cloning an object - // element in IE9, the outerHTML strategy above is not sufficient. + // Support: IE 9 + // When cloning an object the outerHTML strategy above is not sufficient. // If the src has innerHTML and the destination does not, // copy the src.innerHTML into the dest.innerHTML. #10324 if ( src.innerHTML && !jQuery.trim( dest.innerHTML ) ) { dest.innerHTML = src.innerHTML; } - // IE9-10 fails to persist the checked state of a cloned checkbox or radio button. + // Support: IE >= 9 + // Fails to persist the checked state of a cloned checkbox or radio button. } else if ( nodeName === "input" && manipulation_rcheckableType.test( src.type ) ) { dest.checked = src.checked; - // IE9-10 fails to return the selected option to the default selected - // state when cloning options + // Support: IE >= 9 + // Fails to return the selected option to the default selected state when cloning options } else if ( nodeName === "input" || nodeName === "textarea" ) { dest.defaultValue = src.defaultValue; } From f66c33d751879d139465417291f8da2ff266631a Mon Sep 17 00:00:00 2001 From: Oleg Date: Sun, 23 Dec 2012 21:11:40 +0400 Subject: [PATCH 33/51] Remove fix for #9587 --- src/manipulation.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 85807a550..7b3676a4a 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -386,10 +386,7 @@ jQuery.extend({ srcElements = getAll( elem ); for ( i = 0; ( node = srcElements[ i ] ) != null; ++i ) { - // Ensure that the destination node is not null; Fixes #9587 - if ( destElements[ i ] ) { - fixCloneNodeIssues( node, destElements[ i ] ); - } + fixCloneNodeIssues( node, destElements[ i ] ); } } From 5f8e99b36826e494e307afdec5d54b3366eb93fe Mon Sep 17 00:00:00 2001 From: Oleg Date: Mon, 24 Dec 2012 01:54:53 +0400 Subject: [PATCH 34/51] Use common loop iteration idiom --- src/manipulation.js | 49 ++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 7b3676a4a..ebf38e563 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -133,9 +133,12 @@ jQuery.fn.extend({ // keepData is for internal use only--do not document remove: function( selector, keepData ) { var elem, + l = this.length, i = 0; - for ( ; ( elem = this[ i ] ) != null; i++ ) { + for ( ; i < l; i++ ) { + elem = this[ i ]; + if ( !selector || jQuery.filter( selector, [ elem ] ).length > 0 ) { if ( !keepData && elem.nodeType === 1 ) { jQuery.cleanData( getAll( elem ) ); @@ -155,9 +158,12 @@ jQuery.fn.extend({ empty: function() { var elem, + l = this.length, i = 0; - for ( ; ( elem = this[ i ] ) != null; i++ ) { + for ( ; i < l; i++ ) { + elem = this[ i ]; + if ( elem.nodeType === 1 ) { // Prevent memory leaks @@ -373,7 +379,7 @@ jQuery.each({ jQuery.extend({ clone: function( elem, dataAndEvents, deepDataAndEvents ) { - var destElements, srcElements, node, i, + var destElements, srcElements, i, l, inPage = jQuery.contains( elem.ownerDocument, elem ), clone = elem.cloneNode( true ); @@ -385,8 +391,8 @@ jQuery.extend({ destElements = getAll( clone ); srcElements = getAll( elem ); - for ( i = 0; ( node = srcElements[ i ] ) != null; ++i ) { - fixCloneNodeIssues( node, destElements[ i ] ); + for ( i = 0, l = srcElements.length; i < l; i++ ) { + fixCloneNodeIssues( srcElements[ i ], destElements[ i ] ); } } @@ -396,8 +402,8 @@ jQuery.extend({ srcElements = srcElements || getAll( elem ); destElements = destElements || getAll( clone ); - for ( i = 0; ( node = srcElements[ i ] ) != null; i++ ) { - cloneCopyEvent( node, destElements[ i ] ); + for ( i = 0, l = srcElements.length; i < l; i++ ) { + cloneCopyEvent( srcElements[ i ], destElements[ i ] ); } } else { cloneCopyEvent( elem, clone ); @@ -415,7 +421,8 @@ jQuery.extend({ }, clean: function( elems, context, fragment, scripts, selection ) { - var elem, i, j, tmp, tag, wrap, + var elem, i, j, ll, tmp, tag, wrap, + l = elems.length, ret = [], container = context === document && fragment; @@ -424,8 +431,11 @@ jQuery.extend({ context = document; } - for ( i = 0; ( elem = elems[ i ] ) != null; i++ ) { + for ( i = 0; i < l; i++ ) { + elem = elems[ i ]; + if ( elem || elem === 0 ) { + // Add nodes directly if ( jQuery.type( elem ) === "object" ) { core_push.apply( ret, elem.nodeType ? [ elem ] : elem ); @@ -469,7 +479,8 @@ jQuery.extend({ } if ( fragment ) { - for ( i = 0; ( elem = ret[ i ] ) != null; i++ ) { + for ( i = 0, l = ret.length; i < l; i++ ) { + elem = ret[ i ]; container = jQuery.contains( elem.ownerDocument, elem ); // Append to fragment @@ -487,7 +498,9 @@ jQuery.extend({ // Capture executables if ( scripts ) { - for ( j = 0; ( elem = tmp[ j ] ) != null; j++ ) { + for ( j = 0, ll = tmp.length; j < ll; j++ ) { + elem = tmp[ j ]; + if ( rscriptType.test( elem.type || "" ) ) { scripts.push( elem ); } @@ -502,11 +515,13 @@ jQuery.extend({ cleanData: function( elems, /* internal */ acceptData ) { var data, id, elem, type, i = 0, + l = elems.length, internalKey = jQuery.expando, cache = jQuery.cache, special = jQuery.event.special; - for ( ; ( elem = elems[ i ] ) != null; i++ ) { + for ( ; i < l; i++ ) { + elem = elems[ i ]; if ( acceptData || jQuery.acceptData( elem ) ) { @@ -547,6 +562,7 @@ function disableScript( elem ) { } function restoreScript( elem ) { var match = rscriptTypeMasked.exec( elem.type ); + if ( match ) { elem.type = match[ 1 ]; @@ -559,10 +575,11 @@ function restoreScript( elem ) { // Mark scripts as having already been evaluated function setGlobalEval( elems, refElements ) { - var elem, - i = 0; - for ( ; ( elem = elems[ i ] ) != null; i++ ) { - jQuery._data( elem, "globalEval", !refElements || jQuery._data( refElements[ i ], "globalEval" ) ); + var i = 0, + l = elems.length; + + for ( ; i < l; i++ ) { + jQuery._data( elems[ i ], "globalEval", !refElements || jQuery._data( refElements[ i ], "globalEval" ) ); } } From 5e64281a11301bb95f657e828c5010a9b24d9bff Mon Sep 17 00:00:00 2001 From: Oleg Date: Mon, 24 Dec 2012 02:51:09 +0400 Subject: [PATCH 35/51] Save 43 bytes --- src/manipulation.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index ebf38e563..6c7017f0d 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -133,8 +133,8 @@ jQuery.fn.extend({ // keepData is for internal use only--do not document remove: function( selector, keepData ) { var elem, - l = this.length, - i = 0; + i = 0, + l = this.length; for ( ; i < l; i++ ) { elem = this[ i ]; @@ -158,8 +158,8 @@ jQuery.fn.extend({ empty: function() { var elem, - l = this.length, - i = 0; + i = 0, + l = this.length; for ( ; i < l; i++ ) { elem = this[ i ]; @@ -361,10 +361,10 @@ jQuery.each({ }, function( name, original ) { jQuery.fn[ name ] = function( selector ) { var elems, - i = 0, ret = [], insert = jQuery( selector ), - last = insert.length - 1; + last = insert.length - 1, + i = 0; for ( ; i <= last; i++ ) { elems = i === last ? this : this.clone( true ); @@ -379,9 +379,9 @@ jQuery.each({ jQuery.extend({ clone: function( elem, dataAndEvents, deepDataAndEvents ) { - var destElements, srcElements, i, l, - inPage = jQuery.contains( elem.ownerDocument, elem ), - clone = elem.cloneNode( true ); + var i, l, srcElements, destElements, + clone = elem.cloneNode( true ), + inPage = jQuery.contains( elem.ownerDocument, elem ); // Support: IE >=9 // Fix Cloning issues @@ -421,7 +421,8 @@ jQuery.extend({ }, clean: function( elems, context, fragment, scripts, selection ) { - var elem, i, j, ll, tmp, tag, wrap, + var elem, tmp, tag, wrap, j, ll, + i = 0, l = elems.length, ret = [], container = context === document && fragment; @@ -431,7 +432,7 @@ jQuery.extend({ context = document; } - for ( i = 0; i < l; i++ ) { + for ( ; i < l; i++ ) { elem = elems[ i ]; if ( elem || elem === 0 ) { @@ -513,9 +514,9 @@ jQuery.extend({ }, cleanData: function( elems, /* internal */ acceptData ) { - var data, id, elem, type, - i = 0, + var id, data, elem, type, l = elems.length, + i = 0, internalKey = jQuery.expando, cache = jQuery.cache, special = jQuery.event.special; @@ -575,8 +576,8 @@ function restoreScript( elem ) { // Mark scripts as having already been evaluated function setGlobalEval( elems, refElements ) { - var i = 0, - l = elems.length; + var l = elems.length, + i = 0; for ( ; i < l; i++ ) { jQuery._data( elems[ i ], "globalEval", !refElements || jQuery._data( refElements[ i ], "globalEval" ) ); @@ -589,7 +590,7 @@ function cloneCopyEvent( src, dest ) { return; } - var type, l, i, + var i, l, type, oldData = jQuery._data( src ), curData = jQuery._data( dest, oldData ), events = oldData.events; From 33be48acfdc2059368c3c8d171a1ddb94a3c9be9 Mon Sep 17 00:00:00 2001 From: Oleg Date: Mon, 24 Dec 2012 04:16:17 +0400 Subject: [PATCH 36/51] Remove fix for object element --- src/manipulation.js | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 6c7017f0d..355739a10 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -642,22 +642,9 @@ function fixCloneNodeIssues( src, dest ) { nodeName = dest.nodeName.toLowerCase(); - if ( nodeName === "object" ) { - if ( dest.parentNode ) { - dest.outerHTML = src.outerHTML; - } - - // Support: IE 9 - // When cloning an object the outerHTML strategy above is not sufficient. - // If the src has innerHTML and the destination does not, - // copy the src.innerHTML into the dest.innerHTML. #10324 - if ( src.innerHTML && !jQuery.trim( dest.innerHTML ) ) { - dest.innerHTML = src.innerHTML; - } - // Support: IE >= 9 // Fails to persist the checked state of a cloned checkbox or radio button. - } else if ( nodeName === "input" && manipulation_rcheckableType.test( src.type ) ) { + if ( nodeName === "input" && manipulation_rcheckableType.test( src.type ) ) { dest.checked = src.checked; // Support: IE >= 9 From fa3dad300fb6dc1882eef178cc22a1d7f3974ec1 Mon Sep 17 00:00:00 2001 From: Oleg Date: Mon, 24 Dec 2012 04:28:52 +0400 Subject: [PATCH 37/51] Simplify check for non-Elements --- src/manipulation.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 355739a10..61a6216be 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -633,14 +633,7 @@ function getAll( context, tag ) { } function fixCloneNodeIssues( src, dest ) { - var nodeName; - - // We do not need to do anything for non-Elements - if ( dest.nodeType !== 1 ) { - return; - } - - nodeName = dest.nodeName.toLowerCase(); + var nodeName = dest.nodeName.toLowerCase(); // Support: IE >= 9 // Fails to persist the checked state of a cloned checkbox or radio button. From 25712d77c3bc0221b5b2b9b9492c20a9cfbe1b17 Mon Sep 17 00:00:00 2001 From: Oleg Date: Mon, 24 Dec 2012 04:29:41 +0400 Subject: [PATCH 38/51] Simplify getAll helper --- src/manipulation.js | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 61a6216be..b211fe16f 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -613,19 +613,9 @@ function cloneCopyEvent( src, dest ) { } function getAll( context, tag ) { - var elems, elem, - i = 0, - ret = typeof context.getElementsByTagName !== "undefined" ? context.getElementsByTagName( tag || "*" ) : - typeof context.querySelectorAll !== "undefined" ? context.querySelectorAll( tag || "*" ) : - undefined; - - if ( !ret ) { - for ( ret = [], elems = context.childNodes || context; (elem = elems[ i ]) != null; i++ ) { - core_push.apply( ret, !tag || jQuery.nodeName( elem, tag ) ? - getAll( elem, tag ) : - elems ); - } - } + var ret = context.getElementsByTagName ? context.getElementsByTagName( tag || "*" ) : + context.querySelectorAll ? context.querySelectorAll( tag || "*" ) : + []; return tag === undefined || tag && jQuery.nodeName( context, tag ) ? jQuery.merge( [ context ], ret ) : From f7528916a29f5d8cd3d19285a67cd84ea9dcfe91 Mon Sep 17 00:00:00 2001 From: Oleg Date: Mon, 24 Dec 2012 04:47:13 +0400 Subject: [PATCH 39/51] Use tabs instead of spaces --- test/unit/manipulation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index b8b5e1724..5cb30c81a 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -2240,7 +2240,7 @@ test( "insertAfter, insertBefore, etc do not work when destination is original e }); test( "Index for function argument should be received (#13094)", 2, function() { - var i = 0; + var i = 0; jQuery("
").before(function( index ) { equal( index, i++, "Index should be correct" ); From f193acf3a1f6838f8f6b90d4038e3cd9bb89f1ba Mon Sep 17 00:00:00 2001 From: Oleg Date: Fri, 28 Dec 2012 18:39:12 +0400 Subject: [PATCH 40/51] Remove fix for #4484, add more tests --- src/manipulation.js | 1 - test/unit/manipulation.js | 9 +++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index b211fe16f..967c6068d 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -11,7 +11,6 @@ var rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^> wrapMap = { option: [ 1, "" ], legend: [ 1, "
" ], param: [ 1, "" ], @@ -19,6 +21,7 @@ var rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^> _default: [ 0, "" ] }; +// Support: IE 9 wrapMap.optgroup = wrapMap.option; wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead; wrapMap.th = wrapMap.td; diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index e88f71fda..8054fd075 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -395,7 +395,7 @@ var testAppendForObject = function( valueObj, isFragment ) { var testAppend = function( valueObj ) { - expect( 61 ); + expect( 63 ); testAppendForObject( valueObj, false ); testAppendForObject( valueObj, true ); @@ -454,6 +454,10 @@ var testAppend = function( valueObj ) { jQuery("#select1").append( valueObj("") ); equal( jQuery("#select1 option:last").text(), "Test", "Appending OPTION (all caps)" ); + jQuery("#select1").append( valueObj("") ); + equal( jQuery("#select1 optgroup").attr("label"), "optgroup", "Label attribute in newly inserted optgroup is correct" ); + equal( jQuery("#select1 option:last").text(), "optgroup", "Appending optgroup" ); + jQuery("#table").append( valueObj("") ); equal( jQuery("#table colgroup").length, 1, "Append colgroup" ); From 378ab82865f92a5aec4324d22c7345eff0a737a0 Mon Sep 17 00:00:00 2001 From: Oleg Date: Fri, 28 Dec 2012 19:09:50 +0400 Subject: [PATCH 42/51] Remove fieldset from wrapMap --- src/manipulation.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/manipulation.js b/src/manipulation.js index 0ce24de18..7fd31c640 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -12,7 +12,6 @@ var rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^> // Support: IE 9 option: [ 1, "" ], - param: [ 1, "" ], thead: [ 1, "" ], tr: [ 2, "
" ], col: [ 2, "
" ], From b3e546c4eb0e14c5fefefa1e0c14026ba63f0017 Mon Sep 17 00:00:00 2001 From: Oleg Date: Fri, 28 Dec 2012 19:43:01 +0400 Subject: [PATCH 44/51] Rewrite tests for colgroup, caption Add tests for thead, tbody, tfoot --- test/unit/manipulation.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 8054fd075..bf61045f4 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -395,13 +395,13 @@ var testAppendForObject = function( valueObj, isFragment ) { var testAppend = function( valueObj ) { - expect( 63 ); + expect( 66 ); testAppendForObject( valueObj, false ); testAppendForObject( valueObj, true ); var defaultText, result, message, iframe, iframeDoc, j, d, - $input, $radioChecked, $radioUnchecked, $radioParent, $map; + $input, $radioChecked, $radioUnchecked, $radioParent, $map, $table; defaultText = "Try them out:"; result = jQuery("#first").append( valueObj("buga") ); @@ -458,15 +458,16 @@ var testAppend = function( valueObj ) { equal( jQuery("#select1 optgroup").attr("label"), "optgroup", "Label attribute in newly inserted optgroup is correct" ); equal( jQuery("#select1 option:last").text(), "optgroup", "Appending optgroup" ); - jQuery("#table").append( valueObj("") ); - equal( jQuery("#table colgroup").length, 1, "Append colgroup" ); + $table = jQuery("#table"); + + jQuery.each( "thead tbody tfoot colgroup caption".split(" "), function( i, name ) { + $table.append( valueObj( "<" + name + "/>" ) ); + equal( $table.find( name ).length, 1, "Append " + name ); + }); jQuery("#table colgroup").append( valueObj("") ); equal( jQuery("#table colgroup col").length, 1, "Append col" ); - jQuery("#table").append( valueObj("") ); - equal( jQuery("#table caption").length, 1, "Append caption" ); - jQuery("#form") .append( valueObj("") ) .append( valueObj("") ); From 9dbfbe5b9ae2232d84d19ce27b0a9d31994fe165 Mon Sep 17 00:00:00 2001 From: Oleg Date: Fri, 28 Dec 2012 19:50:22 +0400 Subject: [PATCH 45/51] wrapMap.thead = wrapMap.tr Add support comments --- src/manipulation.js | 5 ++--- test/unit/manipulation.js | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 3c2cea824..1f2aef97a 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -12,8 +12,7 @@ var rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^> // Support: IE 9 option: [ 1, "
" ], - tr: [ 2, "
" ], + tr: [ 1, "
" ], col: [ 2, "
" ], td: [ 3, "
" ], _default: [ 0, "" ] @@ -21,7 +20,7 @@ var rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^> // Support: IE 9 wrapMap.optgroup = wrapMap.option; -wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead; +wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead = wrapMap.tr; wrapMap.th = wrapMap.td; jQuery.fn.extend({ diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index bf61045f4..e1850a4f7 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -395,7 +395,7 @@ var testAppendForObject = function( valueObj, isFragment ) { var testAppend = function( valueObj ) { - expect( 66 ); + expect( 67 ); testAppendForObject( valueObj, false ); testAppendForObject( valueObj, true ); @@ -460,7 +460,7 @@ var testAppend = function( valueObj ) { $table = jQuery("#table"); - jQuery.each( "thead tbody tfoot colgroup caption".split(" "), function( i, name ) { + jQuery.each( "thead tbody tfoot colgroup caption tr".split(" "), function( i, name ) { $table.append( valueObj( "<" + name + "/>" ) ); equal( $table.find( name ).length, 1, "Append " + name ); }); From ecd106280abe7ac7e09a532d42d3441d4b910d56 Mon Sep 17 00:00:00 2001 From: Oleg Date: Fri, 28 Dec 2012 19:59:55 +0400 Subject: [PATCH 46/51] wrapMap.col = wrapMap.tr --- src/manipulation.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 1f2aef97a..d34e1c541 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -13,14 +13,13 @@ var rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^> // Support: IE 9 option: [ 1, "
" ], - col: [ 2, "
" ], td: [ 3, "
" ], _default: [ 0, "" ] }; // Support: IE 9 wrapMap.optgroup = wrapMap.option; -wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead = wrapMap.tr; +wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead = wrapMap.col = wrapMap.tr; wrapMap.th = wrapMap.td; jQuery.fn.extend({ From acb206a4886f53c3eb9628e17d699dbb1b96ef25 Mon Sep 17 00:00:00 2001 From: Oleg Date: Fri, 28 Dec 2012 20:06:04 +0400 Subject: [PATCH 47/51] Add test for td append --- test/unit/manipulation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index e1850a4f7..d5c35ec1b 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -395,7 +395,7 @@ var testAppendForObject = function( valueObj, isFragment ) { var testAppend = function( valueObj ) { - expect( 67 ); + expect( 68 ); testAppendForObject( valueObj, false ); testAppendForObject( valueObj, true ); @@ -460,7 +460,7 @@ var testAppend = function( valueObj ) { $table = jQuery("#table"); - jQuery.each( "thead tbody tfoot colgroup caption tr".split(" "), function( i, name ) { + jQuery.each( "thead tbody tfoot colgroup caption tr td".split(" "), function( i, name ) { $table.append( valueObj( "<" + name + "/>" ) ); equal( $table.find( name ).length, 1, "Append " + name ); }); From 4862eb43e3c1b9d428bd64db50c08c6a6d6e01fd Mon Sep 17 00:00:00 2001 From: Oleg Date: Fri, 28 Dec 2012 20:16:28 +0400 Subject: [PATCH 48/51] Add more tests for wrapMap --- test/unit/manipulation.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index d5c35ec1b..19e20dd06 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -395,7 +395,7 @@ var testAppendForObject = function( valueObj, isFragment ) { var testAppend = function( valueObj ) { - expect( 68 ); + expect( 75 ); testAppendForObject( valueObj, false ); testAppendForObject( valueObj, true ); @@ -463,6 +463,7 @@ var testAppend = function( valueObj ) { jQuery.each( "thead tbody tfoot colgroup caption tr td".split(" "), function( i, name ) { $table.append( valueObj( "<" + name + "/>" ) ); equal( $table.find( name ).length, 1, "Append " + name ); + ok( jQuery.clean( ["<" + name + "/>"] ).length, name + " wrapped correctly" ); }); jQuery("#table colgroup").append( valueObj("") ); From 1490afe693949bd6b030f9a3b65010d9d9d3f80c Mon Sep 17 00:00:00 2001 From: Oleg Date: Fri, 28 Dec 2012 20:16:49 +0400 Subject: [PATCH 49/51] Add empty line --- src/manipulation.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/manipulation.js b/src/manipulation.js index d34e1c541..4b32fda1f 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -12,6 +12,7 @@ var rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^> // Support: IE 9 option: [ 1, "
" ], td: [ 3, "
" ], _default: [ 0, "" ] From 72e9e91612347eab1c28596a34c0b53d2c36b150 Mon Sep 17 00:00:00 2001 From: Oleg Date: Fri, 28 Dec 2012 20:27:59 +0400 Subject: [PATCH 50/51] Add tests for th element --- test/unit/manipulation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 19e20dd06..d9b014187 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -395,7 +395,7 @@ var testAppendForObject = function( valueObj, isFragment ) { var testAppend = function( valueObj ) { - expect( 75 ); + expect( 77 ); testAppendForObject( valueObj, false ); testAppendForObject( valueObj, true ); @@ -460,7 +460,7 @@ var testAppend = function( valueObj ) { $table = jQuery("#table"); - jQuery.each( "thead tbody tfoot colgroup caption tr td".split(" "), function( i, name ) { + jQuery.each( "thead tbody tfoot colgroup caption tr th td".split(" "), function( i, name ) { $table.append( valueObj( "<" + name + "/>" ) ); equal( $table.find( name ).length, 1, "Append " + name ); ok( jQuery.clean( ["<" + name + "/>"] ).length, name + " wrapped correctly" ); From 39e6792b5ce70789ef1445336ac76104220d5e09 Mon Sep 17 00:00:00 2001 From: Oleg Date: Fri, 28 Dec 2012 23:38:30 +0400 Subject: [PATCH 51/51] Rename fixCloneNodeIssues helper to fixInput Move support comment --- src/manipulation.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 4b32fda1f..9aea16f9d 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -20,6 +20,7 @@ var rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^> // Support: IE 9 wrapMap.optgroup = wrapMap.option; + wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead = wrapMap.col = wrapMap.tr; wrapMap.th = wrapMap.td; @@ -391,7 +392,7 @@ jQuery.extend({ srcElements = getAll( elem ); for ( i = 0, l = srcElements.length; i < l; i++ ) { - fixCloneNodeIssues( srcElements[ i ], destElements[ i ] ); + fixInput( srcElements[ i ], destElements[ i ] ); } } @@ -621,15 +622,14 @@ function getAll( context, tag ) { ret; } -function fixCloneNodeIssues( src, dest ) { +// Support: IE >= 9 +function fixInput( src, dest ) { var nodeName = dest.nodeName.toLowerCase(); - // Support: IE >= 9 // Fails to persist the checked state of a cloned checkbox or radio button. if ( nodeName === "input" && manipulation_rcheckableType.test( src.type ) ) { dest.checked = src.checked; - // Support: IE >= 9 // Fails to return the selected option to the default selected state when cloning options } else if ( nodeName === "input" || nodeName === "textarea" ) { dest.defaultValue = src.defaultValue;