Sha256: a506eccc9534098db1f445c63c361475962dfd8185bfe2626f45d89cbafac44c

Contents?: true

Size: 1.25 KB

Versions: 24

Compression:

Stored size: 1.25 KB

Contents

//>>excludeStart("exclude", pragmas.exclude);
define([ "shoestring" ], function(){
//>>excludeEnd("exclude");

	/**
	 * Replace each element in the current set with that argument HTML string or HTMLElement.
	 *
	 * @param {string|HTMLElement} fragment The value to assign.
	 * @return shoestring
	 * @this shoestring
	 */
	shoestring.fn.replaceWith = function( fragment ){
		if( typeof( fragment ) === "string" ){
			fragment = shoestring( fragment );
		}

		var ret = [];

		if( fragment.length > 1 ){
			fragment = fragment.reverse();
		}
		this.each(function( i ){
			var clone = this.cloneNode( true ),
				insertEl;
			ret.push( clone );

			// If there is no parentNode, this is pointless, drop it.
			if( !this.parentNode ){ return; }

			if( fragment.length === 1 ){
				insertEl = i > 0 ? fragment[ 0 ].cloneNode( true ) : fragment[ 0 ];
				this.parentNode.replaceChild( insertEl, this );
			} else {
				for( var j = 0, jl = fragment.length; j < jl; j++ ){
					insertEl = i > 0 ? fragment[ j ].cloneNode( true ) : fragment[ j ];
					this.parentNode.insertBefore( insertEl, this.nextSibling );
				}
				this.parentNode.removeChild( this );
			}
		});

		return shoestring( ret );
	};

//>>excludeStart("exclude", pragmas.exclude);
});
//>>excludeEnd("exclude");

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
trusty-cms-6.3.1 node_modules/shoestring/src/dom/replaceWith.js
trusty-cms-5.0.7 node_modules/shoestring/src/dom/replaceWith.js
trusty-cms-5.0.6 node_modules/shoestring/src/dom/replaceWith.js
trusty-cms-5.0.5 node_modules/shoestring/src/dom/replaceWith.js
trusty-cms-5.0.4 node_modules/shoestring/src/dom/replaceWith.js
trusty-cms-5.0.3 node_modules/shoestring/src/dom/replaceWith.js
trusty-cms-5.0.2 node_modules/shoestring/src/dom/replaceWith.js
trusty-cms-5.0.1 node_modules/shoestring/src/dom/replaceWith.js
trusty-cms-4.3.5 node_modules/shoestring/src/dom/replaceWith.js
trusty-cms-5.0.0 node_modules/shoestring/src/dom/replaceWith.js
trusty-cms-4.3.4 node_modules/shoestring/src/dom/replaceWith.js
trusty-cms-4.3.3 node_modules/shoestring/src/dom/replaceWith.js
trusty-cms-4.3.2 node_modules/shoestring/src/dom/replaceWith.js
trusty-cms-4.3.1 node_modules/shoestring/src/dom/replaceWith.js
trusty-cms-4.3 node_modules/shoestring/src/dom/replaceWith.js
trusty-cms-4.2.3 node_modules/shoestring/src/dom/replaceWith.js
trusty-cms-4.2.2 node_modules/shoestring/src/dom/replaceWith.js
trusty-cms-4.2.1 node_modules/shoestring/src/dom/replaceWith.js
trusty-cms-4.2 node_modules/shoestring/src/dom/replaceWith.js
trusty-cms-4.1.9 node_modules/shoestring/src/dom/replaceWith.js