0
|
1 //>>excludeStart("exclude", pragmas.exclude);
|
|
2 define([ "shoestring" ], function(){
|
|
3 //>>excludeEnd("exclude");
|
|
4
|
|
5 /**
|
|
6 * Returns a `shoestring` object with the set of *one* siblingx before each element in the original set.
|
|
7 *
|
|
8 * @return shoestring
|
|
9 * @this shoestring
|
|
10 */
|
|
11 shoestring.fn.prev = function(){
|
|
12 //>>includeStart("development", pragmas.development);
|
|
13 if( arguments.length > 0 ){
|
|
14 shoestring.error( 'prev-selector' );
|
|
15 }
|
|
16 //>>includeEnd("development");
|
|
17
|
|
18 var result = [];
|
|
19
|
|
20 // TODO need to implement map
|
|
21 this.each(function() {
|
|
22 var children, item, found;
|
|
23
|
|
24 // get the child nodes for this member of the set
|
|
25 children = shoestring( this.parentNode )[0].childNodes;
|
|
26
|
|
27 for( var i = children.length -1; i >= 0; i-- ){
|
|
28 item = children.item( i );
|
|
29
|
|
30 // found the item we needed (found) which means current item value is
|
|
31 // the next node in the list, as long as it's viable grab it
|
|
32 // NOTE may need to be more permissive
|
|
33 if( found && item.nodeType === 1 ){
|
|
34 result.push( item );
|
|
35 break;
|
|
36 }
|
|
37
|
|
38 // find the current item and mark it as found
|
|
39 if( item === this ){
|
|
40 found = true;
|
|
41 }
|
|
42 }
|
|
43 });
|
|
44
|
|
45 return shoestring( result );
|
|
46 };
|
|
47
|
|
48 //>>excludeStart("exclude", pragmas.exclude);
|
|
49 });
|
|
50 //>>excludeEnd("exclude");
|