commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / bower_components / jquery / src / wrap.js
1 define([
2 "./core",
3 "./core/init",
4 "./manipulation", // clone
5 "./traversing" // parent, contents
6 ], function( jQuery ) {
7
8 jQuery.fn.extend({
9 wrapAll: function( html ) {
10 if ( jQuery.isFunction( html ) ) {
11 return this.each(function(i) {
12 jQuery(this).wrapAll( html.call(this, i) );
13 });
14 }
15
16 if ( this[0] ) {
17 // The elements to wrap the target around
18 var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone(true);
19
20 if ( this[0].parentNode ) {
21 wrap.insertBefore( this[0] );
22 }
23
24 wrap.map(function() {
25 var elem = this;
26
27 while ( elem.firstChild && elem.firstChild.nodeType === 1 ) {
28 elem = elem.firstChild;
29 }
30
31 return elem;
32 }).append( this );
33 }
34
35 return this;
36 },
37
38 wrapInner: function( html ) {
39 if ( jQuery.isFunction( html ) ) {
40 return this.each(function(i) {
41 jQuery(this).wrapInner( html.call(this, i) );
42 });
43 }
44
45 return this.each(function() {
46 var self = jQuery( this ),
47 contents = self.contents();
48
49 if ( contents.length ) {
50 contents.wrapAll( html );
51
52 } else {
53 self.append( html );
54 }
55 });
56 },
57
58 wrap: function( html ) {
59 var isFunction = jQuery.isFunction( html );
60
61 return this.each(function(i) {
62 jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html );
63 });
64 },
65
66 unwrap: function() {
67 return this.parent().each(function() {
68 if ( !jQuery.nodeName( this, "body" ) ) {
69 jQuery( this ).replaceWith( this.childNodes );
70 }
71 }).end();
72 }
73 });
74
75 return jQuery;
76 });