Blame view

app/bower_components/jquery/src/manipulation.js 12.1 KB
87c93a029   Dang YoungWorld   add modal
1
  define( [
f986e111b   TRUONG   add libs
2
  	"./core",
f986e111b   TRUONG   add libs
3
4
  	"./var/concat",
  	"./var/push",
f986e111b   TRUONG   add libs
5
6
  	"./core/access",
  	"./manipulation/var/rcheckableType",
87c93a029   Dang YoungWorld   add modal
7
8
9
10
11
12
  	"./manipulation/var/rtagName",
  	"./manipulation/var/rscriptType",
  	"./manipulation/wrapMap",
  	"./manipulation/getAll",
  	"./manipulation/setGlobalEval",
  	"./manipulation/buildFragment",
f986e111b   TRUONG   add libs
13
  	"./manipulation/support",
87c93a029   Dang YoungWorld   add modal
14
15
16
17
  	"./data/var/dataPriv",
  	"./data/var/dataUser",
  	"./data/var/acceptData",
  	"./core/DOMEval",
f986e111b   TRUONG   add libs
18
  	"./core/init",
f986e111b   TRUONG   add libs
19
20
21
  	"./traversing",
  	"./selector",
  	"./event"
87c93a029   Dang YoungWorld   add modal
22
23
24
25
  ], function( jQuery, concat, push, access,
  	rcheckableType, rtagName, rscriptType,
  	wrapMap, getAll, setGlobalEval, buildFragment, support,
  	dataPriv, dataUser, acceptData, DOMEval ) {
f986e111b   TRUONG   add libs
26

87c93a029   Dang YoungWorld   add modal
27
  "use strict";
f986e111b   TRUONG   add libs
28

87c93a029   Dang YoungWorld   add modal
29
  var
f986e111b   TRUONG   add libs
30

87c93a029   Dang YoungWorld   add modal
31
  	/* eslint-disable max-len */
f986e111b   TRUONG   add libs
32

87c93a029   Dang YoungWorld   add modal
33
34
35
  	// See https://github.com/eslint/eslint/issues/3229
  	rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([a-z][^\/\0>\x20\t\r
  \f]*)[^>]*)\/>/gi,
f986e111b   TRUONG   add libs
36

87c93a029   Dang YoungWorld   add modal
37
  	/* eslint-enable */
f986e111b   TRUONG   add libs
38

87c93a029   Dang YoungWorld   add modal
39
40
41
42
  	// Support: IE <=10 - 11, Edge 12 - 13
  	// In IE/Edge using regex groups here causes severe slowdowns.
  	// See https://connect.microsoft.com/IE/feedback/details/1736512/
  	rnoInnerhtml = /<script|<style|<link/i,
f986e111b   TRUONG   add libs
43

87c93a029   Dang YoungWorld   add modal
44
45
46
47
  	// checked="checked" or checked
  	rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
  	rscriptTypeMasked = /^true\/(.*)/,
  	rcleanScript = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g;
f986e111b   TRUONG   add libs
48

f986e111b   TRUONG   add libs
49
  function manipulationTarget( elem, content ) {
87c93a029   Dang YoungWorld   add modal
50
51
  	if ( jQuery.nodeName( elem, "table" ) &&
  		jQuery.nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ) {
f986e111b   TRUONG   add libs
52

87c93a029   Dang YoungWorld   add modal
53
54
55
56
  		return elem.getElementsByTagName( "tbody" )[ 0 ] || elem;
  	}
  
  	return elem;
f986e111b   TRUONG   add libs
57
58
59
60
  }
  
  // Replace/restore the type attribute of script elements for safe DOM manipulation
  function disableScript( elem ) {
87c93a029   Dang YoungWorld   add modal
61
  	elem.type = ( elem.getAttribute( "type" ) !== null ) + "/" + elem.type;
f986e111b   TRUONG   add libs
62
63
64
65
  	return elem;
  }
  function restoreScript( elem ) {
  	var match = rscriptTypeMasked.exec( elem.type );
87c93a029   Dang YoungWorld   add modal
66

f986e111b   TRUONG   add libs
67
  	if ( match ) {
87c93a029   Dang YoungWorld   add modal
68
  		elem.type = match[ 1 ];
f986e111b   TRUONG   add libs
69
  	} else {
87c93a029   Dang YoungWorld   add modal
70
  		elem.removeAttribute( "type" );
f986e111b   TRUONG   add libs
71
  	}
f986e111b   TRUONG   add libs
72

87c93a029   Dang YoungWorld   add modal
73
  	return elem;
f986e111b   TRUONG   add libs
74
75
76
  }
  
  function cloneCopyEvent( src, dest ) {
87c93a029   Dang YoungWorld   add modal
77
  	var i, l, type, pdataOld, pdataCur, udataOld, udataCur, events;
f986e111b   TRUONG   add libs
78

87c93a029   Dang YoungWorld   add modal
79
  	if ( dest.nodeType !== 1 ) {
f986e111b   TRUONG   add libs
80
81
  		return;
  	}
87c93a029   Dang YoungWorld   add modal
82
83
84
85
86
  	// 1. Copy private data: events, handlers, etc.
  	if ( dataPriv.hasData( src ) ) {
  		pdataOld = dataPriv.access( src );
  		pdataCur = dataPriv.set( dest, pdataOld );
  		events = pdataOld.events;
f986e111b   TRUONG   add libs
87

87c93a029   Dang YoungWorld   add modal
88
89
90
  		if ( events ) {
  			delete pdataCur.handle;
  			pdataCur.events = {};
f986e111b   TRUONG   add libs
91

87c93a029   Dang YoungWorld   add modal
92
93
94
95
  			for ( type in events ) {
  				for ( i = 0, l = events[ type ].length; i < l; i++ ) {
  					jQuery.event.add( dest, type, events[ type ][ i ] );
  				}
f986e111b   TRUONG   add libs
96
97
98
  			}
  		}
  	}
87c93a029   Dang YoungWorld   add modal
99
100
101
102
103
104
  	// 2. Copy user data
  	if ( dataUser.hasData( src ) ) {
  		udataOld = dataUser.access( src );
  		udataCur = jQuery.extend( {}, udataOld );
  
  		dataUser.set( dest, udataCur );
f986e111b   TRUONG   add libs
105
106
  	}
  }
87c93a029   Dang YoungWorld   add modal
107
108
109
  // Fix IE bugs, see support tests
  function fixInput( src, dest ) {
  	var nodeName = dest.nodeName.toLowerCase();
f986e111b   TRUONG   add libs
110

87c93a029   Dang YoungWorld   add modal
111
112
113
  	// Fails to persist the checked state of a cloned checkbox or radio button.
  	if ( nodeName === "input" && rcheckableType.test( src.type ) ) {
  		dest.checked = src.checked;
f986e111b   TRUONG   add libs
114

87c93a029   Dang YoungWorld   add modal
115
116
117
118
119
  	// Fails to return the selected option to the default selected state when cloning options
  	} else if ( nodeName === "input" || nodeName === "textarea" ) {
  		dest.defaultValue = src.defaultValue;
  	}
  }
f986e111b   TRUONG   add libs
120

87c93a029   Dang YoungWorld   add modal
121
  function domManip( collection, args, callback, ignored ) {
f986e111b   TRUONG   add libs
122

87c93a029   Dang YoungWorld   add modal
123
124
  	// Flatten any nested arrays
  	args = concat.apply( [], args );
f986e111b   TRUONG   add libs
125

87c93a029   Dang YoungWorld   add modal
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
  	var fragment, first, scripts, hasScripts, node, doc,
  		i = 0,
  		l = collection.length,
  		iNoClone = l - 1,
  		value = args[ 0 ],
  		isFunction = jQuery.isFunction( value );
  
  	// We can't cloneNode fragments that contain checked, in WebKit
  	if ( isFunction ||
  			( l > 1 && typeof value === "string" &&
  				!support.checkClone && rchecked.test( value ) ) ) {
  		return collection.each( function( index ) {
  			var self = collection.eq( index );
  			if ( isFunction ) {
  				args[ 0 ] = value.call( this, index, self.html() );
  			}
  			domManip( self, args, callback, ignored );
  		} );
f986e111b   TRUONG   add libs
144
  	}
87c93a029   Dang YoungWorld   add modal
145
146
147
  	if ( l ) {
  		fragment = buildFragment( args, collection[ 0 ].ownerDocument, false, collection, ignored );
  		first = fragment.firstChild;
f986e111b   TRUONG   add libs
148

87c93a029   Dang YoungWorld   add modal
149
150
  		if ( fragment.childNodes.length === 1 ) {
  			fragment = first;
f986e111b   TRUONG   add libs
151
  		}
87c93a029   Dang YoungWorld   add modal
152
153
154
155
  		// Require either new content or an interest in ignored elements to invoke the callback
  		if ( first || ignored ) {
  			scripts = jQuery.map( getAll( fragment, "script" ), disableScript );
  			hasScripts = scripts.length;
f986e111b   TRUONG   add libs
156

87c93a029   Dang YoungWorld   add modal
157
158
159
160
161
  			// Use the original fragment for the last item
  			// instead of the first because it can end up
  			// being emptied incorrectly in certain situations (#8070).
  			for ( ; i < l; i++ ) {
  				node = fragment;
f986e111b   TRUONG   add libs
162

87c93a029   Dang YoungWorld   add modal
163
164
  				if ( i !== iNoClone ) {
  					node = jQuery.clone( node, true, true );
f986e111b   TRUONG   add libs
165

87c93a029   Dang YoungWorld   add modal
166
167
  					// Keep references to cloned scripts for later restoration
  					if ( hasScripts ) {
f986e111b   TRUONG   add libs
168

87c93a029   Dang YoungWorld   add modal
169
170
171
172
173
  						// Support: Android <=4.0 only, PhantomJS 1 only
  						// push.apply(_, arraylike) throws on ancient WebKit
  						jQuery.merge( scripts, getAll( node, "script" ) );
  					}
  				}
f986e111b   TRUONG   add libs
174

87c93a029   Dang YoungWorld   add modal
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
  				callback.call( collection[ i ], node, i );
  			}
  
  			if ( hasScripts ) {
  				doc = scripts[ scripts.length - 1 ].ownerDocument;
  
  				// Reenable scripts
  				jQuery.map( scripts, restoreScript );
  
  				// Evaluate executable scripts on first document insertion
  				for ( i = 0; i < hasScripts; i++ ) {
  					node = scripts[ i ];
  					if ( rscriptType.test( node.type || "" ) &&
  						!dataPriv.access( node, "globalEval" ) &&
  						jQuery.contains( doc, node ) ) {
  
  						if ( node.src ) {
  
  							// Optional AJAX dependency, but won't run scripts if not present
  							if ( jQuery._evalUrl ) {
  								jQuery._evalUrl( node.src );
  							}
  						} else {
  							DOMEval( node.textContent.replace( rcleanScript, "" ), doc );
  						}
  					}
  				}
  			}
  		}
f986e111b   TRUONG   add libs
204
  	}
87c93a029   Dang YoungWorld   add modal
205
206
  
  	return collection;
f986e111b   TRUONG   add libs
207
  }
87c93a029   Dang YoungWorld   add modal
208
209
210
211
  function remove( elem, selector, keepData ) {
  	var node,
  		nodes = selector ? jQuery.filter( selector, elem ) : elem,
  		i = 0;
f986e111b   TRUONG   add libs
212

87c93a029   Dang YoungWorld   add modal
213
214
215
216
  	for ( ; ( node = nodes[ i ] ) != null; i++ ) {
  		if ( !keepData && node.nodeType === 1 ) {
  			jQuery.cleanData( getAll( node ) );
  		}
f986e111b   TRUONG   add libs
217

87c93a029   Dang YoungWorld   add modal
218
219
220
221
222
  		if ( node.parentNode ) {
  			if ( keepData && jQuery.contains( node.ownerDocument, node ) ) {
  				setGlobalEval( getAll( node, "script" ) );
  			}
  			node.parentNode.removeChild( node );
f986e111b   TRUONG   add libs
223
  		}
87c93a029   Dang YoungWorld   add modal
224
225
226
227
228
229
230
231
232
233
234
235
236
237
  	}
  
  	return elem;
  }
  
  jQuery.extend( {
  	htmlPrefilter: function( html ) {
  		return html.replace( rxhtmlTag, "<$1></$2>" );
  	},
  
  	clone: function( elem, dataAndEvents, deepDataAndEvents ) {
  		var i, l, srcElements, destElements,
  			clone = elem.cloneNode( true ),
  			inPage = jQuery.contains( elem.ownerDocument, elem );
f986e111b   TRUONG   add libs
238

87c93a029   Dang YoungWorld   add modal
239
240
241
  		// Fix IE cloning issues
  		if ( !support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) &&
  				!jQuery.isXMLDoc( elem ) ) {
f986e111b   TRUONG   add libs
242

87c93a029   Dang YoungWorld   add modal
243
  			// We eschew Sizzle here for performance reasons: https://jsperf.com/getall-vs-sizzle/2
f986e111b   TRUONG   add libs
244
245
  			destElements = getAll( clone );
  			srcElements = getAll( elem );
87c93a029   Dang YoungWorld   add modal
246
247
  			for ( i = 0, l = srcElements.length; i < l; i++ ) {
  				fixInput( srcElements[ i ], destElements[ i ] );
f986e111b   TRUONG   add libs
248
249
250
251
252
253
254
255
  			}
  		}
  
  		// Copy the events from the original to the clone
  		if ( dataAndEvents ) {
  			if ( deepDataAndEvents ) {
  				srcElements = srcElements || getAll( elem );
  				destElements = destElements || getAll( clone );
87c93a029   Dang YoungWorld   add modal
256
257
  				for ( i = 0, l = srcElements.length; i < l; i++ ) {
  					cloneCopyEvent( srcElements[ i ], destElements[ i ] );
f986e111b   TRUONG   add libs
258
259
260
261
262
263
264
265
266
267
268
  				}
  			} else {
  				cloneCopyEvent( elem, clone );
  			}
  		}
  
  		// Preserve script evaluation history
  		destElements = getAll( clone, "script" );
  		if ( destElements.length > 0 ) {
  			setGlobalEval( destElements, !inPage && getAll( elem, "script" ) );
  		}
f986e111b   TRUONG   add libs
269
270
271
  		// Return the cloned set
  		return clone;
  	},
87c93a029   Dang YoungWorld   add modal
272
273
274
  	cleanData: function( elems ) {
  		var data, elem, type,
  			special = jQuery.event.special,
f986e111b   TRUONG   add libs
275
  			i = 0;
87c93a029   Dang YoungWorld   add modal
276
277
278
  		for ( ; ( elem = elems[ i ] ) !== undefined; i++ ) {
  			if ( acceptData( elem ) ) {
  				if ( ( data = elem[ dataPriv.expando ] ) ) {
f986e111b   TRUONG   add libs
279
280
281
282
283
284
285
286
287
288
289
  					if ( data.events ) {
  						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 );
  							}
  						}
  					}
87c93a029   Dang YoungWorld   add modal
290
291
292
293
294
  					// Support: Chrome <=35 - 45+
  					// Assign undefined instead of using delete, see Data#remove
  					elem[ dataPriv.expando ] = undefined;
  				}
  				if ( elem[ dataUser.expando ] ) {
f986e111b   TRUONG   add libs
295

87c93a029   Dang YoungWorld   add modal
296
297
298
  					// Support: Chrome <=35 - 45+
  					// Assign undefined instead of using delete, see Data#remove
  					elem[ dataUser.expando ] = undefined;
f986e111b   TRUONG   add libs
299
300
301
302
  				}
  			}
  		}
  	}
87c93a029   Dang YoungWorld   add modal
303
304
305
306
307
308
309
310
311
312
  } );
  
  jQuery.fn.extend( {
  	detach: function( selector ) {
  		return remove( this, selector, true );
  	},
  
  	remove: function( selector ) {
  		return remove( this, selector );
  	},
f986e111b   TRUONG   add libs
313

f986e111b   TRUONG   add libs
314
315
316
317
  	text: function( value ) {
  		return access( this, function( value ) {
  			return value === undefined ?
  				jQuery.text( this ) :
87c93a029   Dang YoungWorld   add modal
318
319
320
321
322
  				this.empty().each( function() {
  					if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
  						this.textContent = value;
  					}
  				} );
f986e111b   TRUONG   add libs
323
324
325
326
  		}, null, value, arguments.length );
  	},
  
  	append: function() {
87c93a029   Dang YoungWorld   add modal
327
  		return domManip( this, arguments, function( elem ) {
f986e111b   TRUONG   add libs
328
329
330
331
  			if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
  				var target = manipulationTarget( this, elem );
  				target.appendChild( elem );
  			}
87c93a029   Dang YoungWorld   add modal
332
  		} );
f986e111b   TRUONG   add libs
333
334
335
  	},
  
  	prepend: function() {
87c93a029   Dang YoungWorld   add modal
336
  		return domManip( this, arguments, function( elem ) {
f986e111b   TRUONG   add libs
337
338
339
340
  			if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
  				var target = manipulationTarget( this, elem );
  				target.insertBefore( elem, target.firstChild );
  			}
87c93a029   Dang YoungWorld   add modal
341
  		} );
f986e111b   TRUONG   add libs
342
343
344
  	},
  
  	before: function() {
87c93a029   Dang YoungWorld   add modal
345
  		return domManip( this, arguments, function( elem ) {
f986e111b   TRUONG   add libs
346
347
348
  			if ( this.parentNode ) {
  				this.parentNode.insertBefore( elem, this );
  			}
87c93a029   Dang YoungWorld   add modal
349
  		} );
f986e111b   TRUONG   add libs
350
351
352
  	},
  
  	after: function() {
87c93a029   Dang YoungWorld   add modal
353
  		return domManip( this, arguments, function( elem ) {
f986e111b   TRUONG   add libs
354
355
356
  			if ( this.parentNode ) {
  				this.parentNode.insertBefore( elem, this.nextSibling );
  			}
87c93a029   Dang YoungWorld   add modal
357
  		} );
f986e111b   TRUONG   add libs
358
359
360
361
362
  	},
  
  	empty: function() {
  		var elem,
  			i = 0;
87c93a029   Dang YoungWorld   add modal
363
  		for ( ; ( elem = this[ i ] ) != null; i++ ) {
f986e111b   TRUONG   add libs
364
  			if ( elem.nodeType === 1 ) {
f986e111b   TRUONG   add libs
365

87c93a029   Dang YoungWorld   add modal
366
367
  				// Prevent memory leaks
  				jQuery.cleanData( getAll( elem, false ) );
f986e111b   TRUONG   add libs
368

87c93a029   Dang YoungWorld   add modal
369
370
  				// Remove any remaining nodes
  				elem.textContent = "";
f986e111b   TRUONG   add libs
371
372
373
374
375
376
377
378
379
  			}
  		}
  
  		return this;
  	},
  
  	clone: function( dataAndEvents, deepDataAndEvents ) {
  		dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
  		deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
87c93a029   Dang YoungWorld   add modal
380
  		return this.map( function() {
f986e111b   TRUONG   add libs
381
  			return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
87c93a029   Dang YoungWorld   add modal
382
  		} );
f986e111b   TRUONG   add libs
383
384
385
386
387
388
389
  	},
  
  	html: function( value ) {
  		return access( this, function( value ) {
  			var elem = this[ 0 ] || {},
  				i = 0,
  				l = this.length;
87c93a029   Dang YoungWorld   add modal
390
391
  			if ( value === undefined && elem.nodeType === 1 ) {
  				return elem.innerHTML;
f986e111b   TRUONG   add libs
392
393
394
395
  			}
  
  			// See if we can take a shortcut and just use innerHTML
  			if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
87c93a029   Dang YoungWorld   add modal
396
  				!wrapMap[ ( rtagName.exec( value ) || [ "", "" ] )[ 1 ].toLowerCase() ] ) {
f986e111b   TRUONG   add libs
397

87c93a029   Dang YoungWorld   add modal
398
  				value = jQuery.htmlPrefilter( value );
f986e111b   TRUONG   add libs
399
400
  
  				try {
87c93a029   Dang YoungWorld   add modal
401
402
  					for ( ; i < l; i++ ) {
  						elem = this[ i ] || {};
f986e111b   TRUONG   add libs
403
  						// Remove element nodes and prevent memory leaks
f986e111b   TRUONG   add libs
404
405
406
407
408
409
410
411
412
  						if ( elem.nodeType === 1 ) {
  							jQuery.cleanData( getAll( elem, false ) );
  							elem.innerHTML = value;
  						}
  					}
  
  					elem = 0;
  
  				// If using innerHTML throws an exception, use the fallback method
87c93a029   Dang YoungWorld   add modal
413
  				} catch ( e ) {}
f986e111b   TRUONG   add libs
414
415
416
417
418
419
420
421
422
  			}
  
  			if ( elem ) {
  				this.empty().append( value );
  			}
  		}, null, value, arguments.length );
  	},
  
  	replaceWith: function() {
87c93a029   Dang YoungWorld   add modal
423
  		var ignored = [];
f986e111b   TRUONG   add libs
424

87c93a029   Dang YoungWorld   add modal
425
426
427
  		// Make the changes, replacing each non-ignored context element with the new content
  		return domManip( this, arguments, function( elem ) {
  			var parent = this.parentNode;
f986e111b   TRUONG   add libs
428

87c93a029   Dang YoungWorld   add modal
429
430
431
432
  			if ( jQuery.inArray( this, ignored ) < 0 ) {
  				jQuery.cleanData( getAll( this ) );
  				if ( parent ) {
  					parent.replaceChild( elem, this );
f986e111b   TRUONG   add libs
433
  				}
f986e111b   TRUONG   add libs
434
  			}
f986e111b   TRUONG   add libs
435

87c93a029   Dang YoungWorld   add modal
436
437
  		// Force callback invocation
  		}, ignored );
f986e111b   TRUONG   add libs
438
  	}
87c93a029   Dang YoungWorld   add modal
439
  } );
f986e111b   TRUONG   add libs
440

87c93a029   Dang YoungWorld   add modal
441
  jQuery.each( {
f986e111b   TRUONG   add libs
442
443
444
445
446
447
448
449
  	appendTo: "append",
  	prependTo: "prepend",
  	insertBefore: "before",
  	insertAfter: "after",
  	replaceAll: "replaceWith"
  }, function( name, original ) {
  	jQuery.fn[ name ] = function( selector ) {
  		var elems,
f986e111b   TRUONG   add libs
450
451
  			ret = [],
  			insert = jQuery( selector ),
87c93a029   Dang YoungWorld   add modal
452
453
  			last = insert.length - 1,
  			i = 0;
f986e111b   TRUONG   add libs
454
455
  
  		for ( ; i <= last; i++ ) {
87c93a029   Dang YoungWorld   add modal
456
457
  			elems = i === last ? this : this.clone( true );
  			jQuery( insert[ i ] )[ original ]( elems );
f986e111b   TRUONG   add libs
458

87c93a029   Dang YoungWorld   add modal
459
460
  			// Support: Android <=4.0 only, PhantomJS 1 only
  			// .get() because push.apply(_, arraylike) throws on ancient WebKit
f986e111b   TRUONG   add libs
461
462
463
464
465
  			push.apply( ret, elems.get() );
  		}
  
  		return this.pushStack( ret );
  	};
87c93a029   Dang YoungWorld   add modal
466
  } );
f986e111b   TRUONG   add libs
467
468
  
  return jQuery;
87c93a029   Dang YoungWorld   add modal
469
  } );