aboutsummaryrefslogtreecommitdiffstats
path: root/lib/jquery/src/wrap.js
diff options
context:
space:
mode:
authorJesús Eduardo <heckyel@hyperbola.info>2017-08-06 20:43:24 -0500
committerJesús Eduardo <heckyel@hyperbola.info>2017-08-06 20:43:24 -0500
commitf7045b862a5b7c3de8ee2ea3da67616b38a667cc (patch)
tree504f420546df4934495bbd6f3d9761650b3783bd /lib/jquery/src/wrap.js
downloadytlibre-f7045b862a5b7c3de8ee2ea3da67616b38a667cc.tar.lz
ytlibre-f7045b862a5b7c3de8ee2ea3da67616b38a667cc.tar.xz
ytlibre-f7045b862a5b7c3de8ee2ea3da67616b38a667cc.zip
first commit
Diffstat (limited to 'lib/jquery/src/wrap.js')
-rw-r--r--lib/jquery/src/wrap.js77
1 files changed, 77 insertions, 0 deletions
diff --git a/lib/jquery/src/wrap.js b/lib/jquery/src/wrap.js
new file mode 100644
index 0000000..88b9bb5
--- /dev/null
+++ b/lib/jquery/src/wrap.js
@@ -0,0 +1,77 @@
+define( [
+ "./core",
+ "./core/init",
+ "./manipulation", // clone
+ "./traversing" // parent, contents
+], function( jQuery ) {
+
+"use strict";
+
+jQuery.fn.extend( {
+ wrapAll: function( html ) {
+ var wrap;
+
+ if ( this[ 0 ] ) {
+ if ( jQuery.isFunction( html ) ) {
+ html = html.call( this[ 0 ] );
+ }
+
+ // 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 ] );
+ }
+
+ wrap.map( function() {
+ var elem = this;
+
+ while ( elem.firstElementChild ) {
+ elem = elem.firstElementChild;
+ }
+
+ 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( selector ) {
+ this.parent( selector ).not( "body" ).each( function() {
+ jQuery( this ).replaceWith( this.childNodes );
+ } );
+ return this;
+ }
+} );
+
+return jQuery;
+} );