]>
git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/ex-mode/node_modules/space-pen/node_modules/jquery/src/manipulation.js
c6279626420fce794facc0e6f888dc70f43891e4
6 "./manipulation/var/rcheckableType",
7 "./manipulation/support",
8 "./data/var/data_priv",
9 "./data/var/data_user",
16 ], function( jQuery
, concat
, push
, access
, rcheckableType
, support
, data_priv
, data_user
) {
19 rxhtmlTag
= /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,
20 rtagName
= /<([\w:]+)/,
22 rnoInnerhtml
= /<(?:script|style|link)/i,
23 // checked="checked" or checked
24 rchecked
= /checked\s*(?:[^=]|=\s*.checked.)/i,
25 rscriptType
= /^$|\/(?:java|ecma)script/i,
26 rscriptTypeMasked
= /^true\/(.*)/,
27 rcleanScript
= /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,
29 // We have to close these tags to support XHTML (#13200)
33 option: [ 1, "<select multiple='multiple'>", "</select>" ],
35 thead: [ 1, "<table>", "</table>" ],
36 col: [ 2, "<table><colgroup>", "</colgroup></table>" ],
37 tr: [ 2, "<table><tbody>", "</tbody></table>" ],
38 td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
40 _default: [ 0, "", "" ]
44 wrapMap
.optgroup
= wrapMap
.option
;
46 wrapMap
.tbody
= wrapMap
.tfoot
= wrapMap
.colgroup
= wrapMap
.caption
= wrapMap
.thead
;
47 wrapMap
.th
= wrapMap
.td
;
49 // Support: 1.x compatibility
50 // Manipulating tables requires a tbody
51 function manipulationTarget( elem
, content
) {
52 return jQuery
.nodeName( elem
, "table" ) &&
53 jQuery
.nodeName( content
.nodeType
!== 11 ? content : content
.firstChild
, "tr" ) ?
55 elem
.getElementsByTagName("tbody")[0] ||
56 elem
.appendChild( elem
.ownerDocument
.createElement("tbody") ) :
60 // Replace/restore the type attribute of script elements for safe DOM manipulation
61 function disableScript( elem
) {
62 elem
.type
= (elem
.getAttribute("type") !== null) + "/" + elem
.type
;
65 function restoreScript( elem
) {
66 var match
= rscriptTypeMasked
.exec( elem
.type
);
69 elem
.type
= match
[ 1 ];
71 elem
.removeAttribute("type");
77 // Mark scripts as having already been evaluated
78 function setGlobalEval( elems
, refElements
) {
82 for ( ; i
< l
; i
++ ) {
84 elems
[ i
], "globalEval", !refElements
|| data_priv
.get( refElements
[ i
], "globalEval" )
89 function cloneCopyEvent( src
, dest
) {
90 var i
, l
, type
, pdataOld
, pdataCur
, udataOld
, udataCur
, events
;
92 if ( dest
.nodeType
!== 1 ) {
96 // 1. Copy private data: events, handlers, etc.
97 if ( data_priv
.hasData( src
) ) {
98 pdataOld
= data_priv
.access( src
);
99 pdataCur
= data_priv
.set( dest
, pdataOld
);
100 events
= pdataOld
.events
;
103 delete pdataCur
.handle
;
104 pdataCur
.events
= {};
106 for ( type
in events
) {
107 for ( i
= 0, l
= events
[ type
].length
; i
< l
; i
++ ) {
108 jQuery
.event
.add( dest
, type
, events
[ type
][ i
] );
115 if ( data_user
.hasData( src
) ) {
116 udataOld
= data_user
.access( src
);
117 udataCur
= jQuery
.extend( {}, udataOld
);
119 data_user
.set( dest
, udataCur
);
123 function getAll( context
, tag
) {
124 var ret
= context
.getElementsByTagName
? context
.getElementsByTagName( tag
|| "*" ) :
125 context
.querySelectorAll
? context
.querySelectorAll( tag
|| "*" ) :
128 return tag
=== undefined || tag
&& jQuery
.nodeName( context
, tag
) ?
129 jQuery
.merge( [ context
], ret
) :
133 // Fix IE bugs, see support tests
134 function fixInput( src
, dest
) {
135 var nodeName
= dest
.nodeName
.toLowerCase();
137 // Fails to persist the checked state of a cloned checkbox or radio button.
138 if ( nodeName
=== "input" && rcheckableType
.test( src
.type
) ) {
139 dest
.checked
= src
.checked
;
141 // Fails to return the selected option to the default selected state when cloning options
142 } else if ( nodeName
=== "input" || nodeName
=== "textarea" ) {
143 dest
.defaultValue
= src
.defaultValue
;
148 clone: function( elem
, dataAndEvents
, deepDataAndEvents
) {
149 var i
, l
, srcElements
, destElements
,
150 clone
= elem
.cloneNode( true ),
151 inPage
= jQuery
.contains( elem
.ownerDocument
, elem
);
153 // Fix IE cloning issues
154 if ( !support
.noCloneChecked
&& ( elem
.nodeType
=== 1 || elem
.nodeType
=== 11 ) &&
155 !jQuery
.isXMLDoc( elem
) ) {
157 // We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2
158 destElements
= getAll( clone
);
159 srcElements
= getAll( elem
);
161 for ( i
= 0, l
= srcElements
.length
; i
< l
; i
++ ) {
162 fixInput( srcElements
[ i
], destElements
[ i
] );
166 // Copy the events from the original to the clone
167 if ( dataAndEvents
) {
168 if ( deepDataAndEvents
) {
169 srcElements
= srcElements
|| getAll( elem
);
170 destElements
= destElements
|| getAll( clone
);
172 for ( i
= 0, l
= srcElements
.length
; i
< l
; i
++ ) {
173 cloneCopyEvent( srcElements
[ i
], destElements
[ i
] );
176 cloneCopyEvent( elem
, clone
);
180 // Preserve script evaluation history
181 destElements
= getAll( clone
, "script" );
182 if ( destElements
.length
> 0 ) {
183 setGlobalEval( destElements
, !inPage
&& getAll( elem
, "script" ) );
186 // Return the cloned set
190 buildFragment: function( elems
, context
, scripts
, selection
) {
191 var elem
, tmp
, tag
, wrap
, contains
, j
,
192 fragment
= context
.createDocumentFragment(),
197 for ( ; i
< l
; i
++ ) {
200 if ( elem
|| elem
=== 0 ) {
202 // Add nodes directly
203 if ( jQuery
.type( elem
) === "object" ) {
204 // Support: QtWebKit, PhantomJS
205 // push.apply(_, arraylike) throws on ancient WebKit
206 jQuery
.merge( nodes
, elem
.nodeType
? [ elem
] : elem
);
208 // Convert non-html into a text node
209 } else if ( !rhtml
.test( elem
) ) {
210 nodes
.push( context
.createTextNode( elem
) );
212 // Convert html into DOM nodes
214 tmp
= tmp
|| fragment
.appendChild( context
.createElement("div") );
216 // Deserialize a standard representation
217 tag
= ( rtagName
.exec( elem
) || [ "", "" ] )[ 1 ].toLowerCase();
218 wrap
= wrapMap
[ tag
] || wrapMap
._default
;
219 tmp
.innerHTML
= wrap
[ 1 ] + elem
.replace( rxhtmlTag
, "<$1></$2>" ) + wrap
[ 2 ];
221 // Descend through wrappers to the right content
227 // Support: QtWebKit, PhantomJS
228 // push.apply(_, arraylike) throws on ancient WebKit
229 jQuery
.merge( nodes
, tmp
.childNodes
);
231 // Remember the top-level container
232 tmp
= fragment
.firstChild
;
234 // Ensure the created nodes are orphaned (#12392)
235 tmp
.textContent
= "";
240 // Remove wrapper from fragment
241 fragment
.textContent
= "";
244 while ( (elem
= nodes
[ i
++ ]) ) {
246 // #4087 - If origin and destination elements are the same, and this is
247 // that element, do not do anything
248 if ( selection
&& jQuery
.inArray( elem
, selection
) !== -1 ) {
252 contains
= jQuery
.contains( elem
.ownerDocument
, elem
);
254 // Append to fragment
255 tmp
= getAll( fragment
.appendChild( elem
), "script" );
257 // Preserve script evaluation history
259 setGlobalEval( tmp
);
262 // Capture executables
265 while ( (elem
= tmp
[ j
++ ]) ) {
266 if ( rscriptType
.test( elem
.type
|| "" ) ) {
267 scripts
.push( elem
);
276 cleanData: function( elems
) {
277 var data
, elem
, type
, key
,
278 special
= jQuery
.event
.special
,
281 for ( ; (elem
= elems
[ i
]) !== undefined; i
++ ) {
282 if ( jQuery
.acceptData( elem
) ) {
283 key
= elem
[ data_priv
.expando
];
285 if ( key
&& (data
= data_priv
.cache
[ key
]) ) {
287 for ( type
in data
.events
) {
288 if ( special
[ type
] ) {
289 jQuery
.event
.remove( elem
, type
);
291 // This is a shortcut to avoid jQuery.event.remove's overhead
293 jQuery
.removeEvent( elem
, type
, data
.handle
);
297 if ( data_priv
.cache
[ key
] ) {
298 // Discard any remaining `private` data
299 delete data_priv
.cache
[ key
];
303 // Discard any remaining `user` data
304 delete data_user
.cache
[ elem
[ data_user
.expando
] ];
310 text: function( value
) {
311 return access( this, function( value
) {
312 return value
=== undefined ?
313 jQuery
.text( this ) :
314 this.empty().each(function() {
315 if ( this.nodeType
=== 1 || this.nodeType
=== 11 || this.nodeType
=== 9 ) {
316 this.textContent
= value
;
319 }, null, value
, arguments
.length
);
323 return this.domManip( arguments
, function( elem
) {
324 if ( this.nodeType
=== 1 || this.nodeType
=== 11 || this.nodeType
=== 9 ) {
325 var target
= manipulationTarget( this, elem
);
326 target
.appendChild( elem
);
331 prepend: function() {
332 return this.domManip( arguments
, function( elem
) {
333 if ( this.nodeType
=== 1 || this.nodeType
=== 11 || this.nodeType
=== 9 ) {
334 var target
= manipulationTarget( this, elem
);
335 target
.insertBefore( elem
, target
.firstChild
);
341 return this.domManip( arguments
, function( elem
) {
342 if ( this.parentNode
) {
343 this.parentNode
.insertBefore( elem
, this );
349 return this.domManip( arguments
, function( elem
) {
350 if ( this.parentNode
) {
351 this.parentNode
.insertBefore( elem
, this.nextSibling
);
356 remove: function( selector
, keepData
/* Internal Use Only */ ) {
358 elems
= selector
? jQuery
.filter( selector
, this ) : this,
361 for ( ; (elem
= elems
[i
]) != null; i
++ ) {
362 if ( !keepData
&& elem
.nodeType
=== 1 ) {
363 jQuery
.cleanData( getAll( elem
) );
366 if ( elem
.parentNode
) {
367 if ( keepData
&& jQuery
.contains( elem
.ownerDocument
, elem
) ) {
368 setGlobalEval( getAll( elem
, "script" ) );
370 elem
.parentNode
.removeChild( elem
);
381 for ( ; (elem
= this[i
]) != null; i
++ ) {
382 if ( elem
.nodeType
=== 1 ) {
384 // Prevent memory leaks
385 jQuery
.cleanData( getAll( elem
, false ) );
387 // Remove any remaining nodes
388 elem
.textContent
= "";
395 clone: function( dataAndEvents
, deepDataAndEvents
) {
396 dataAndEvents
= dataAndEvents
== null ? false : dataAndEvents
;
397 deepDataAndEvents
= deepDataAndEvents
== null ? dataAndEvents : deepDataAndEvents
;
399 return this.map(function() {
400 return jQuery
.clone( this, dataAndEvents
, deepDataAndEvents
);
404 html: function( value
) {
405 return access( this, function( value
) {
406 var elem
= this[ 0 ] || {},
410 if ( value
=== undefined && elem
.nodeType
=== 1 ) {
411 return elem
.innerHTML
;
414 // See if we can take a shortcut and just use innerHTML
415 if ( typeof value
=== "string" && !rnoInnerhtml
.test( value
) &&
416 !wrapMap
[ ( rtagName
.exec( value
) || [ "", "" ] )[ 1 ].toLowerCase() ] ) {
418 value
= value
.replace( rxhtmlTag
, "<$1></$2>" );
421 for ( ; i
< l
; i
++ ) {
422 elem
= this[ i
] || {};
424 // Remove element nodes and prevent memory leaks
425 if ( elem
.nodeType
=== 1 ) {
426 jQuery
.cleanData( getAll( elem
, false ) );
427 elem
.innerHTML
= value
;
433 // If using innerHTML throws an exception, use the fallback method
438 this.empty().append( value
);
440 }, null, value
, arguments
.length
);
443 replaceWith: function() {
444 var arg
= arguments
[ 0 ];
446 // Make the changes, replacing each context element with the new content
447 this.domManip( arguments
, function( elem
) {
448 arg
= this.parentNode
;
450 jQuery
.cleanData( getAll( this ) );
453 arg
.replaceChild( elem
, this );
457 // Force removal if there was no new content (e.g., from empty arguments)
458 return arg
&& (arg
.length
|| arg
.nodeType
) ? this : this.remove();
461 detach: function( selector
) {
462 return this.remove( selector
, true );
465 domManip: function( args
, callback
) {
467 // Flatten any nested arrays
468 args
= concat
.apply( [], args
);
470 var fragment
, first
, scripts
, hasScripts
, node
, doc
,
476 isFunction
= jQuery
.isFunction( value
);
478 // We can't cloneNode fragments that contain checked, in WebKit
480 ( l
> 1 && typeof value
=== "string" &&
481 !support
.checkClone
&& rchecked
.test( value
) ) ) {
482 return this.each(function( index
) {
483 var self
= set.eq( index
);
485 args
[ 0 ] = value
.call( this, index
, self
.html() );
487 self
.domManip( args
, callback
);
492 fragment
= jQuery
.buildFragment( args
, this[ 0 ].ownerDocument
, false, this );
493 first
= fragment
.firstChild
;
495 if ( fragment
.childNodes
.length
=== 1 ) {
500 scripts
= jQuery
.map( getAll( fragment
, "script" ), disableScript
);
501 hasScripts
= scripts
.length
;
503 // Use the original fragment for the last item instead of the first because it can end up
504 // being emptied incorrectly in certain situations (#8070).
505 for ( ; i
< l
; i
++ ) {
508 if ( i
!== iNoClone
) {
509 node
= jQuery
.clone( node
, true, true );
511 // Keep references to cloned scripts for later restoration
514 // jQuery.merge because push.apply(_, arraylike) throws
515 jQuery
.merge( scripts
, getAll( node
, "script" ) );
519 callback
.call( this[ i
], node
, i
);
523 doc
= scripts
[ scripts
.length
- 1 ].ownerDocument
;
526 jQuery
.map( scripts
, restoreScript
);
528 // Evaluate executable scripts on first document insertion
529 for ( i
= 0; i
< hasScripts
; i
++ ) {
531 if ( rscriptType
.test( node
.type
|| "" ) &&
532 !data_priv
.access( node
, "globalEval" ) && jQuery
.contains( doc
, node
) ) {
535 // Optional AJAX dependency, but won't run scripts if not present
536 if ( jQuery
._evalUrl
) {
537 jQuery
._evalUrl( node
.src
);
540 jQuery
.globalEval( node
.textContent
.replace( rcleanScript
, "" ) );
554 prependTo: "prepend",
555 insertBefore: "before",
556 insertAfter: "after",
557 replaceAll: "replaceWith"
558 }, function( name
, original
) {
559 jQuery
.fn
[ name
] = function( selector
) {
562 insert
= jQuery( selector
),
563 last
= insert
.length
- 1,
566 for ( ; i
<= last
; i
++ ) {
567 elems
= i
=== last
? this : this.clone( true );
568 jQuery( insert
[ i
] )[ original
]( elems
);
571 // .get() because push.apply(_, arraylike) throws
572 push
.apply( ret
, elems
.get() );
575 return this.pushStack( ret
);