6 "./manipulation/var/rcheckableType",
7 "./manipulation/var/rtagName",
8 "./manipulation/var/rscriptType",
9 "./manipulation/wrapMap",
10 "./manipulation/getAll",
11 "./manipulation/setGlobalEval",
12 "./manipulation/buildFragment",
13 "./manipulation/support",
15 "./data/var/dataPriv",
16 "./data/var/dataUser",
17 "./data/var/acceptData",
25 ], function( jQuery, concat, push, access,
26 rcheckableType, rtagName, rscriptType,
27 wrapMap, getAll, setGlobalEval, buildFragment, support,
28 dataPriv, dataUser, acceptData, DOMEval, nodeName ) {
34 /* eslint-disable max-len */
36 // See https://github.com/eslint/eslint/issues/3229
37 rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([a-z][^\/\0>\x20\t\r\n\f]*)[^>]*)\/>/gi,
41 // Support: IE <=10 - 11, Edge 12 - 13
42 // In IE/Edge using regex groups here causes severe slowdowns.
43 // See https://connect.microsoft.com/IE/feedback/details/1736512/
44 rnoInnerhtml = /<script|<style|<link/i,
46 // checked="checked" or checked
47 rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
48 rscriptTypeMasked = /^true\/(.*)/,
49 rcleanScript = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g;
51 // Prefer a tbody over its parent table for containing new rows
52 function manipulationTarget( elem, content ) {
53 if ( nodeName( elem, "table" ) &&
54 nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ) {
56 return jQuery( ">tbody", elem )[ 0 ] || elem;
62 // Replace/restore the type attribute of script elements for safe DOM manipulation
63 function disableScript( elem ) {
64 elem.type = ( elem.getAttribute( "type" ) !== null ) + "/" + elem.type;
67 function restoreScript( elem ) {
68 var match = rscriptTypeMasked.exec( elem.type );
71 elem.type = match[ 1 ];
73 elem.removeAttribute( "type" );
79 function cloneCopyEvent( src, dest ) {
80 var i, l, type, pdataOld, pdataCur, udataOld, udataCur, events;
82 if ( dest.nodeType !== 1 ) {
86 // 1. Copy private data: events, handlers, etc.
87 if ( dataPriv.hasData( src ) ) {
88 pdataOld = dataPriv.access( src );
89 pdataCur = dataPriv.set( dest, pdataOld );
90 events = pdataOld.events;
93 delete pdataCur.handle;
96 for ( type in events ) {
97 for ( i = 0, l = events[ type ].length; i < l; i++ ) {
98 jQuery.event.add( dest, type, events[ type ][ i ] );
105 if ( dataUser.hasData( src ) ) {
106 udataOld = dataUser.access( src );
107 udataCur = jQuery.extend( {}, udataOld );
109 dataUser.set( dest, udataCur );
113 // Fix IE bugs, see support tests
114 function fixInput( src, dest ) {
115 var nodeName = dest.nodeName.toLowerCase();
117 // Fails to persist the checked state of a cloned checkbox or radio button.
118 if ( nodeName === "input" && rcheckableType.test( src.type ) ) {
119 dest.checked = src.checked;
121 // Fails to return the selected option to the default selected state when cloning options
122 } else if ( nodeName === "input" || nodeName === "textarea" ) {
123 dest.defaultValue = src.defaultValue;
127 function domManip( collection, args, callback, ignored ) {
129 // Flatten any nested arrays
130 args = concat.apply( [], args );
132 var fragment, first, scripts, hasScripts, node, doc,
134 l = collection.length,
137 isFunction = jQuery.isFunction( value );
139 // We can't cloneNode fragments that contain checked, in WebKit
141 ( l > 1 && typeof value === "string" &&
142 !support.checkClone && rchecked.test( value ) ) ) {
143 return collection.each( function( index ) {
144 var self = collection.eq( index );
146 args[ 0 ] = value.call( this, index, self.html() );
148 domManip( self, args, callback, ignored );
153 fragment = buildFragment( args, collection[ 0 ].ownerDocument, false, collection, ignored );
154 first = fragment.firstChild;
156 if ( fragment.childNodes.length === 1 ) {
160 // Require either new content or an interest in ignored elements to invoke the callback
161 if ( first || ignored ) {
162 scripts = jQuery.map( getAll( fragment, "script" ), disableScript );
163 hasScripts = scripts.length;
165 // Use the original fragment for the last item
166 // instead of the first because it can end up
167 // being emptied incorrectly in certain situations (#8070).
168 for ( ; i < l; i++ ) {
171 if ( i !== iNoClone ) {
172 node = jQuery.clone( node, true, true );
174 // Keep references to cloned scripts for later restoration
177 // Support: Android <=4.0 only, PhantomJS 1 only
178 // push.apply(_, arraylike) throws on ancient WebKit
179 jQuery.merge( scripts, getAll( node, "script" ) );
183 callback.call( collection[ i ], node, i );
187 doc = scripts[ scripts.length - 1 ].ownerDocument;
190 jQuery.map( scripts, restoreScript );
192 // Evaluate executable scripts on first document insertion
193 for ( i = 0; i < hasScripts; i++ ) {
195 if ( rscriptType.test( node.type || "" ) &&
196 !dataPriv.access( node, "globalEval" ) &&
197 jQuery.contains( doc, node ) ) {
201 // Optional AJAX dependency, but won't run scripts if not present
202 if ( jQuery._evalUrl ) {
203 jQuery._evalUrl( node.src );
206 DOMEval( node.textContent.replace( rcleanScript, "" ), doc );
217 function remove( elem, selector, keepData ) {
219 nodes = selector ? jQuery.filter( selector, elem ) : elem,
222 for ( ; ( node = nodes[ i ] ) != null; i++ ) {
223 if ( !keepData && node.nodeType === 1 ) {
224 jQuery.cleanData( getAll( node ) );
227 if ( node.parentNode ) {
228 if ( keepData && jQuery.contains( node.ownerDocument, node ) ) {
229 setGlobalEval( getAll( node, "script" ) );
231 node.parentNode.removeChild( node );
239 htmlPrefilter: function( html ) {
240 return html.replace( rxhtmlTag, "<$1></$2>" );
243 clone: function( elem, dataAndEvents, deepDataAndEvents ) {
244 var i, l, srcElements, destElements,
245 clone = elem.cloneNode( true ),
246 inPage = jQuery.contains( elem.ownerDocument, elem );
248 // Fix IE cloning issues
249 if ( !support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) &&
250 !jQuery.isXMLDoc( elem ) ) {
252 // We eschew Sizzle here for performance reasons: https://jsperf.com/getall-vs-sizzle/2
253 destElements = getAll( clone );
254 srcElements = getAll( elem );
256 for ( i = 0, l = srcElements.length; i < l; i++ ) {
257 fixInput( srcElements[ i ], destElements[ i ] );
261 // Copy the events from the original to the clone
262 if ( dataAndEvents ) {
263 if ( deepDataAndEvents ) {
264 srcElements = srcElements || getAll( elem );
265 destElements = destElements || getAll( clone );
267 for ( i = 0, l = srcElements.length; i < l; i++ ) {
268 cloneCopyEvent( srcElements[ i ], destElements[ i ] );
271 cloneCopyEvent( elem, clone );
275 // Preserve script evaluation history
276 destElements = getAll( clone, "script" );
277 if ( destElements.length > 0 ) {
278 setGlobalEval( destElements, !inPage && getAll( elem, "script" ) );
281 // Return the cloned set
285 cleanData: function( elems ) {
286 var data, elem, type,
287 special = jQuery.event.special,
290 for ( ; ( elem = elems[ i ] ) !== undefined; i++ ) {
291 if ( acceptData( elem ) ) {
292 if ( ( data = elem[ dataPriv.expando ] ) ) {
294 for ( type in data.events ) {
295 if ( special[ type ] ) {
296 jQuery.event.remove( elem, type );
298 // This is a shortcut to avoid jQuery.event.remove's overhead
300 jQuery.removeEvent( elem, type, data.handle );
305 // Support: Chrome <=35 - 45+
306 // Assign undefined instead of using delete, see Data#remove
307 elem[ dataPriv.expando ] = undefined;
309 if ( elem[ dataUser.expando ] ) {
311 // Support: Chrome <=35 - 45+
312 // Assign undefined instead of using delete, see Data#remove
313 elem[ dataUser.expando ] = undefined;
321 detach: function( selector ) {
322 return remove( this, selector, true );
325 remove: function( selector ) {
326 return remove( this, selector );
329 text: function( value ) {
330 return access( this, function( value ) {
331 return value === undefined ?
332 jQuery.text( this ) :
333 this.empty().each( function() {
334 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
335 this.textContent = value;
338 }, null, value, arguments.length );
342 return domManip( this, arguments, function( elem ) {
343 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
344 var target = manipulationTarget( this, elem );
345 target.appendChild( elem );
350 prepend: function() {
351 return domManip( this, arguments, function( elem ) {
352 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
353 var target = manipulationTarget( this, elem );
354 target.insertBefore( elem, target.firstChild );
360 return domManip( this, arguments, function( elem ) {
361 if ( this.parentNode ) {
362 this.parentNode.insertBefore( elem, this );
368 return domManip( this, arguments, function( elem ) {
369 if ( this.parentNode ) {
370 this.parentNode.insertBefore( elem, this.nextSibling );
379 for ( ; ( elem = this[ i ] ) != null; i++ ) {
380 if ( elem.nodeType === 1 ) {
382 // Prevent memory leaks
383 jQuery.cleanData( getAll( elem, false ) );
385 // Remove any remaining nodes
386 elem.textContent = "";
393 clone: function( dataAndEvents, deepDataAndEvents ) {
394 dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
395 deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
397 return this.map( function() {
398 return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
402 html: function( value ) {
403 return access( this, function( value ) {
404 var elem = this[ 0 ] || {},
408 if ( value === undefined && elem.nodeType === 1 ) {
409 return elem.innerHTML;
412 // See if we can take a shortcut and just use innerHTML
413 if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
414 !wrapMap[ ( rtagName.exec( value ) || [ "", "" ] )[ 1 ].toLowerCase() ] ) {
416 value = jQuery.htmlPrefilter( value );
419 for ( ; i < l; i++ ) {
420 elem = this[ i ] || {};
422 // Remove element nodes and prevent memory leaks
423 if ( elem.nodeType === 1 ) {
424 jQuery.cleanData( getAll( elem, false ) );
425 elem.innerHTML = value;
431 // If using innerHTML throws an exception, use the fallback method
436 this.empty().append( value );
438 }, null, value, arguments.length );
441 replaceWith: function() {
444 // Make the changes, replacing each non-ignored context element with the new content
445 return domManip( this, arguments, function( elem ) {
446 var parent = this.parentNode;
448 if ( jQuery.inArray( this, ignored ) < 0 ) {
449 jQuery.cleanData( getAll( this ) );
451 parent.replaceChild( elem, this );
455 // Force callback invocation
462 prependTo: "prepend",
463 insertBefore: "before",
464 insertAfter: "after",
465 replaceAll: "replaceWith"
466 }, function( name, original ) {
467 jQuery.fn[ name ] = function( selector ) {
470 insert = jQuery( selector ),
471 last = insert.length - 1,
474 for ( ; i <= last; i++ ) {
475 elems = i === last ? this : this.clone( true );
476 jQuery( insert[ i ] )[ original ]( elems );
478 // Support: Android <=4.0 only, PhantomJS 1 only
479 // .get() because push.apply(_, arraylike) throws on ancient WebKit
480 push.apply( ret, elems.get() );
483 return this.pushStack( ret );