comparison default/node_modules/shoestring/src/dom/prepend.js @ 0:1d038bc9b3d2 default tip

Up:default
author Liny <dev@neowd.com>
date Sat, 31 May 2025 09:21:51 +0800
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1d038bc9b3d2
1 //>>excludeStart("exclude", pragmas.exclude);
2 define([ "shoestring" ], function(){
3 //>>excludeEnd("exclude");
4
5 /**
6 * Add an HTML string or element before the children of each element in the current set.
7 *
8 * @param {string|HTMLElement} fragment The HTML string or element to add.
9 * @return shoestring
10 * @this shoestring
11 */
12 shoestring.fn.prepend = function( fragment ){
13 if( typeof( fragment ) === "string" || fragment.nodeType !== undefined ){
14 fragment = shoestring( fragment );
15 }
16
17 return this.each(function( i ){
18
19 for( var j = 0, jl = fragment.length; j < jl; j++ ){
20 var insertEl = i > 0 ? fragment[ j ].cloneNode( true ) : fragment[ j ];
21 if ( this.firstChild ){
22 this.insertBefore( insertEl, this.firstChild );
23 } else {
24 this.appendChild( insertEl );
25 }
26 }
27 });
28 };
29
30 //>>excludeStart("exclude", pragmas.exclude);
31 });
32 //>>excludeEnd("exclude");