| 1 |
lars |
1 |
/*
|
|
|
2 |
cssQuery, version 2.0.2 (2005-08-19)
|
|
|
3 |
Copyright: 2004-2005, Dean Edwards (http://dean.edwards.name/)
|
|
|
4 |
License: http://creativecommons.org/licenses/LGPL/2.1/
|
|
|
5 |
*/
|
|
|
6 |
|
|
|
7 |
/* Thanks to Bill Edney */
|
|
|
8 |
|
|
|
9 |
cssQuery.addModule("css-level3", function() {
|
|
|
10 |
|
|
|
11 |
// -----------------------------------------------------------------------
|
|
|
12 |
// selectors
|
|
|
13 |
// -----------------------------------------------------------------------
|
|
|
14 |
|
|
|
15 |
// indirect sibling selector
|
|
|
16 |
selectors["~"] = function($results, $from, $tagName, $namespace) {
|
|
|
17 |
var $element, i;
|
|
|
18 |
for (i = 0; ($element = $from[i]); i++) {
|
|
|
19 |
while ($element = nextElementSibling($element)) {
|
|
|
20 |
if (compareTagName($element, $tagName, $namespace))
|
|
|
21 |
$results.push($element);
|
|
|
22 |
}
|
|
|
23 |
}
|
|
|
24 |
};
|
|
|
25 |
|
|
|
26 |
// -----------------------------------------------------------------------
|
|
|
27 |
// pseudo-classes
|
|
|
28 |
// -----------------------------------------------------------------------
|
|
|
29 |
|
|
|
30 |
// I'm hoping these pseudo-classes are pretty readable. Let me know if
|
|
|
31 |
// any need explanation.
|
|
|
32 |
|
|
|
33 |
pseudoClasses["contains"] = function($element, $text) {
|
|
|
34 |
$text = new RegExp(regEscape(getText($text)));
|
|
|
35 |
return $text.test(getTextContent($element));
|
|
|
36 |
};
|
|
|
37 |
|
|
|
38 |
pseudoClasses["root"] = function($element) {
|
|
|
39 |
return $element == getDocument($element).documentElement;
|
|
|
40 |
};
|
|
|
41 |
|
|
|
42 |
pseudoClasses["empty"] = function($element) {
|
|
|
43 |
var $node, i;
|
|
|
44 |
for (i = 0; ($node = $element.childNodes[i]); i++) {
|
|
|
45 |
if (thisElement($node) || $node.nodeType == 3) return false;
|
|
|
46 |
}
|
|
|
47 |
return true;
|
|
|
48 |
};
|
|
|
49 |
|
|
|
50 |
pseudoClasses["last-child"] = function($element) {
|
|
|
51 |
return !nextElementSibling($element);
|
|
|
52 |
};
|
|
|
53 |
|
|
|
54 |
pseudoClasses["only-child"] = function($element) {
|
|
|
55 |
$element = $element.parentNode;
|
|
|
56 |
return firstElementChild($element) == lastElementChild($element);
|
|
|
57 |
};
|
|
|
58 |
|
|
|
59 |
pseudoClasses["not"] = function($element, $selector) {
|
|
|
60 |
var $negated = cssQuery($selector, getDocument($element));
|
|
|
61 |
for (var i = 0; i < $negated.length; i++) {
|
|
|
62 |
if ($negated[i] == $element) return false;
|
|
|
63 |
}
|
|
|
64 |
return true;
|
|
|
65 |
};
|
|
|
66 |
|
|
|
67 |
pseudoClasses["nth-child"] = function($element, $arguments) {
|
|
|
68 |
return nthChild($element, $arguments, previousElementSibling);
|
|
|
69 |
};
|
|
|
70 |
|
|
|
71 |
pseudoClasses["nth-last-child"] = function($element, $arguments) {
|
|
|
72 |
return nthChild($element, $arguments, nextElementSibling);
|
|
|
73 |
};
|
|
|
74 |
|
|
|
75 |
pseudoClasses["target"] = function($element) {
|
|
|
76 |
return $element.id == location.hash.slice(1);
|
|
|
77 |
};
|
|
|
78 |
|
|
|
79 |
// UI element states
|
|
|
80 |
|
|
|
81 |
pseudoClasses["checked"] = function($element) {
|
|
|
82 |
return $element.checked;
|
|
|
83 |
};
|
|
|
84 |
|
|
|
85 |
pseudoClasses["enabled"] = function($element) {
|
|
|
86 |
return $element.disabled === false;
|
|
|
87 |
};
|
|
|
88 |
|
|
|
89 |
pseudoClasses["disabled"] = function($element) {
|
|
|
90 |
return $element.disabled;
|
|
|
91 |
};
|
|
|
92 |
|
|
|
93 |
pseudoClasses["indeterminate"] = function($element) {
|
|
|
94 |
return $element.indeterminate;
|
|
|
95 |
};
|
|
|
96 |
|
|
|
97 |
// -----------------------------------------------------------------------
|
|
|
98 |
// attribute selector tests
|
|
|
99 |
// -----------------------------------------------------------------------
|
|
|
100 |
|
|
|
101 |
AttributeSelector.tests["^="] = function($attribute, $value) {
|
|
|
102 |
return "/^" + regEscape($value) + "/.test(" + $attribute + ")";
|
|
|
103 |
};
|
|
|
104 |
|
|
|
105 |
AttributeSelector.tests["$="] = function($attribute, $value) {
|
|
|
106 |
return "/" + regEscape($value) + "$/.test(" + $attribute + ")";
|
|
|
107 |
};
|
|
|
108 |
|
|
|
109 |
AttributeSelector.tests["*="] = function($attribute, $value) {
|
|
|
110 |
return "/" + regEscape($value) + "/.test(" + $attribute + ")";
|
|
|
111 |
};
|
|
|
112 |
|
|
|
113 |
// -----------------------------------------------------------------------
|
|
|
114 |
// nth child support (Bill Edney)
|
|
|
115 |
// -----------------------------------------------------------------------
|
|
|
116 |
|
|
|
117 |
function nthChild($element, $arguments, $traverse) {
|
|
|
118 |
switch ($arguments) {
|
|
|
119 |
case "n": return true;
|
|
|
120 |
case "even": $arguments = "2n"; break;
|
|
|
121 |
case "odd": $arguments = "2n+1";
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
var $$children = childElements($element.parentNode);
|
|
|
125 |
function _checkIndex($index) {
|
|
|
126 |
var $index = ($traverse == nextElementSibling) ? $$children.length - $index : $index - 1;
|
|
|
127 |
return $$children[$index] == $element;
|
|
|
128 |
};
|
|
|
129 |
|
|
|
130 |
// it was just a number (no "n")
|
|
|
131 |
if (!isNaN($arguments)) return _checkIndex($arguments);
|
|
|
132 |
|
|
|
133 |
$arguments = $arguments.split("n");
|
|
|
134 |
var $multiplier = parseInt($arguments[0]);
|
|
|
135 |
var $step = parseInt($arguments[1]);
|
|
|
136 |
|
|
|
137 |
if ((isNaN($multiplier) || $multiplier == 1) && $step == 0) return true;
|
|
|
138 |
if ($multiplier == 0 && !isNaN($step)) return _checkIndex($step);
|
|
|
139 |
if (isNaN($step)) $step = 0;
|
|
|
140 |
|
|
|
141 |
var $count = 1;
|
|
|
142 |
while ($element = $traverse($element)) $count++;
|
|
|
143 |
|
|
|
144 |
if (isNaN($multiplier) || $multiplier == 1)
|
|
|
145 |
return ($traverse == nextElementSibling) ? ($count <= $step) : ($step >= $count);
|
|
|
146 |
|
|
|
147 |
return ($count % $multiplier) == $step;
|
|
|
148 |
};
|
|
|
149 |
|
|
|
150 |
}); // addModule
|