Blame view
app/bower_components/jquery/src/wrap.js
1.42 KB
|
87c93a029
|
1 |
define( [ |
|
f986e111b
|
2 3 4 5 6 |
"./core",
"./core/init",
"./manipulation", // clone
"./traversing" // parent, contents
], function( jQuery ) {
|
|
87c93a029
|
7 8 9 |
"use strict";
jQuery.fn.extend( {
|
|
f986e111b
|
10 |
wrapAll: function( html ) {
|
|
87c93a029
|
11 12 13 14 15 16 |
var wrap;
if ( this[ 0 ] ) {
if ( jQuery.isFunction( html ) ) {
html = html.call( this[ 0 ] );
}
|
|
f986e111b
|
17 |
|
|
f986e111b
|
18 |
// The elements to wrap the target around |
|
87c93a029
|
19 |
wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true ); |
|
f986e111b
|
20 |
|
|
87c93a029
|
21 22 |
if ( this[ 0 ].parentNode ) {
wrap.insertBefore( this[ 0 ] );
|
|
f986e111b
|
23 |
} |
|
87c93a029
|
24 |
wrap.map( function() {
|
|
f986e111b
|
25 |
var elem = this; |
|
87c93a029
|
26 27 |
while ( elem.firstElementChild ) {
elem = elem.firstElementChild;
|
|
f986e111b
|
28 29 30 |
} return elem; |
|
87c93a029
|
31 |
} ).append( this ); |
|
f986e111b
|
32 33 34 35 36 37 38 |
}
return this;
},
wrapInner: function( html ) {
if ( jQuery.isFunction( html ) ) {
|
|
87c93a029
|
39 40 41 |
return this.each( function( i ) {
jQuery( this ).wrapInner( html.call( this, i ) );
} );
|
|
f986e111b
|
42 |
} |
|
87c93a029
|
43 |
return this.each( function() {
|
|
f986e111b
|
44 45 46 47 48 49 50 51 52 |
var self = jQuery( this ),
contents = self.contents();
if ( contents.length ) {
contents.wrapAll( html );
} else {
self.append( html );
}
|
|
87c93a029
|
53 |
} ); |
|
f986e111b
|
54 55 56 57 |
},
wrap: function( html ) {
var isFunction = jQuery.isFunction( html );
|
|
87c93a029
|
58 59 60 |
return this.each( function( i ) {
jQuery( this ).wrapAll( isFunction ? html.call( this, i ) : html );
} );
|
|
f986e111b
|
61 |
}, |
|
87c93a029
|
62 63 64 65 66 |
unwrap: function( selector ) {
this.parent( selector ).not( "body" ).each( function() {
jQuery( this ).replaceWith( this.childNodes );
} );
return this;
|
|
f986e111b
|
67 |
} |
|
87c93a029
|
68 |
} ); |
|
f986e111b
|
69 70 |
return jQuery; |
|
87c93a029
|
71 |
} ); |