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