scratch – Diff between revs 58 and 125

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