UPDATE 4.4.0.0
[phpmyadmin.git] / js / jquery / src / jquery / wrap.js
bloba3c35d9f24be7d48a4edb418b6f2385f291f20ad
1 define([
2         "./core",
3         "./core/init",
4         "./traversing" // parent, contents
5 ], function( jQuery ) {
7 jQuery.fn.extend({
8         wrapAll: function( html ) {
9                 if ( jQuery.isFunction( html ) ) {
10                         return this.each(function(i) {
11                                 jQuery(this).wrapAll( html.call(this, i) );
12                         });
13                 }
15                 if ( this[0] ) {
16                         // The elements to wrap the target around
17                         var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone(true);
19                         if ( this[0].parentNode ) {
20                                 wrap.insertBefore( this[0] );
21                         }
23                         wrap.map(function() {
24                                 var elem = this;
26                                 while ( elem.firstChild && elem.firstChild.nodeType === 1 ) {
27                                         elem = elem.firstChild;
28                                 }
30                                 return elem;
31                         }).append( this );
32                 }
34                 return this;
35         },
37         wrapInner: function( html ) {
38                 if ( jQuery.isFunction( html ) ) {
39                         return this.each(function(i) {
40                                 jQuery(this).wrapInner( html.call(this, i) );
41                         });
42                 }
44                 return this.each(function() {
45                         var self = jQuery( this ),
46                                 contents = self.contents();
48                         if ( contents.length ) {
49                                 contents.wrapAll( html );
51                         } else {
52                                 self.append( html );
53                         }
54                 });
55         },
57         wrap: function( html ) {
58                 var isFunction = jQuery.isFunction( html );
60                 return this.each(function(i) {
61                         jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html );
62                 });
63         },
65         unwrap: function() {
66                 return this.parent().each(function() {
67                         if ( !jQuery.nodeName( this, "body" ) ) {
68                                 jQuery( this ).replaceWith( this.childNodes );
69                         }
70                 }).end();
71         }
72 });
74 return jQuery;
75 });