// SpryDOMUtils.js - version 0.6 - Spry Pre-Release 1.6 // // Copyright (c) 2007. Adobe Systems Incorporated. // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // * Neither the name of Adobe Systems Incorporated nor the names of its // contributors may be used to endorse or promote products derived from this // software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. var Spry;if(!Spry)Spry={};if(!Spry.Utils)Spry.Utils={};Spry.$=function(element) {if(arguments.length>1) {for(var i=0,elements=[],length=arguments.length;i~\+\[\]]+\(([^\(\)]+|\([^\(\)]*\))*\))|[\.#:]?[^\.#:\s,>~\+\[\]]+)|(\s*[\s,>~\+]\s*)/g;var tkn=new Spry.$$.Token;var sequence=[];sequence.push(tkn);var tokenSequences=[];tokenSequences.push(sequence);s=s.replace(/^\s*|\s*$/,"");var expMatch=tokenExpr.exec(s);while(expMatch) {var tstr=expMatch[0];var c=tstr.charAt(0);switch(c) {case'.':tkn.classes.push(new Spry.$$.Token.Attr("class","\\b"+tstr.substr(1)+"\\b"));break;case'#':tkn.id=tstr.substr(1);break;case':':tkn.pseudos.push(new Spry.$$.Token.PseudoClass(tstr));break;case'[':var attrComps=tstr.match(/\[([^\"'~\^\$\*\|\]=]+)(([~\^\$\*\|]?=)\s*('[^']*'|"[^"]*"|[^"'\]]+))?\s*\]/);var name=attrComps[1];var matchType=attrComps[3];var val=attrComps[4];if(val) {val=val.replace(/^['"]|['"]$/g,"");val=val.replace(Spry.$$.escapeRegExpCharsRE,'\\$&');} var matchStr=undefined;switch(matchType) {case"=":matchStr="^"+val+"$";break;case"^=":matchStr="^"+val;break;case"$=":matchStr=val+"$";break;case"~=":case"|=":matchStr="\\b"+val+"\\b";break;case"*=":matchStr=val;break;} tkn.attrs.push(new Spry.$$.Token.Attr(name,matchStr));break;default:var combiMatch=tstr.match(/^\s*([\s,~>\+])\s*$/);if(combiMatch) {if(combiMatch[1]==',') {sequence=new Array;tokenSequences.push(sequence);tkn=new Spry.$$.Token;sequence.push(tkn);} else {tkn=new Spry.$$.Token;tkn.type=Spry.$$.Token.COMBINATOR;tkn.name=combiMatch[1];sequence.push(tkn);tkn=new Spry.$$.Token();sequence.push(tkn);}} else tkn.name=tstr.toLowerCase();break;} expMatch=tokenExpr.exec(s);} Spry.$$.cache[s]=tokenSequences;return tokenSequences;};Spry.$$.combinatorFuncs={" ":function(nodes,token) {var uid=++Spry.$$.uniqueID;var results=[];var nn=nodes.length;for(var i=0;i":function(nodes,token) {var results=[];var nn=nodes.length;for(var i=0;i0)?1:-1);var invalid=false;if(a>0&&b<0) {b=b%a;b=((b=(b%a))<0)?a+b:b;} else if(a<0) {if(b<0) invalid=true;else a=Math.abs(a);} o=new Object;o.a=a;o.b=b;o.mode=mode;o.invalid=invalid;Spry.$$.nthCache[str]=o;} return o;};Spry.$$.nthChild=function(arg,node,token,fromLastSib,matchNodeName) {if(matchNodeName) {var nodeName=token.getNodeNameIfTypeMatches(node);if(!nodeName)return false;} var o=Spry.$$.parseNthChildString(arg);if(o.invalid) return false;var qidProp="spry$$ncQueryID";var posProp="spry$$ncPos";var countProp="spry$$ncCount";if(matchNodeName) {qidProp+=nodeName;posProp+=nodeName;countProp+=nodeName;} var parent=node.parentNode;if(parent[qidProp]!=Spry.$$.queryID) {var pos=0;parent[qidProp]=Spry.$$.queryID;var c=parent.firstChild;while(c) {if(c.nodeType==1&&(!matchNodeName||nodeName==c.nodeName.toLowerCase())) c[posProp]=++pos;c=c.nextSibling;} parent[countProp]=pos;} pos=node[posProp];if(fromLastSib) pos=parent[countProp]-pos+1;if(o.mode==0) return pos==o.b;if(o.mode>0) return(poso.b)?false:(!((o.b-pos)%o.a));};Spry.$$.processTokens=function(tokens,root) {var numTokens=tokens.length;var nodeSet=[root];var combiFunc=null;for(var i=0;i0;i++) {var t=tokens[i];if(t.type==Spry.$$.Token.SELECTOR) {if(combiFunc) {nodeSet=combiFunc(nodeSet,t);combiFunc=null;} else nodeSet=Spry.$$.getMatchingElements(nodeSet,t);} else combiFunc=Spry.$$.combinatorFuncs[t.name];} return nodeSet;};Spry.$$.getMatchingElements=function(nodes,token) {var results=[];if(token.id) {n=nodes[0];if(n&&n.ownerDocument) {var e=n.ownerDocument.getElementById(token.id);if(e) {if(token.match(e)) results.push(e);} return results;}} var nn=nodes.length;for(var i=0;i