Project

General

Profile

1
define( [
2
	"./core",
3
	"./core/init",
4
	"./manipulation", // clone
5
	"./traversing" // parent, contents
6
], function( jQuery ) {
7

    
8
"use strict";
9

    
10
jQuery.fn.extend( {
11
	wrapAll: function( html ) {
12
		var wrap;
13

    
14
		if ( this[ 0 ] ) {
15
			if ( jQuery.isFunction( html ) ) {
16
				html = html.call( this[ 0 ] );
17
			}
18

    
19
			// The elements to wrap the target around
20
			wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );
21

    
22
			if ( this[ 0 ].parentNode ) {
23
				wrap.insertBefore( this[ 0 ] );
24
			}
25

    
26
			wrap.map( function() {
27
				var elem = this;
28

    
29
				while ( elem.firstElementChild ) {
30
					elem = elem.firstElementChild;
31
				}
32

    
33
				return elem;
34
			} ).append( this );
35
		}
36

    
37
		return this;
38
	},
39

    
40
	wrapInner: function( html ) {
41
		if ( jQuery.isFunction( html ) ) {
42
			return this.each( function( i ) {
43
				jQuery( this ).wrapInner( html.call( this, i ) );
44
			} );
45
		}
46

    
47
		return this.each( function() {
48
			var self = jQuery( this ),
49
				contents = self.contents();
50

    
51
			if ( contents.length ) {
52
				contents.wrapAll( html );
53

    
54
			} else {
55
				self.append( html );
56
			}
57
		} );
58
	},
59

    
60
	wrap: function( html ) {
61
		var isFunction = jQuery.isFunction( html );
62

    
63
		return this.each( function( i ) {
64
			jQuery( this ).wrapAll( isFunction ? html.call( this, i ) : html );
65
		} );
66
	},
67

    
68
	unwrap: function( selector ) {
69
		this.parent( selector ).not( "body" ).each( function() {
70
			jQuery( this ).replaceWith( this.childNodes );
71
		} );
72
		return this;
73
	}
74
} );
75

    
76
return jQuery;
77
} );
(22-22/22)