Blame view

bower_components/jquery/src/wrap.js 1.46 KB
c5169e0e   Renato De Donato   a new hope
1
  define([
74249687   Luigi Serra   Cross browser con...
2
3
4
5
6
7
  	"./core",
  	"./core/init",
  	"./manipulation", // clone
  	"./traversing" // parent, contents
  ], function( jQuery ) {
  
c5169e0e   Renato De Donato   a new hope
8
  jQuery.fn.extend({
74249687   Luigi Serra   Cross browser con...
9
10
11
12
  	wrapAll: function( html ) {
  		var wrap;
  
  		if ( jQuery.isFunction( html ) ) {
c5169e0e   Renato De Donato   a new hope
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 ] );
  			}
  
c5169e0e   Renato De Donato   a new hope
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;
c5169e0e   Renato De Donato   a new hope
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 ) ) {
c5169e0e   Renato De Donato   a new hope
43
44
45
  			return this.each(function( i ) {
  				jQuery( this ).wrapInner( html.call(this, i) );
  			});
74249687   Luigi Serra   Cross browser con...
46
47
  		}
  
c5169e0e   Renato De Donato   a new hope
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 );
  			}
c5169e0e   Renato De Donato   a new hope
58
  		});
74249687   Luigi Serra   Cross browser con...
59
60
61
62
63
  	},
  
  	wrap: function( html ) {
  		var isFunction = jQuery.isFunction( html );
  
c5169e0e   Renato De Donato   a new hope
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() {
c5169e0e   Renato De Donato   a new hope
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 );
  			}
c5169e0e   Renato De Donato   a new hope
74
  		}).end();
74249687   Luigi Serra   Cross browser con...
75
  	}
c5169e0e   Renato De Donato   a new hope
76
  });
74249687   Luigi Serra   Cross browser con...
77
78
  
  return jQuery;
c5169e0e   Renato De Donato   a new hope
79
  });