Blame view

bower_components/jquery/src/manipulation.js 12 KB
a1a3bc73   Luigi Serra   graphs updates
1
  define( [
74249687   Luigi Serra   Cross browser con...
2
3
4
5
6
  	"./core",
  	"./var/concat",
  	"./var/push",
  	"./core/access",
  	"./manipulation/var/rcheckableType",
a1a3bc73   Luigi Serra   graphs updates
7
8
9
10
11
12
  	"./manipulation/var/rtagName",
  	"./manipulation/var/rscriptType",
  	"./manipulation/wrapMap",
  	"./manipulation/getAll",
  	"./manipulation/setGlobalEval",
  	"./manipulation/buildFragment",
74249687   Luigi Serra   Cross browser con...
13
  	"./manipulation/support",
a1a3bc73   Luigi Serra   graphs updates
14
15
16
17
  
  	"./data/var/dataPriv",
  	"./data/var/dataUser",
  	"./data/var/acceptData",
74249687   Luigi Serra   Cross browser con...
18
19
  
  	"./core/init",
74249687   Luigi Serra   Cross browser con...
20
21
22
  	"./traversing",
  	"./selector",
  	"./event"
a1a3bc73   Luigi Serra   graphs updates
23
24
25
26
  ], function( jQuery, concat, push, access,
  	rcheckableType, rtagName, rscriptType,
  	wrapMap, getAll, setGlobalEval, buildFragment, support,
  	dataPriv, dataUser, acceptData ) {
74249687   Luigi Serra   Cross browser con...
27
28
  
  var
a1a3bc73   Luigi Serra   graphs updates
29
30
31
32
33
34
35
  	rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:-]+)[^>]*)\/>/gi,
  
  	// Support: IE 10-11, Edge 10240+
  	// In IE/Edge using regex groups here causes severe slowdowns.
  	// See https://connect.microsoft.com/IE/feedback/details/1736512/
  	rnoInnerhtml = /<script|<style|<link/i,
  
74249687   Luigi Serra   Cross browser con...
36
37
  	// checked="checked" or checked
  	rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
74249687   Luigi Serra   Cross browser con...
38
  	rscriptTypeMasked = /^true\/(.*)/,
a1a3bc73   Luigi Serra   graphs updates
39
  	rcleanScript = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g;
74249687   Luigi Serra   Cross browser con...
40
  
74249687   Luigi Serra   Cross browser con...
41
  function manipulationTarget( elem, content ) {
a1a3bc73   Luigi Serra   graphs updates
42
43
44
45
46
  	if ( jQuery.nodeName( elem, "table" ) &&
  		jQuery.nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ) {
  
  		return elem.getElementsByTagName( "tbody" )[ 0 ] || elem;
  	}
74249687   Luigi Serra   Cross browser con...
47
  
a1a3bc73   Luigi Serra   graphs updates
48
  	return elem;
74249687   Luigi Serra   Cross browser con...
49
50
51
52
  }
  
  // Replace/restore the type attribute of script elements for safe DOM manipulation
  function disableScript( elem ) {
a1a3bc73   Luigi Serra   graphs updates
53
  	elem.type = ( elem.getAttribute( "type" ) !== null ) + "/" + elem.type;
74249687   Luigi Serra   Cross browser con...
54
55
56
57
58
59
60
61
  	return elem;
  }
  function restoreScript( elem ) {
  	var match = rscriptTypeMasked.exec( elem.type );
  
  	if ( match ) {
  		elem.type = match[ 1 ];
  	} else {
a1a3bc73   Luigi Serra   graphs updates
62
  		elem.removeAttribute( "type" );
74249687   Luigi Serra   Cross browser con...
63
64
65
66
67
  	}
  
  	return elem;
  }
  
74249687   Luigi Serra   Cross browser con...
68
69
70
71
72
73
74
75
  function cloneCopyEvent( src, dest ) {
  	var i, l, type, pdataOld, pdataCur, udataOld, udataCur, events;
  
  	if ( dest.nodeType !== 1 ) {
  		return;
  	}
  
  	// 1. Copy private data: events, handlers, etc.
a1a3bc73   Luigi Serra   graphs updates
76
77
78
  	if ( dataPriv.hasData( src ) ) {
  		pdataOld = dataPriv.access( src );
  		pdataCur = dataPriv.set( dest, pdataOld );
74249687   Luigi Serra   Cross browser con...
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
  		events = pdataOld.events;
  
  		if ( events ) {
  			delete pdataCur.handle;
  			pdataCur.events = {};
  
  			for ( type in events ) {
  				for ( i = 0, l = events[ type ].length; i < l; i++ ) {
  					jQuery.event.add( dest, type, events[ type ][ i ] );
  				}
  			}
  		}
  	}
  
  	// 2. Copy user data
a1a3bc73   Luigi Serra   graphs updates
94
95
  	if ( dataUser.hasData( src ) ) {
  		udataOld = dataUser.access( src );
74249687   Luigi Serra   Cross browser con...
96
97
  		udataCur = jQuery.extend( {}, udataOld );
  
a1a3bc73   Luigi Serra   graphs updates
98
  		dataUser.set( dest, udataCur );
74249687   Luigi Serra   Cross browser con...
99
100
101
  	}
  }
  
74249687   Luigi Serra   Cross browser con...
102
103
104
105
106
107
108
109
110
111
112
113
114
115
  // Fix IE bugs, see support tests
  function fixInput( src, dest ) {
  	var nodeName = dest.nodeName.toLowerCase();
  
  	// Fails to persist the checked state of a cloned checkbox or radio button.
  	if ( nodeName === "input" && rcheckableType.test( src.type ) ) {
  		dest.checked = src.checked;
  
  	// Fails to return the selected option to the default selected state when cloning options
  	} else if ( nodeName === "input" || nodeName === "textarea" ) {
  		dest.defaultValue = src.defaultValue;
  	}
  }
  
a1a3bc73   Luigi Serra   graphs updates
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
  function domManip( collection, args, callback, ignored ) {
  
  	// Flatten any nested arrays
  	args = concat.apply( [], args );
  
  	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 );
  		} );
  	}
  
  	if ( l ) {
  		fragment = buildFragment( args, collection[ 0 ].ownerDocument, false, collection, ignored );
  		first = fragment.firstChild;
  
  		if ( fragment.childNodes.length === 1 ) {
  			fragment = first;
  		}
  
  		// 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;
  
  			// 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;
  
  				if ( i !== iNoClone ) {
  					node = jQuery.clone( node, true, true );
  
  					// Keep references to cloned scripts for later restoration
  					if ( hasScripts ) {
  
  						// Support: Android<4.1, PhantomJS<2
  						// push.apply(_, arraylike) throws on ancient WebKit
  						jQuery.merge( scripts, getAll( node, "script" ) );
  					}
  				}
  
  				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 {
  							jQuery.globalEval( node.textContent.replace( rcleanScript, "" ) );
  						}
  					}
  				}
  			}
  		}
  	}
  
  	return collection;
  }
  
  function remove( elem, selector, keepData ) {
  	var node,
  		nodes = selector ? jQuery.filter( selector, elem ) : elem,
  		i = 0;
  
  	for ( ; ( node = nodes[ i ] ) != null; i++ ) {
  		if ( !keepData && node.nodeType === 1 ) {
  			jQuery.cleanData( getAll( node ) );
  		}
  
  		if ( node.parentNode ) {
  			if ( keepData && jQuery.contains( node.ownerDocument, node ) ) {
  				setGlobalEval( getAll( node, "script" ) );
  			}
  			node.parentNode.removeChild( node );
  		}
  	}
  
  	return elem;
  }
  
  jQuery.extend( {
  	htmlPrefilter: function( html ) {
  		return html.replace( rxhtmlTag, "<$1></$2>" );
  	},
  
74249687   Luigi Serra   Cross browser con...
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
  	clone: function( elem, dataAndEvents, deepDataAndEvents ) {
  		var i, l, srcElements, destElements,
  			clone = elem.cloneNode( true ),
  			inPage = jQuery.contains( elem.ownerDocument, elem );
  
  		// Fix IE cloning issues
  		if ( !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, l = srcElements.length; i < l; i++ ) {
  				fixInput( srcElements[ i ], destElements[ i ] );
  			}
  		}
  
  		// Copy the events from the original to the clone
  		if ( dataAndEvents ) {
  			if ( deepDataAndEvents ) {
  				srcElements = srcElements || getAll( elem );
  				destElements = destElements || getAll( clone );
  
  				for ( i = 0, l = srcElements.length; i < l; i++ ) {
  					cloneCopyEvent( srcElements[ i ], destElements[ i ] );
  				}
  			} else {
  				cloneCopyEvent( elem, clone );
  			}
  		}
  
  		// Preserve script evaluation history
  		destElements = getAll( clone, "script" );
  		if ( destElements.length > 0 ) {
  			setGlobalEval( destElements, !inPage && getAll( elem, "script" ) );
  		}
  
  		// Return the cloned set
  		return clone;
  	},
  
74249687   Luigi Serra   Cross browser con...
274
  	cleanData: function( elems ) {
a1a3bc73   Luigi Serra   graphs updates
275
  		var data, elem, type,
74249687   Luigi Serra   Cross browser con...
276
277
278
  			special = jQuery.event.special,
  			i = 0;
  
a1a3bc73   Luigi Serra   graphs updates
279
280
281
  		for ( ; ( elem = elems[ i ] ) !== undefined; i++ ) {
  			if ( acceptData( elem ) ) {
  				if ( ( data = elem[ dataPriv.expando ] ) ) {
74249687   Luigi Serra   Cross browser con...
282
283
284
285
286
287
288
289
290
291
292
  					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 );
  							}
  						}
  					}
a1a3bc73   Luigi Serra   graphs updates
293
294
295
296
297
298
299
300
301
302
  
  					// Support: Chrome <= 35-45+
  					// Assign undefined instead of using delete, see Data#remove
  					elem[ dataPriv.expando ] = undefined;
  				}
  				if ( elem[ dataUser.expando ] ) {
  
  					// Support: Chrome <= 35-45+
  					// Assign undefined instead of using delete, see Data#remove
  					elem[ dataUser.expando ] = undefined;
74249687   Luigi Serra   Cross browser con...
303
304
  				}
  			}
74249687   Luigi Serra   Cross browser con...
305
306
  		}
  	}
a1a3bc73   Luigi Serra   graphs updates
307
308
309
310
311
312
313
314
315
316
317
318
319
320
  } );
  
  jQuery.fn.extend( {
  
  	// Keep domManip exposed until 3.0 (gh-2225)
  	domManip: domManip,
  
  	detach: function( selector ) {
  		return remove( this, selector, true );
  	},
  
  	remove: function( selector ) {
  		return remove( this, selector );
  	},
74249687   Luigi Serra   Cross browser con...
321
  
74249687   Luigi Serra   Cross browser con...
322
323
324
325
  	text: function( value ) {
  		return access( this, function( value ) {
  			return value === undefined ?
  				jQuery.text( this ) :
a1a3bc73   Luigi Serra   graphs updates
326
  				this.empty().each( function() {
74249687   Luigi Serra   Cross browser con...
327
328
329
  					if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
  						this.textContent = value;
  					}
a1a3bc73   Luigi Serra   graphs updates
330
  				} );
74249687   Luigi Serra   Cross browser con...
331
332
333
334
  		}, null, value, arguments.length );
  	},
  
  	append: function() {
a1a3bc73   Luigi Serra   graphs updates
335
  		return domManip( this, arguments, function( elem ) {
74249687   Luigi Serra   Cross browser con...
336
337
338
339
  			if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
  				var target = manipulationTarget( this, elem );
  				target.appendChild( elem );
  			}
a1a3bc73   Luigi Serra   graphs updates
340
  		} );
74249687   Luigi Serra   Cross browser con...
341
342
343
  	},
  
  	prepend: function() {
a1a3bc73   Luigi Serra   graphs updates
344
  		return domManip( this, arguments, function( elem ) {
74249687   Luigi Serra   Cross browser con...
345
346
347
348
  			if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
  				var target = manipulationTarget( this, elem );
  				target.insertBefore( elem, target.firstChild );
  			}
a1a3bc73   Luigi Serra   graphs updates
349
  		} );
74249687   Luigi Serra   Cross browser con...
350
351
352
  	},
  
  	before: function() {
a1a3bc73   Luigi Serra   graphs updates
353
  		return domManip( this, arguments, function( elem ) {
74249687   Luigi Serra   Cross browser con...
354
355
356
  			if ( this.parentNode ) {
  				this.parentNode.insertBefore( elem, this );
  			}
a1a3bc73   Luigi Serra   graphs updates
357
  		} );
74249687   Luigi Serra   Cross browser con...
358
359
360
  	},
  
  	after: function() {
a1a3bc73   Luigi Serra   graphs updates
361
  		return domManip( this, arguments, function( elem ) {
74249687   Luigi Serra   Cross browser con...
362
363
364
  			if ( this.parentNode ) {
  				this.parentNode.insertBefore( elem, this.nextSibling );
  			}
a1a3bc73   Luigi Serra   graphs updates
365
  		} );
74249687   Luigi Serra   Cross browser con...
366
367
368
369
370
371
  	},
  
  	empty: function() {
  		var elem,
  			i = 0;
  
a1a3bc73   Luigi Serra   graphs updates
372
  		for ( ; ( elem = this[ i ] ) != null; i++ ) {
74249687   Luigi Serra   Cross browser con...
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
  			if ( elem.nodeType === 1 ) {
  
  				// Prevent memory leaks
  				jQuery.cleanData( getAll( elem, false ) );
  
  				// Remove any remaining nodes
  				elem.textContent = "";
  			}
  		}
  
  		return this;
  	},
  
  	clone: function( dataAndEvents, deepDataAndEvents ) {
  		dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
  		deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
  
a1a3bc73   Luigi Serra   graphs updates
390
  		return this.map( function() {
74249687   Luigi Serra   Cross browser con...
391
  			return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
a1a3bc73   Luigi Serra   graphs updates
392
  		} );
74249687   Luigi Serra   Cross browser con...
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
  	},
  
  	html: function( value ) {
  		return access( this, function( value ) {
  			var elem = this[ 0 ] || {},
  				i = 0,
  				l = this.length;
  
  			if ( value === undefined && elem.nodeType === 1 ) {
  				return elem.innerHTML;
  			}
  
  			// See if we can take a shortcut and just use innerHTML
  			if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
  				!wrapMap[ ( rtagName.exec( value ) || [ "", "" ] )[ 1 ].toLowerCase() ] ) {
  
a1a3bc73   Luigi Serra   graphs updates
409
  				value = jQuery.htmlPrefilter( value );
74249687   Luigi Serra   Cross browser con...
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
  
  				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;
  						}
  					}
  
  					elem = 0;
  
  				// If using innerHTML throws an exception, use the fallback method
a1a3bc73   Luigi Serra   graphs updates
425
  				} catch ( e ) {}
74249687   Luigi Serra   Cross browser con...
426
427
428
429
430
431
432
433
434
  			}
  
  			if ( elem ) {
  				this.empty().append( value );
  			}
  		}, null, value, arguments.length );
  	},
  
  	replaceWith: function() {
a1a3bc73   Luigi Serra   graphs updates
435
  		var ignored = [];
74249687   Luigi Serra   Cross browser con...
436
  
a1a3bc73   Luigi Serra   graphs updates
437
438
439
  		// Make the changes, replacing each non-ignored context element with the new content
  		return domManip( this, arguments, function( elem ) {
  			var parent = this.parentNode;
74249687   Luigi Serra   Cross browser con...
440
  
a1a3bc73   Luigi Serra   graphs updates
441
442
443
444
  			if ( jQuery.inArray( this, ignored ) < 0 ) {
  				jQuery.cleanData( getAll( this ) );
  				if ( parent ) {
  					parent.replaceChild( elem, this );
74249687   Luigi Serra   Cross browser con...
445
  				}
74249687   Luigi Serra   Cross browser con...
446
447
  			}
  
a1a3bc73   Luigi Serra   graphs updates
448
449
  		// Force callback invocation
  		}, ignored );
74249687   Luigi Serra   Cross browser con...
450
  	}
a1a3bc73   Luigi Serra   graphs updates
451
  } );
74249687   Luigi Serra   Cross browser con...
452
  
a1a3bc73   Luigi Serra   graphs updates
453
  jQuery.each( {
74249687   Luigi Serra   Cross browser con...
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
  	appendTo: "append",
  	prependTo: "prepend",
  	insertBefore: "before",
  	insertAfter: "after",
  	replaceAll: "replaceWith"
  }, function( name, original ) {
  	jQuery.fn[ name ] = function( selector ) {
  		var elems,
  			ret = [],
  			insert = jQuery( selector ),
  			last = insert.length - 1,
  			i = 0;
  
  		for ( ; i <= last; i++ ) {
  			elems = i === last ? this : this.clone( true );
  			jQuery( insert[ i ] )[ original ]( elems );
  
  			// Support: QtWebKit
  			// .get() because push.apply(_, arraylike) throws
  			push.apply( ret, elems.get() );
  		}
  
  		return this.pushStack( ret );
  	};
a1a3bc73   Luigi Serra   graphs updates
478
  } );
74249687   Luigi Serra   Cross browser con...
479
480
  
  return jQuery;
a1a3bc73   Luigi Serra   graphs updates
481
  } );