Project

General

Profile

1
define( [
2
	"./core",
3
	"./var/concat",
4
	"./var/push",
5
	"./core/access",
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",
14

    
15
	"./data/var/dataPriv",
16
	"./data/var/dataUser",
17
	"./data/var/acceptData",
18
	"./core/DOMEval",
19
	"./core/nodeName",
20

    
21
	"./core/init",
22
	"./traversing",
23
	"./selector",
24
	"./event"
25
], function( jQuery, concat, push, access,
26
	rcheckableType, rtagName, rscriptType,
27
	wrapMap, getAll, setGlobalEval, buildFragment, support,
28
	dataPriv, dataUser, acceptData, DOMEval, nodeName ) {
29

    
30
"use strict";
31

    
32
var
33

    
34
	/* eslint-disable max-len */
35

    
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,
38

    
39
	/* eslint-enable */
40

    
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,
45

    
46
	// checked="checked" or checked
47
	rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
48
	rscriptTypeMasked = /^true\/(.*)/,
49
	rcleanScript = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g;
50

    
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" ) ) {
55

    
56
		return jQuery( ">tbody", elem )[ 0 ] || elem;
57
	}
58

    
59
	return elem;
60
}
61

    
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;
65
	return elem;
66
}
67
function restoreScript( elem ) {
68
	var match = rscriptTypeMasked.exec( elem.type );
69

    
70
	if ( match ) {
71
		elem.type = match[ 1 ];
72
	} else {
73
		elem.removeAttribute( "type" );
74
	}
75

    
76
	return elem;
77
}
78

    
79
function cloneCopyEvent( src, dest ) {
80
	var i, l, type, pdataOld, pdataCur, udataOld, udataCur, events;
81

    
82
	if ( dest.nodeType !== 1 ) {
83
		return;
84
	}
85

    
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;
91

    
92
		if ( events ) {
93
			delete pdataCur.handle;
94
			pdataCur.events = {};
95

    
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 ] );
99
				}
100
			}
101
		}
102
	}
103

    
104
	// 2. Copy user data
105
	if ( dataUser.hasData( src ) ) {
106
		udataOld = dataUser.access( src );
107
		udataCur = jQuery.extend( {}, udataOld );
108

    
109
		dataUser.set( dest, udataCur );
110
	}
111
}
112

    
113
// Fix IE bugs, see support tests
114
function fixInput( src, dest ) {
115
	var nodeName = dest.nodeName.toLowerCase();
116

    
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;
120

    
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;
124
	}
125
}
126

    
127
function domManip( collection, args, callback, ignored ) {
128

    
129
	// Flatten any nested arrays
130
	args = concat.apply( [], args );
131

    
132
	var fragment, first, scripts, hasScripts, node, doc,
133
		i = 0,
134
		l = collection.length,
135
		iNoClone = l - 1,
136
		value = args[ 0 ],
137
		isFunction = jQuery.isFunction( value );
138

    
139
	// We can't cloneNode fragments that contain checked, in WebKit
140
	if ( isFunction ||
141
			( l > 1 && typeof value === "string" &&
142
				!support.checkClone && rchecked.test( value ) ) ) {
143
		return collection.each( function( index ) {
144
			var self = collection.eq( index );
145
			if ( isFunction ) {
146
				args[ 0 ] = value.call( this, index, self.html() );
147
			}
148
			domManip( self, args, callback, ignored );
149
		} );
150
	}
151

    
152
	if ( l ) {
153
		fragment = buildFragment( args, collection[ 0 ].ownerDocument, false, collection, ignored );
154
		first = fragment.firstChild;
155

    
156
		if ( fragment.childNodes.length === 1 ) {
157
			fragment = first;
158
		}
159

    
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;
164

    
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++ ) {
169
				node = fragment;
170

    
171
				if ( i !== iNoClone ) {
172
					node = jQuery.clone( node, true, true );
173

    
174
					// Keep references to cloned scripts for later restoration
175
					if ( hasScripts ) {
176

    
177
						// Support: Android <=4.0 only, PhantomJS 1 only
178
						// push.apply(_, arraylike) throws on ancient WebKit
179
						jQuery.merge( scripts, getAll( node, "script" ) );
180
					}
181
				}
182

    
183
				callback.call( collection[ i ], node, i );
184
			}
185

    
186
			if ( hasScripts ) {
187
				doc = scripts[ scripts.length - 1 ].ownerDocument;
188

    
189
				// Reenable scripts
190
				jQuery.map( scripts, restoreScript );
191

    
192
				// Evaluate executable scripts on first document insertion
193
				for ( i = 0; i < hasScripts; i++ ) {
194
					node = scripts[ i ];
195
					if ( rscriptType.test( node.type || "" ) &&
196
						!dataPriv.access( node, "globalEval" ) &&
197
						jQuery.contains( doc, node ) ) {
198

    
199
						if ( node.src ) {
200

    
201
							// Optional AJAX dependency, but won't run scripts if not present
202
							if ( jQuery._evalUrl ) {
203
								jQuery._evalUrl( node.src );
204
							}
205
						} else {
206
							DOMEval( node.textContent.replace( rcleanScript, "" ), doc );
207
						}
208
					}
209
				}
210
			}
211
		}
212
	}
213

    
214
	return collection;
215
}
216

    
217
function remove( elem, selector, keepData ) {
218
	var node,
219
		nodes = selector ? jQuery.filter( selector, elem ) : elem,
220
		i = 0;
221

    
222
	for ( ; ( node = nodes[ i ] ) != null; i++ ) {
223
		if ( !keepData && node.nodeType === 1 ) {
224
			jQuery.cleanData( getAll( node ) );
225
		}
226

    
227
		if ( node.parentNode ) {
228
			if ( keepData && jQuery.contains( node.ownerDocument, node ) ) {
229
				setGlobalEval( getAll( node, "script" ) );
230
			}
231
			node.parentNode.removeChild( node );
232
		}
233
	}
234

    
235
	return elem;
236
}
237

    
238
jQuery.extend( {
239
	htmlPrefilter: function( html ) {
240
		return html.replace( rxhtmlTag, "<$1></$2>" );
241
	},
242

    
243
	clone: function( elem, dataAndEvents, deepDataAndEvents ) {
244
		var i, l, srcElements, destElements,
245
			clone = elem.cloneNode( true ),
246
			inPage = jQuery.contains( elem.ownerDocument, elem );
247

    
248
		// Fix IE cloning issues
249
		if ( !support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) &&
250
				!jQuery.isXMLDoc( elem ) ) {
251

    
252
			// We eschew Sizzle here for performance reasons: https://jsperf.com/getall-vs-sizzle/2
253
			destElements = getAll( clone );
254
			srcElements = getAll( elem );
255

    
256
			for ( i = 0, l = srcElements.length; i < l; i++ ) {
257
				fixInput( srcElements[ i ], destElements[ i ] );
258
			}
259
		}
260

    
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 );
266

    
267
				for ( i = 0, l = srcElements.length; i < l; i++ ) {
268
					cloneCopyEvent( srcElements[ i ], destElements[ i ] );
269
				}
270
			} else {
271
				cloneCopyEvent( elem, clone );
272
			}
273
		}
274

    
275
		// Preserve script evaluation history
276
		destElements = getAll( clone, "script" );
277
		if ( destElements.length > 0 ) {
278
			setGlobalEval( destElements, !inPage && getAll( elem, "script" ) );
279
		}
280

    
281
		// Return the cloned set
282
		return clone;
283
	},
284

    
285
	cleanData: function( elems ) {
286
		var data, elem, type,
287
			special = jQuery.event.special,
288
			i = 0;
289

    
290
		for ( ; ( elem = elems[ i ] ) !== undefined; i++ ) {
291
			if ( acceptData( elem ) ) {
292
				if ( ( data = elem[ dataPriv.expando ] ) ) {
293
					if ( data.events ) {
294
						for ( type in data.events ) {
295
							if ( special[ type ] ) {
296
								jQuery.event.remove( elem, type );
297

    
298
							// This is a shortcut to avoid jQuery.event.remove's overhead
299
							} else {
300
								jQuery.removeEvent( elem, type, data.handle );
301
							}
302
						}
303
					}
304

    
305
					// Support: Chrome <=35 - 45+
306
					// Assign undefined instead of using delete, see Data#remove
307
					elem[ dataPriv.expando ] = undefined;
308
				}
309
				if ( elem[ dataUser.expando ] ) {
310

    
311
					// Support: Chrome <=35 - 45+
312
					// Assign undefined instead of using delete, see Data#remove
313
					elem[ dataUser.expando ] = undefined;
314
				}
315
			}
316
		}
317
	}
318
} );
319

    
320
jQuery.fn.extend( {
321
	detach: function( selector ) {
322
		return remove( this, selector, true );
323
	},
324

    
325
	remove: function( selector ) {
326
		return remove( this, selector );
327
	},
328

    
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;
336
					}
337
				} );
338
		}, null, value, arguments.length );
339
	},
340

    
341
	append: function() {
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 );
346
			}
347
		} );
348
	},
349

    
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 );
355
			}
356
		} );
357
	},
358

    
359
	before: function() {
360
		return domManip( this, arguments, function( elem ) {
361
			if ( this.parentNode ) {
362
				this.parentNode.insertBefore( elem, this );
363
			}
364
		} );
365
	},
366

    
367
	after: function() {
368
		return domManip( this, arguments, function( elem ) {
369
			if ( this.parentNode ) {
370
				this.parentNode.insertBefore( elem, this.nextSibling );
371
			}
372
		} );
373
	},
374

    
375
	empty: function() {
376
		var elem,
377
			i = 0;
378

    
379
		for ( ; ( elem = this[ i ] ) != null; i++ ) {
380
			if ( elem.nodeType === 1 ) {
381

    
382
				// Prevent memory leaks
383
				jQuery.cleanData( getAll( elem, false ) );
384

    
385
				// Remove any remaining nodes
386
				elem.textContent = "";
387
			}
388
		}
389

    
390
		return this;
391
	},
392

    
393
	clone: function( dataAndEvents, deepDataAndEvents ) {
394
		dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
395
		deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
396

    
397
		return this.map( function() {
398
			return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
399
		} );
400
	},
401

    
402
	html: function( value ) {
403
		return access( this, function( value ) {
404
			var elem = this[ 0 ] || {},
405
				i = 0,
406
				l = this.length;
407

    
408
			if ( value === undefined && elem.nodeType === 1 ) {
409
				return elem.innerHTML;
410
			}
411

    
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() ] ) {
415

    
416
				value = jQuery.htmlPrefilter( value );
417

    
418
				try {
419
					for ( ; i < l; i++ ) {
420
						elem = this[ i ] || {};
421

    
422
						// Remove element nodes and prevent memory leaks
423
						if ( elem.nodeType === 1 ) {
424
							jQuery.cleanData( getAll( elem, false ) );
425
							elem.innerHTML = value;
426
						}
427
					}
428

    
429
					elem = 0;
430

    
431
				// If using innerHTML throws an exception, use the fallback method
432
				} catch ( e ) {}
433
			}
434

    
435
			if ( elem ) {
436
				this.empty().append( value );
437
			}
438
		}, null, value, arguments.length );
439
	},
440

    
441
	replaceWith: function() {
442
		var ignored = [];
443

    
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;
447

    
448
			if ( jQuery.inArray( this, ignored ) < 0 ) {
449
				jQuery.cleanData( getAll( this ) );
450
				if ( parent ) {
451
					parent.replaceChild( elem, this );
452
				}
453
			}
454

    
455
		// Force callback invocation
456
		}, ignored );
457
	}
458
} );
459

    
460
jQuery.each( {
461
	appendTo: "append",
462
	prependTo: "prepend",
463
	insertBefore: "before",
464
	insertAfter: "after",
465
	replaceAll: "replaceWith"
466
}, function( name, original ) {
467
	jQuery.fn[ name ] = function( selector ) {
468
		var elems,
469
			ret = [],
470
			insert = jQuery( selector ),
471
			last = insert.length - 1,
472
			i = 0;
473

    
474
		for ( ; i <= last; i++ ) {
475
			elems = i === last ? this : this.clone( true );
476
			jQuery( insert[ i ] )[ original ]( elems );
477

    
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() );
481
		}
482

    
483
		return this.pushStack( ret );
484
	};
485
} );
486

    
487
return jQuery;
488
} );
(14-14/22)