2013-08-15 18:15:49 +00:00
|
|
|
define([
|
|
|
|
"./core",
|
|
|
|
"./traversing" // parent, contents
|
|
|
|
], function( jQuery ) {
|
2013-09-09 15:26:21 +00:00
|
|
|
|
2013-04-08 21:40:08 +00:00
|
|
|
jQuery.fn.extend({
|
|
|
|
wrapAll: function( html ) {
|
|
|
|
if ( jQuery.isFunction( html ) ) {
|
|
|
|
return this.each(function(i) {
|
|
|
|
jQuery(this).wrapAll( html.call(this, i) );
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( this[0] ) {
|
|
|
|
// The elements to wrap the target around
|
|
|
|
var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone(true);
|
|
|
|
|
|
|
|
if ( this[0].parentNode ) {
|
|
|
|
wrap.insertBefore( this[0] );
|
|
|
|
}
|
|
|
|
|
|
|
|
wrap.map(function() {
|
|
|
|
var elem = this;
|
|
|
|
|
|
|
|
while ( elem.firstChild && elem.firstChild.nodeType === 1 ) {
|
|
|
|
elem = elem.firstChild;
|
|
|
|
}
|
|
|
|
|
|
|
|
return elem;
|
|
|
|
}).append( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
wrapInner: function( html ) {
|
|
|
|
if ( jQuery.isFunction( html ) ) {
|
|
|
|
return this.each(function(i) {
|
|
|
|
jQuery(this).wrapInner( html.call(this, i) );
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.each(function() {
|
|
|
|
var self = jQuery( this ),
|
|
|
|
contents = self.contents();
|
|
|
|
|
|
|
|
if ( contents.length ) {
|
|
|
|
contents.wrapAll( html );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
self.append( html );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
wrap: function( html ) {
|
|
|
|
var isFunction = jQuery.isFunction( html );
|
|
|
|
|
|
|
|
return this.each(function(i) {
|
|
|
|
jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html );
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
unwrap: function() {
|
|
|
|
return this.parent().each(function() {
|
|
|
|
if ( !jQuery.nodeName( this, "body" ) ) {
|
|
|
|
jQuery( this ).replaceWith( this.childNodes );
|
|
|
|
}
|
|
|
|
}).end();
|
|
|
|
}
|
|
|
|
});
|
2013-09-09 01:25:27 +00:00
|
|
|
|
|
|
|
return jQuery;
|
2013-08-15 18:15:49 +00:00
|
|
|
});
|