Blame view

bower_components/jquery/src/wrap.js 1.48 KB
a1a3bc73   Luigi Serra   graphs updates
1
  define( [
74249687   Luigi Serra   Cross browser con...
2
3
4
5
6
7
  	"./core",
  	"./core/init",
  	"./manipulation", // clone
  	"./traversing" // parent, contents
  ], function( jQuery ) {
  
a1a3bc73   Luigi Serra   graphs updates
8
  jQuery.fn.extend( {
74249687   Luigi Serra   Cross browser con...
9
10
11
12
  	wrapAll: function( html ) {
  		var wrap;
  
  		if ( jQuery.isFunction( html ) ) {
a1a3bc73   Luigi Serra   graphs updates
13
14
15
  			return this.each( function( i ) {
  				jQuery( this ).wrapAll( html.call( this, i ) );
  			} );
74249687   Luigi Serra   Cross browser con...
16
17
18
19
20
21
22
23
24
25
26
  		}
  
  		if ( 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 ] );
  			}
  
a1a3bc73   Luigi Serra   graphs updates
27
  			wrap.map( function() {
74249687   Luigi Serra   Cross browser con...
28
29
30
31
32
33
34
  				var elem = this;
  
  				while ( elem.firstElementChild ) {
  					elem = elem.firstElementChild;
  				}
  
  				return elem;
a1a3bc73   Luigi Serra   graphs updates
35
  			} ).append( this );
74249687   Luigi Serra   Cross browser con...
36
37
38
39
40
41
42
  		}
  
  		return this;
  	},
  
  	wrapInner: function( html ) {
  		if ( jQuery.isFunction( html ) ) {
a1a3bc73   Luigi Serra   graphs updates
43
44
45
  			return this.each( function( i ) {
  				jQuery( this ).wrapInner( html.call( this, i ) );
  			} );
74249687   Luigi Serra   Cross browser con...
46
47
  		}
  
a1a3bc73   Luigi Serra   graphs updates
48
  		return this.each( function() {
74249687   Luigi Serra   Cross browser con...
49
50
51
52
53
54
55
56
57
  			var self = jQuery( this ),
  				contents = self.contents();
  
  			if ( contents.length ) {
  				contents.wrapAll( html );
  
  			} else {
  				self.append( html );
  			}
a1a3bc73   Luigi Serra   graphs updates
58
  		} );
74249687   Luigi Serra   Cross browser con...
59
60
61
62
63
  	},
  
  	wrap: function( html ) {
  		var isFunction = jQuery.isFunction( html );
  
a1a3bc73   Luigi Serra   graphs updates
64
65
66
  		return this.each( function( i ) {
  			jQuery( this ).wrapAll( isFunction ? html.call( this, i ) : html );
  		} );
74249687   Luigi Serra   Cross browser con...
67
68
69
  	},
  
  	unwrap: function() {
a1a3bc73   Luigi Serra   graphs updates
70
  		return this.parent().each( function() {
74249687   Luigi Serra   Cross browser con...
71
72
73
  			if ( !jQuery.nodeName( this, "body" ) ) {
  				jQuery( this ).replaceWith( this.childNodes );
  			}
a1a3bc73   Luigi Serra   graphs updates
74
  		} ).end();
74249687   Luigi Serra   Cross browser con...
75
  	}
a1a3bc73   Luigi Serra   graphs updates
76
  } );
74249687   Luigi Serra   Cross browser con...
77
78
  
  return jQuery;
a1a3bc73   Luigi Serra   graphs updates
79
  } );