ffffng/app/bower_components/jquery/src/wrap.js

79 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-05-13 13:25:33 +02:00
define( [
2014-05-12 20:08:19 +02:00
"./core",
2019-03-29 22:00:08 +01:00
"./var/isFunction",
2014-05-12 20:08:19 +02:00
"./core/init",
2016-05-16 13:33:49 +02:00
"./manipulation", // clone
2014-05-12 20:08:19 +02:00
"./traversing" // parent, contents
2019-03-29 22:00:08 +01:00
], function( jQuery, isFunction ) {
2014-05-12 20:08:19 +02:00
2017-05-13 13:25:33 +02:00
"use strict";
jQuery.fn.extend( {
2014-05-12 20:08:19 +02:00
wrapAll: function( html ) {
var wrap;
if ( this[ 0 ] ) {
2019-03-29 22:00:08 +01:00
if ( isFunction( html ) ) {
2017-05-13 13:25:33 +02:00
html = html.call( this[ 0 ] );
}
2014-05-12 20:08:19 +02:00
// The elements to wrap the target around
wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );
if ( this[ 0 ].parentNode ) {
wrap.insertBefore( this[ 0 ] );
}
2017-05-13 13:25:33 +02:00
wrap.map( function() {
2014-05-12 20:08:19 +02:00
var elem = this;
while ( elem.firstElementChild ) {
elem = elem.firstElementChild;
}
return elem;
2017-05-13 13:25:33 +02:00
} ).append( this );
2014-05-12 20:08:19 +02:00
}
return this;
},
wrapInner: function( html ) {
2019-03-29 22:00:08 +01:00
if ( isFunction( html ) ) {
2017-05-13 13:25:33 +02:00
return this.each( function( i ) {
jQuery( this ).wrapInner( html.call( this, i ) );
} );
2014-05-12 20:08:19 +02:00
}
2017-05-13 13:25:33 +02:00
return this.each( function() {
2014-05-12 20:08:19 +02:00
var self = jQuery( this ),
contents = self.contents();
if ( contents.length ) {
contents.wrapAll( html );
} else {
self.append( html );
}
2017-05-13 13:25:33 +02:00
} );
2014-05-12 20:08:19 +02:00
},
wrap: function( html ) {
2019-03-29 22:00:08 +01:00
var htmlIsFunction = isFunction( html );
2014-05-12 20:08:19 +02:00
2017-05-13 13:25:33 +02:00
return this.each( function( i ) {
2019-03-29 22:00:08 +01:00
jQuery( this ).wrapAll( htmlIsFunction ? html.call( this, i ) : html );
2017-05-13 13:25:33 +02:00
} );
2014-05-12 20:08:19 +02:00
},
2017-05-13 13:25:33 +02:00
unwrap: function( selector ) {
this.parent( selector ).not( "body" ).each( function() {
jQuery( this ).replaceWith( this.childNodes );
} );
return this;
2014-05-12 20:08:19 +02:00
}
2017-05-13 13:25:33 +02:00
} );
2014-05-12 20:08:19 +02:00
return jQuery;
2017-05-13 13:25:33 +02:00
} );