Mercurial > nebulaweb3
comparison default/node_modules/shoestring/src/dom/index.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 (function() { | |
6 function _getIndex( set, test ) { | |
7 var i, result, element; | |
8 | |
9 for( i = result = 0; i < set.length; i++ ) { | |
10 element = set.item ? set.item(i) : set[i]; | |
11 | |
12 if( test(element) ){ | |
13 return result; | |
14 } | |
15 | |
16 // ignore text nodes, etc | |
17 // NOTE may need to be more permissive | |
18 if( element.nodeType === 1 ){ | |
19 result++; | |
20 } | |
21 } | |
22 | |
23 return -1; | |
24 } | |
25 | |
26 /** | |
27 * Find the index in the current set for the passed selector. | |
28 * Without a selector it returns the index of the first node within the array of its siblings. | |
29 * | |
30 * @param {string|undefined} selector The selector used to search for the index. | |
31 * @return {integer} | |
32 * @this {shoestring} | |
33 */ | |
34 shoestring.fn.index = function( selector ){ | |
35 var self, children; | |
36 | |
37 self = this; | |
38 | |
39 // no arg? check the children, otherwise check each element that matches | |
40 if( selector === undefined ){ | |
41 children = ( ( this[ 0 ] && this[0].parentNode ) || doc.documentElement).childNodes; | |
42 | |
43 // check if the element matches the first of the set | |
44 return _getIndex(children, function( element ) { | |
45 return self[0] === element; | |
46 }); | |
47 } else { | |
48 //>>includeStart("development", pragmas.development); | |
49 if( selector.constructor === shoestring.Shoestring ) { | |
50 shoestring.error( "index-shoestring-object" ); | |
51 } | |
52 //>>includeEnd("development"); | |
53 | |
54 // check if the element matches the first selected node from the parent | |
55 return _getIndex(self, function( element ) { | |
56 return element === (shoestring( selector, element.parentNode )[ 0 ]); | |
57 }); | |
58 } | |
59 }; | |
60 })(); | |
61 | |
62 //>>excludeStart("exclude", pragmas.exclude); | |
63 }); | |
64 //>>excludeEnd("exclude"); |