You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.4 KiB

4 years ago
  1. define( [
  2. "./core",
  3. "./core/init",
  4. "./manipulation", // clone
  5. "./traversing" // parent, contents
  6. ], function( jQuery ) {
  7. "use strict";
  8. jQuery.fn.extend( {
  9. wrapAll: function( html ) {
  10. var wrap;
  11. if ( this[ 0 ] ) {
  12. if ( jQuery.isFunction( html ) ) {
  13. html = html.call( this[ 0 ] );
  14. }
  15. // The elements to wrap the target around
  16. wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );
  17. if ( this[ 0 ].parentNode ) {
  18. wrap.insertBefore( this[ 0 ] );
  19. }
  20. wrap.map( function() {
  21. var elem = this;
  22. while ( elem.firstElementChild ) {
  23. elem = elem.firstElementChild;
  24. }
  25. return elem;
  26. } ).append( this );
  27. }
  28. return this;
  29. },
  30. wrapInner: function( html ) {
  31. if ( jQuery.isFunction( html ) ) {
  32. return this.each( function( i ) {
  33. jQuery( this ).wrapInner( html.call( this, i ) );
  34. } );
  35. }
  36. return this.each( function() {
  37. var self = jQuery( this ),
  38. contents = self.contents();
  39. if ( contents.length ) {
  40. contents.wrapAll( html );
  41. } else {
  42. self.append( html );
  43. }
  44. } );
  45. },
  46. wrap: function( html ) {
  47. var isFunction = jQuery.isFunction( html );
  48. return this.each( function( i ) {
  49. jQuery( this ).wrapAll( isFunction ? html.call( this, i ) : html );
  50. } );
  51. },
  52. unwrap: function( selector ) {
  53. this.parent( selector ).not( "body" ).each( function() {
  54. jQuery( this ).replaceWith( this.childNodes );
  55. } );
  56. return this;
  57. }
  58. } );
  59. return jQuery;
  60. } );