|
0
|
1 |
/* |
|
|
2 |
Copyright (c) 2009, Yahoo! Inc. All rights reserved. |
|
|
3 |
Code licensed under the BSD License: |
|
|
4 |
http://developer.yahoo.net/yui/license.txt |
|
|
5 |
version: 3.0.0 |
|
|
6 |
build: 1549 |
|
|
7 |
*/ |
|
|
8 |
YUI.add('dom-base', function(Y) { |
|
|
9 |
|
|
|
10 |
(function(Y) { |
|
|
11 |
/** |
|
|
12 |
* The DOM utility provides a cross-browser abtraction layer |
|
|
13 |
* normalizing DOM tasks, and adds extra helper functionality |
|
|
14 |
* for other common tasks. |
|
|
15 |
* @module dom |
|
|
16 |
* @submodule dom-base |
|
|
17 |
* |
|
|
18 |
*/ |
|
|
19 |
|
|
|
20 |
/** |
|
|
21 |
* Provides DOM helper methods. |
|
|
22 |
* @class DOM |
|
|
23 |
* |
|
|
24 |
*/ |
|
|
25 |
var NODE_TYPE = 'nodeType', |
|
|
26 |
OWNER_DOCUMENT = 'ownerDocument', |
|
|
27 |
DEFAULT_VIEW = 'defaultView', |
|
|
28 |
PARENT_WINDOW = 'parentWindow', |
|
|
29 |
TAG_NAME = 'tagName', |
|
|
30 |
PARENT_NODE = 'parentNode', |
|
|
31 |
FIRST_CHILD = 'firstChild', |
|
|
32 |
PREVIOUS_SIBLING = 'previousSibling', |
|
|
33 |
NEXT_SIBLING = 'nextSibling', |
|
|
34 |
CONTAINS = 'contains', |
|
|
35 |
COMPARE_DOCUMENT_POSITION = 'compareDocumentPosition', |
|
|
36 |
|
|
|
37 |
documentElement = document.documentElement, |
|
|
38 |
|
|
|
39 |
re_tag = /<([a-z]+)/i; |
|
|
40 |
|
|
|
41 |
Y.DOM = { |
|
|
42 |
/** |
|
|
43 |
* Returns the HTMLElement with the given ID (Wrapper for document.getElementById). |
|
|
44 |
* @method byId |
|
|
45 |
* @param {String} id the id attribute |
|
|
46 |
* @param {Object} doc optional The document to search. Defaults to current document |
|
|
47 |
* @return {HTMLElement | null} The HTMLElement with the id, or null if none found. |
|
|
48 |
*/ |
|
|
49 |
byId: function(id, doc) { |
|
|
50 |
doc = doc || Y.config.doc; |
|
|
51 |
// TODO: IE Name |
|
|
52 |
return doc.getElementById(id); |
|
|
53 |
}, |
|
|
54 |
|
|
|
55 |
// @deprecated |
|
|
56 |
children: function(node, tag) { |
|
|
57 |
var ret = []; |
|
|
58 |
if (node) { |
|
|
59 |
tag = tag || '*'; |
|
|
60 |
ret = Y.Selector.query('> ' + tag, node); |
|
|
61 |
} |
|
|
62 |
return ret; |
|
|
63 |
}, |
|
|
64 |
|
|
|
65 |
// @deprecated |
|
|
66 |
firstByTag: function(tag, root) { |
|
|
67 |
var ret; |
|
|
68 |
root = root || Y.config.doc; |
|
|
69 |
|
|
|
70 |
if (tag && root.getElementsByTagName) { |
|
|
71 |
ret = root.getElementsByTagName(tag)[0]; |
|
|
72 |
} |
|
|
73 |
|
|
|
74 |
return ret || null; |
|
|
75 |
}, |
|
|
76 |
|
|
|
77 |
/** |
|
|
78 |
* Returns the text content of the HTMLElement. |
|
|
79 |
* @method getText |
|
|
80 |
* @param {HTMLElement} element The html element. |
|
|
81 |
* @return {String} The text content of the element (includes text of any descending elements). |
|
|
82 |
*/ |
|
|
83 |
getText: (documentElement.textContent !== undefined) ? |
|
|
84 |
function(element) { |
|
|
85 |
var ret = ''; |
|
|
86 |
if (element) { |
|
|
87 |
ret = element.textContent; |
|
|
88 |
} |
|
|
89 |
return ret || ''; |
|
|
90 |
} : function(element) { |
|
|
91 |
var ret = ''; |
|
|
92 |
if (element) { |
|
|
93 |
ret = element.innerText; |
|
|
94 |
} |
|
|
95 |
return ret || ''; |
|
|
96 |
}, |
|
|
97 |
|
|
|
98 |
/** |
|
|
99 |
* Sets the text content of the HTMLElement. |
|
|
100 |
* @method setText |
|
|
101 |
* @param {HTMLElement} element The html element. |
|
|
102 |
* @param {String} content The content to add. |
|
|
103 |
*/ |
|
|
104 |
setText: (documentElement.textContent !== undefined) ? |
|
|
105 |
function(element, content) { |
|
|
106 |
if (element) { |
|
|
107 |
element.textContent = content; |
|
|
108 |
} |
|
|
109 |
} : function(element, content) { |
|
|
110 |
if (element) { |
|
|
111 |
element.innerText = content; |
|
|
112 |
} |
|
|
113 |
}, |
|
|
114 |
|
|
|
115 |
/* |
|
|
116 |
* Finds the previous sibling of the element. |
|
|
117 |
* @method previous |
|
|
118 |
* @deprecated Use elementByAxis |
|
|
119 |
* @param {HTMLElement} element The html element. |
|
|
120 |
* @param {Function} fn optional An optional boolean test to apply. |
|
|
121 |
* The optional function is passed the current DOM node being tested as its only argument. |
|
|
122 |
* If no function is given, the first sibling is returned. |
|
|
123 |
* @param {Boolean} all optional Whether all node types should be scanned, or just element nodes. |
|
|
124 |
* @return {HTMLElement | null} The matching DOM node or null if none found. |
|
|
125 |
*/ |
|
|
126 |
previous: function(element, fn, all) { |
|
|
127 |
return Y.DOM.elementByAxis(element, PREVIOUS_SIBLING, fn, all); |
|
|
128 |
}, |
|
|
129 |
|
|
|
130 |
/* |
|
|
131 |
* Finds the next sibling of the element. |
|
|
132 |
* @method next |
|
|
133 |
* @deprecated Use elementByAxis |
|
|
134 |
* @param {HTMLElement} element The html element. |
|
|
135 |
* @param {Function} fn optional An optional boolean test to apply. |
|
|
136 |
* The optional function is passed the current DOM node being tested as its only argument. |
|
|
137 |
* If no function is given, the first sibling is returned. |
|
|
138 |
* @param {Boolean} all optional Whether all node types should be scanned, or just element nodes. |
|
|
139 |
* @return {HTMLElement | null} The matching DOM node or null if none found. |
|
|
140 |
*/ |
|
|
141 |
next: function(element, fn, all) { |
|
|
142 |
return Y.DOM.elementByAxis(element, NEXT_SIBLING, fn, all); |
|
|
143 |
}, |
|
|
144 |
|
|
|
145 |
/* |
|
|
146 |
* Finds the ancestor of the element. |
|
|
147 |
* @method ancestor |
|
|
148 |
* @deprecated Use elementByAxis |
|
|
149 |
* @param {HTMLElement} element The html element. |
|
|
150 |
* @param {Function} fn optional An optional boolean test to apply. |
|
|
151 |
* The optional function is passed the current DOM node being tested as its only argument. |
|
|
152 |
* If no function is given, the parentNode is returned. |
|
|
153 |
* @param {Boolean} all optional Whether all node types should be scanned, or just element nodes. |
|
|
154 |
* @return {HTMLElement | null} The matching DOM node or null if none found. |
|
|
155 |
*/ |
|
|
156 |
// TODO: optional stopAt node? |
|
|
157 |
ancestor: function(element, fn, all) { |
|
|
158 |
return Y.DOM.elementByAxis(element, PARENT_NODE, fn, all); |
|
|
159 |
}, |
|
|
160 |
|
|
|
161 |
/** |
|
|
162 |
* Searches the element by the given axis for the first matching element. |
|
|
163 |
* @method elementByAxis |
|
|
164 |
* @param {HTMLElement} element The html element. |
|
|
165 |
* @param {String} axis The axis to search (parentNode, nextSibling, previousSibling). |
|
|
166 |
* @param {Function} fn optional An optional boolean test to apply. |
|
|
167 |
* @param {Boolean} all optional Whether all node types should be returned, or just element nodes. |
|
|
168 |
* The optional function is passed the current HTMLElement being tested as its only argument. |
|
|
169 |
* If no function is given, the first element is returned. |
|
|
170 |
* @return {HTMLElement | null} The matching element or null if none found. |
|
|
171 |
*/ |
|
|
172 |
elementByAxis: function(element, axis, fn, all) { |
|
|
173 |
while (element && (element = element[axis])) { // NOTE: assignment |
|
|
174 |
if ( (all || element[TAG_NAME]) && (!fn || fn(element)) ) { |
|
|
175 |
return element; |
|
|
176 |
} |
|
|
177 |
} |
|
|
178 |
return null; |
|
|
179 |
}, |
|
|
180 |
|
|
|
181 |
/** |
|
|
182 |
* Determines whether or not one HTMLElement is or contains another HTMLElement. |
|
|
183 |
* @method contains |
|
|
184 |
* @param {HTMLElement} element The containing html element. |
|
|
185 |
* @param {HTMLElement} needle The html element that may be contained. |
|
|
186 |
* @return {Boolean} Whether or not the element is or contains the needle. |
|
|
187 |
*/ |
|
|
188 |
contains: function(element, needle) { |
|
|
189 |
var ret = false; |
|
|
190 |
|
|
|
191 |
if ( !needle || !element || !needle[NODE_TYPE] || !element[NODE_TYPE]) { |
|
|
192 |
ret = false; |
|
|
193 |
} else if (element[CONTAINS]) { |
|
|
194 |
if (Y.UA.opera || needle[NODE_TYPE] === 1) { // IE & SAF contains fail if needle not an ELEMENT_NODE |
|
|
195 |
ret = element[CONTAINS](needle); |
|
|
196 |
} else { |
|
|
197 |
ret = Y.DOM._bruteContains(element, needle); |
|
|
198 |
} |
|
|
199 |
} else if (element[COMPARE_DOCUMENT_POSITION]) { // gecko |
|
|
200 |
if (element === needle || !!(element[COMPARE_DOCUMENT_POSITION](needle) & 16)) { |
|
|
201 |
ret = true; |
|
|
202 |
} |
|
|
203 |
} |
|
|
204 |
|
|
|
205 |
return ret; |
|
|
206 |
}, |
|
|
207 |
|
|
|
208 |
/** |
|
|
209 |
* Determines whether or not the HTMLElement is part of the document. |
|
|
210 |
* @method inDoc |
|
|
211 |
* @param {HTMLElement} element The containing html element. |
|
|
212 |
* @param {HTMLElement} doc optional The document to check. |
|
|
213 |
* @return {Boolean} Whether or not the element is attached to the document. |
|
|
214 |
*/ |
|
|
215 |
inDoc: function(element, doc) { |
|
|
216 |
doc = doc || element[OWNER_DOCUMENT]; |
|
|
217 |
var id = element.id; |
|
|
218 |
if (!id) { // TODO: remove when done? |
|
|
219 |
id = element.id = Y.guid(); |
|
|
220 |
} |
|
|
221 |
|
|
|
222 |
return !! (doc.getElementById(id)); |
|
|
223 |
}, |
|
|
224 |
|
|
|
225 |
/** |
|
|
226 |
* Creates a new dom node using the provided markup string. |
|
|
227 |
* @method create |
|
|
228 |
* @param {String} html The markup used to create the element |
|
|
229 |
* @param {HTMLDocument} doc An optional document context |
|
|
230 |
*/ |
|
|
231 |
create: function(html, doc) { |
|
|
232 |
if (typeof html === 'string') { |
|
|
233 |
html = Y.Lang.trim(html); // match IE which trims whitespace from innerHTML |
|
|
234 |
} |
|
|
235 |
|
|
|
236 |
if (!doc && Y.DOM._cloneCache[html]) { |
|
|
237 |
return Y.DOM._cloneCache[html].cloneNode(true); // NOTE: return |
|
|
238 |
} |
|
|
239 |
|
|
|
240 |
doc = doc || Y.config.doc; |
|
|
241 |
var m = re_tag.exec(html), |
|
|
242 |
create = Y.DOM._create, |
|
|
243 |
custom = Y.DOM.creators, |
|
|
244 |
ret = null, |
|
|
245 |
tag, nodes; |
|
|
246 |
|
|
|
247 |
if (m && custom[m[1]]) { |
|
|
248 |
if (typeof custom[m[1]] === 'function') { |
|
|
249 |
create = custom[m[1]]; |
|
|
250 |
} else { |
|
|
251 |
tag = custom[m[1]]; |
|
|
252 |
} |
|
|
253 |
} |
|
|
254 |
|
|
|
255 |
nodes = create(html, doc, tag).childNodes; |
|
|
256 |
|
|
|
257 |
if (nodes.length === 1) { // return single node, breaking parentNode ref from "fragment" |
|
|
258 |
ret = nodes[0].parentNode.removeChild(nodes[0]); |
|
|
259 |
} else { // return multiple nodes as a fragment |
|
|
260 |
ret = Y.DOM._nl2frag(nodes, doc); |
|
|
261 |
} |
|
|
262 |
|
|
|
263 |
if (ret) { |
|
|
264 |
Y.DOM._cloneCache[html] = ret.cloneNode(true); |
|
|
265 |
} |
|
|
266 |
return ret; |
|
|
267 |
}, |
|
|
268 |
|
|
|
269 |
_nl2frag: function(nodes, doc) { |
|
|
270 |
var ret = null, |
|
|
271 |
i, len; |
|
|
272 |
|
|
|
273 |
if (nodes && (nodes.push || nodes.item) && nodes[0]) { |
|
|
274 |
doc = doc || nodes[0].ownerDocument; |
|
|
275 |
ret = doc.createDocumentFragment(); |
|
|
276 |
|
|
|
277 |
if (nodes.item) { // convert live list to static array |
|
|
278 |
nodes = Y.Array(nodes, 0, true); |
|
|
279 |
} |
|
|
280 |
|
|
|
281 |
for (i = 0, len = nodes.length; i < len; i++) { |
|
|
282 |
ret.appendChild(nodes[i]); |
|
|
283 |
} |
|
|
284 |
} // else inline with log for minification |
|
|
285 |
else { Y.log('unable to convert ' + nodes + ' to fragment', 'warn', 'dom'); } |
|
|
286 |
return ret; |
|
|
287 |
}, |
|
|
288 |
|
|
|
289 |
|
|
|
290 |
CUSTOM_ATTRIBUTES: (!documentElement.hasAttribute) ? { // IE < 8 |
|
|
291 |
'for': 'htmlFor', |
|
|
292 |
'class': 'className' |
|
|
293 |
} : { // w3c |
|
|
294 |
'htmlFor': 'for', |
|
|
295 |
'className': 'class' |
|
|
296 |
}, |
|
|
297 |
|
|
|
298 |
/** |
|
|
299 |
* Provides a normalized attribute interface. |
|
|
300 |
* @method setAttibute |
|
|
301 |
* @param {String | HTMLElement} el The target element for the attribute. |
|
|
302 |
* @param {String} attr The attribute to set. |
|
|
303 |
* @param {String} val The value of the attribute. |
|
|
304 |
*/ |
|
|
305 |
setAttribute: function(el, attr, val, ieAttr) { |
|
|
306 |
if (el && el.setAttribute) { |
|
|
307 |
attr = Y.DOM.CUSTOM_ATTRIBUTES[attr] || attr; |
|
|
308 |
el.setAttribute(attr, val, ieAttr); |
|
|
309 |
} |
|
|
310 |
}, |
|
|
311 |
|
|
|
312 |
|
|
|
313 |
/** |
|
|
314 |
* Provides a normalized attribute interface. |
|
|
315 |
* @method getAttibute |
|
|
316 |
* @param {String | HTMLElement} el The target element for the attribute. |
|
|
317 |
* @param {String} attr The attribute to get. |
|
|
318 |
* @return {String} The current value of the attribute. |
|
|
319 |
*/ |
|
|
320 |
getAttribute: function(el, attr, ieAttr) { |
|
|
321 |
ieAttr = (ieAttr !== undefined) ? ieAttr : 2; |
|
|
322 |
var ret = ''; |
|
|
323 |
if (el && el.getAttribute) { |
|
|
324 |
attr = Y.DOM.CUSTOM_ATTRIBUTES[attr] || attr; |
|
|
325 |
ret = el.getAttribute(attr, ieAttr); |
|
|
326 |
|
|
|
327 |
if (ret === null) { |
|
|
328 |
ret = ''; // per DOM spec |
|
|
329 |
} |
|
|
330 |
} |
|
|
331 |
return ret; |
|
|
332 |
}, |
|
|
333 |
|
|
|
334 |
isWindow: function(obj) { |
|
|
335 |
return obj.alert && obj.document; |
|
|
336 |
}, |
|
|
337 |
|
|
|
338 |
_fragClones: { |
|
|
339 |
div: document.createElement('div') |
|
|
340 |
}, |
|
|
341 |
|
|
|
342 |
_create: function(html, doc, tag) { |
|
|
343 |
tag = tag || 'div'; |
|
|
344 |
|
|
|
345 |
var frag = Y.DOM._fragClones[tag]; |
|
|
346 |
if (frag) { |
|
|
347 |
frag = frag.cloneNode(false); |
|
|
348 |
} else { |
|
|
349 |
frag = Y.DOM._fragClones[tag] = doc.createElement(tag); |
|
|
350 |
} |
|
|
351 |
frag.innerHTML = html; |
|
|
352 |
return frag; |
|
|
353 |
}, |
|
|
354 |
|
|
|
355 |
_removeChildNodes: function(node) { |
|
|
356 |
while (node.firstChild) { |
|
|
357 |
node.removeChild(node.firstChild); |
|
|
358 |
} |
|
|
359 |
}, |
|
|
360 |
|
|
|
361 |
_cloneCache: {}, |
|
|
362 |
|
|
|
363 |
/** |
|
|
364 |
* Inserts content in a node at the given location |
|
|
365 |
* @method addHTML |
|
|
366 |
* @param {HTMLElement} node The node to insert into |
|
|
367 |
* @param {String} content The content to be inserted |
|
|
368 |
* @param {String} where Where to insert the content; default is after lastChild |
|
|
369 |
*/ |
|
|
370 |
addHTML: function(node, content, where) { |
|
|
371 |
if (typeof content === 'string') { |
|
|
372 |
content = Y.Lang.trim(content); // match IE which trims whitespace from innerHTML |
|
|
373 |
} |
|
|
374 |
|
|
|
375 |
var newNode = Y.DOM._cloneCache[content], |
|
|
376 |
nodeParent = node.parentNode; |
|
|
377 |
|
|
|
378 |
if (newNode) { |
|
|
379 |
newNode = newNode.cloneNode(true); |
|
|
380 |
} else { |
|
|
381 |
if (content.nodeType) { // domNode |
|
|
382 |
newNode = content; |
|
|
383 |
} else { // create from string and cache |
|
|
384 |
newNode = Y.DOM.create(content); |
|
|
385 |
} |
|
|
386 |
} |
|
|
387 |
|
|
|
388 |
if (where) { |
|
|
389 |
if (where.nodeType) { // insert regardless of relationship to node |
|
|
390 |
// TODO: check if node.contains(where)? |
|
|
391 |
where.parentNode.insertBefore(newNode, where); |
|
|
392 |
} else { |
|
|
393 |
switch (where) { |
|
|
394 |
case 'replace': |
|
|
395 |
while (node.firstChild) { |
|
|
396 |
node.removeChild(node.firstChild); |
|
|
397 |
} |
|
|
398 |
node.appendChild(newNode); |
|
|
399 |
break; |
|
|
400 |
case 'before': |
|
|
401 |
nodeParent.insertBefore(newNode, node); |
|
|
402 |
break; |
|
|
403 |
case 'after': |
|
|
404 |
if (node.nextSibling) { // IE errors if refNode is null |
|
|
405 |
nodeParent.insertBefore(newNode, node.nextSibling); |
|
|
406 |
} else { |
|
|
407 |
nodeParent.appendChild(newNode); |
|
|
408 |
} |
|
|
409 |
break; |
|
|
410 |
default: |
|
|
411 |
node.appendChild(newNode); |
|
|
412 |
} |
|
|
413 |
} |
|
|
414 |
} else { |
|
|
415 |
node.appendChild(newNode); |
|
|
416 |
} |
|
|
417 |
|
|
|
418 |
return newNode; |
|
|
419 |
}, |
|
|
420 |
|
|
|
421 |
VALUE_SETTERS: {}, |
|
|
422 |
|
|
|
423 |
VALUE_GETTERS: {}, |
|
|
424 |
|
|
|
425 |
getValue: function(node) { |
|
|
426 |
var ret = '', // TODO: return null? |
|
|
427 |
getter; |
|
|
428 |
|
|
|
429 |
if (node && node[TAG_NAME]) { |
|
|
430 |
getter = Y.DOM.VALUE_GETTERS[node[TAG_NAME].toLowerCase()]; |
|
|
431 |
|
|
|
432 |
if (getter) { |
|
|
433 |
ret = getter(node); |
|
|
434 |
} else { |
|
|
435 |
ret = node.value; |
|
|
436 |
} |
|
|
437 |
} |
|
|
438 |
|
|
|
439 |
return (typeof ret === 'string') ? ret : ''; |
|
|
440 |
}, |
|
|
441 |
|
|
|
442 |
setValue: function(node, val) { |
|
|
443 |
var setter; |
|
|
444 |
|
|
|
445 |
if (node && node[TAG_NAME]) { |
|
|
446 |
setter = Y.DOM.VALUE_SETTERS[node[TAG_NAME].toLowerCase()]; |
|
|
447 |
|
|
|
448 |
if (setter) { |
|
|
449 |
setter(node, val); |
|
|
450 |
} else { |
|
|
451 |
node.value = val; |
|
|
452 |
} |
|
|
453 |
} |
|
|
454 |
}, |
|
|
455 |
|
|
|
456 |
/** |
|
|
457 |
* Brute force version of contains. |
|
|
458 |
* Used for browsers without contains support for non-HTMLElement Nodes (textNodes, etc). |
|
|
459 |
* @method _bruteContains |
|
|
460 |
* @private |
|
|
461 |
* @param {HTMLElement} element The containing html element. |
|
|
462 |
* @param {HTMLElement} needle The html element that may be contained. |
|
|
463 |
* @return {Boolean} Whether or not the element is or contains the needle. |
|
|
464 |
*/ |
|
|
465 |
_bruteContains: function(element, needle) { |
|
|
466 |
while (needle) { |
|
|
467 |
if (element === needle) { |
|
|
468 |
return true; |
|
|
469 |
} |
|
|
470 |
needle = needle.parentNode; |
|
|
471 |
} |
|
|
472 |
return false; |
|
|
473 |
}, |
|
|
474 |
|
|
|
475 |
// TODO: move to Lang? |
|
|
476 |
/** |
|
|
477 |
* Memoizes dynamic regular expressions to boost runtime performance. |
|
|
478 |
* @method _getRegExp |
|
|
479 |
* @private |
|
|
480 |
* @param {String} str The string to convert to a regular expression. |
|
|
481 |
* @param {String} flags optional An optinal string of flags. |
|
|
482 |
* @return {RegExp} An instance of RegExp |
|
|
483 |
*/ |
|
|
484 |
_getRegExp: function(str, flags) { |
|
|
485 |
flags = flags || ''; |
|
|
486 |
Y.DOM._regexCache = Y.DOM._regexCache || {}; |
|
|
487 |
if (!Y.DOM._regexCache[str + flags]) { |
|
|
488 |
Y.DOM._regexCache[str + flags] = new RegExp(str, flags); |
|
|
489 |
} |
|
|
490 |
return Y.DOM._regexCache[str + flags]; |
|
|
491 |
}, |
|
|
492 |
|
|
|
493 |
// TODO: make getDoc/Win true privates? |
|
|
494 |
/** |
|
|
495 |
* returns the appropriate document. |
|
|
496 |
* @method _getDoc |
|
|
497 |
* @private |
|
|
498 |
* @param {HTMLElement} element optional Target element. |
|
|
499 |
* @return {Object} The document for the given element or the default document. |
|
|
500 |
*/ |
|
|
501 |
_getDoc: function(element) { |
|
|
502 |
element = element || {}; |
|
|
503 |
|
|
|
504 |
return (element[NODE_TYPE] === 9) ? element : // element === document |
|
|
505 |
element[OWNER_DOCUMENT] || // element === DOM node |
|
|
506 |
element.document || // element === window |
|
|
507 |
Y.config.doc; // default |
|
|
508 |
}, |
|
|
509 |
|
|
|
510 |
/** |
|
|
511 |
* returns the appropriate window. |
|
|
512 |
* @method _getWin |
|
|
513 |
* @private |
|
|
514 |
* @param {HTMLElement} element optional Target element. |
|
|
515 |
* @return {Object} The window for the given element or the default window. |
|
|
516 |
*/ |
|
|
517 |
_getWin: function(element) { |
|
|
518 |
var doc = Y.DOM._getDoc(element); |
|
|
519 |
return doc[DEFAULT_VIEW] || doc[PARENT_WINDOW] || Y.config.win; |
|
|
520 |
}, |
|
|
521 |
|
|
|
522 |
_batch: function(nodes, fn, arg1, arg2, arg3, etc) { |
|
|
523 |
fn = (typeof name === 'string') ? Y.DOM[fn] : fn; |
|
|
524 |
var result, |
|
|
525 |
ret = []; |
|
|
526 |
|
|
|
527 |
if (fn && nodes) { |
|
|
528 |
Y.each(nodes, function(node) { |
|
|
529 |
if ((result = fn.call(Y.DOM, node, arg1, arg2, arg3, etc)) !== undefined) { |
|
|
530 |
ret[ret.length] = result; |
|
|
531 |
} |
|
|
532 |
}); |
|
|
533 |
} |
|
|
534 |
|
|
|
535 |
return ret.length ? ret : nodes; |
|
|
536 |
}, |
|
|
537 |
|
|
|
538 |
_testElement: function(element, tag, fn) { |
|
|
539 |
tag = (tag && tag !== '*') ? tag.toUpperCase() : null; |
|
|
540 |
return (element && element[TAG_NAME] && |
|
|
541 |
(!tag || element[TAG_NAME].toUpperCase() === tag) && |
|
|
542 |
(!fn || fn(element))); |
|
|
543 |
}, |
|
|
544 |
|
|
|
545 |
creators: {}, |
|
|
546 |
|
|
|
547 |
_IESimpleCreate: function(html, doc) { |
|
|
548 |
doc = doc || Y.config.doc; |
|
|
549 |
return doc.createElement(html); |
|
|
550 |
} |
|
|
551 |
}; |
|
|
552 |
|
|
|
553 |
|
|
|
554 |
(function(Y) { |
|
|
555 |
var creators = Y.DOM.creators, |
|
|
556 |
create = Y.DOM.create, |
|
|
557 |
re_tbody = /(?:\/(?:thead|tfoot|tbody|caption|col|colgroup)>)+\s*<tbody/, |
|
|
558 |
|
|
|
559 |
TABLE_OPEN = '<table>', |
|
|
560 |
TABLE_CLOSE = '</table>'; |
|
|
561 |
|
|
|
562 |
if (Y.UA.ie) { |
|
|
563 |
Y.mix(creators, { |
|
|
564 |
// TODO: thead/tfoot with nested tbody |
|
|
565 |
// IE adds TBODY when creating TABLE elements (which may share this impl) |
|
|
566 |
tbody: function(html, doc) { |
|
|
567 |
var frag = create(TABLE_OPEN + html + TABLE_CLOSE, doc), |
|
|
568 |
tb = frag.children.tags('tbody')[0]; |
|
|
569 |
|
|
|
570 |
if (frag.children.length > 1 && tb && !re_tbody.test(html)) { |
|
|
571 |
tb[PARENT_NODE].removeChild(tb); // strip extraneous tbody |
|
|
572 |
} |
|
|
573 |
return frag; |
|
|
574 |
}, |
|
|
575 |
|
|
|
576 |
script: function(html, doc) { |
|
|
577 |
var frag = doc.createElement('div'); |
|
|
578 |
|
|
|
579 |
frag.innerHTML = '-' + html; |
|
|
580 |
frag.removeChild(frag[FIRST_CHILD]); |
|
|
581 |
return frag; |
|
|
582 |
} |
|
|
583 |
|
|
|
584 |
}, true); |
|
|
585 |
|
|
|
586 |
Y.mix(Y.DOM.VALUE_GETTERS, { |
|
|
587 |
button: function(node) { |
|
|
588 |
return (node.attributes && node.attributes.value) ? node.attributes.value.value : ''; |
|
|
589 |
} |
|
|
590 |
}); |
|
|
591 |
|
|
|
592 |
Y.mix(Y.DOM.VALUE_SETTERS, { |
|
|
593 |
// IE: node.value changes the button text, which should be handled via innerHTML |
|
|
594 |
button: function(node, val) { |
|
|
595 |
var attr = node.attributes.value; |
|
|
596 |
if (!attr) { |
|
|
597 |
attr = node[OWNER_DOCUMENT].createAttribute('value'); |
|
|
598 |
node.setAttributeNode(attr); |
|
|
599 |
} |
|
|
600 |
|
|
|
601 |
attr.value = val; |
|
|
602 |
} |
|
|
603 |
}); |
|
|
604 |
} |
|
|
605 |
|
|
|
606 |
if (Y.UA.gecko || Y.UA.ie) { |
|
|
607 |
Y.mix(creators, { |
|
|
608 |
option: function(html, doc) { |
|
|
609 |
return create('<select>' + html + '</select>', doc); |
|
|
610 |
}, |
|
|
611 |
|
|
|
612 |
tr: function(html, doc) { |
|
|
613 |
return create('<tbody>' + html + '</tbody>', doc); |
|
|
614 |
}, |
|
|
615 |
|
|
|
616 |
td: function(html, doc) { |
|
|
617 |
return create('<tr>' + html + '</tr>', doc); |
|
|
618 |
}, |
|
|
619 |
|
|
|
620 |
tbody: function(html, doc) { |
|
|
621 |
return create(TABLE_OPEN + html + TABLE_CLOSE, doc); |
|
|
622 |
} |
|
|
623 |
}); |
|
|
624 |
|
|
|
625 |
Y.mix(creators, { |
|
|
626 |
legend: 'fieldset', |
|
|
627 |
th: creators.td, |
|
|
628 |
thead: creators.tbody, |
|
|
629 |
tfoot: creators.tbody, |
|
|
630 |
caption: creators.tbody, |
|
|
631 |
colgroup: creators.tbody, |
|
|
632 |
col: creators.tbody, |
|
|
633 |
optgroup: creators.option |
|
|
634 |
}); |
|
|
635 |
} |
|
|
636 |
|
|
|
637 |
Y.mix(Y.DOM.VALUE_GETTERS, { |
|
|
638 |
option: function(node) { |
|
|
639 |
var attrs = node.attributes; |
|
|
640 |
return (attrs.value && attrs.value.specified) ? node.value : node.text; |
|
|
641 |
}, |
|
|
642 |
|
|
|
643 |
select: function(node) { |
|
|
644 |
var val = node.value, |
|
|
645 |
options = node.options; |
|
|
646 |
|
|
|
647 |
if (options && val === '') { |
|
|
648 |
if (node.multiple) { |
|
|
649 |
Y.log('multiple select normalization not implemented', 'warn', 'DOM'); |
|
|
650 |
} else { |
|
|
651 |
val = Y.DOM.getValue(options[node.selectedIndex], 'value'); |
|
|
652 |
} |
|
|
653 |
} |
|
|
654 |
|
|
|
655 |
return val; |
|
|
656 |
} |
|
|
657 |
}); |
|
|
658 |
})(Y); |
|
|
659 |
|
|
|
660 |
})(Y); |
|
|
661 |
var addClass, hasClass, removeClass; |
|
|
662 |
|
|
|
663 |
Y.mix(Y.DOM, { |
|
|
664 |
/** |
|
|
665 |
* Determines whether a DOM element has the given className. |
|
|
666 |
* @method hasClass |
|
|
667 |
* @param {HTMLElement} element The DOM element. |
|
|
668 |
* @param {String} className the class name to search for |
|
|
669 |
* @return {Boolean} Whether or not the element has the given class. |
|
|
670 |
*/ |
|
|
671 |
hasClass: function(node, className) { |
|
|
672 |
var re = Y.DOM._getRegExp('(?:^|\\s+)' + className + '(?:\\s+|$)'); |
|
|
673 |
return re.test(node.className); |
|
|
674 |
}, |
|
|
675 |
|
|
|
676 |
/** |
|
|
677 |
* Adds a class name to a given DOM element. |
|
|
678 |
* @method addClass |
|
|
679 |
* @param {HTMLElement} element The DOM element. |
|
|
680 |
* @param {String} className the class name to add to the class attribute |
|
|
681 |
*/ |
|
|
682 |
addClass: function(node, className) { |
|
|
683 |
if (!Y.DOM.hasClass(node, className)) { // skip if already present |
|
|
684 |
node.className = Y.Lang.trim([node.className, className].join(' ')); |
|
|
685 |
} |
|
|
686 |
}, |
|
|
687 |
|
|
|
688 |
/** |
|
|
689 |
* Removes a class name from a given element. |
|
|
690 |
* @method removeClass |
|
|
691 |
* @param {HTMLElement} element The DOM element. |
|
|
692 |
* @param {String} className the class name to remove from the class attribute |
|
|
693 |
*/ |
|
|
694 |
removeClass: function(node, className) { |
|
|
695 |
if (className && hasClass(node, className)) { |
|
|
696 |
node.className = Y.Lang.trim(node.className.replace(Y.DOM._getRegExp('(?:^|\\s+)' + |
|
|
697 |
className + '(?:\\s+|$)'), ' ')); |
|
|
698 |
|
|
|
699 |
if ( hasClass(node, className) ) { // in case of multiple adjacent |
|
|
700 |
removeClass(node, className); |
|
|
701 |
} |
|
|
702 |
} |
|
|
703 |
}, |
|
|
704 |
|
|
|
705 |
/** |
|
|
706 |
* Replace a class with another class for a given element. |
|
|
707 |
* If no oldClassName is present, the newClassName is simply added. |
|
|
708 |
* @method replaceClass |
|
|
709 |
* @param {HTMLElement} element The DOM element. |
|
|
710 |
* @param {String} oldClassName the class name to be replaced |
|
|
711 |
* @param {String} newClassName the class name that will be replacing the old class name |
|
|
712 |
*/ |
|
|
713 |
replaceClass: function(node, oldC, newC) { |
|
|
714 |
//Y.log('replaceClass replacing ' + oldC + ' with ' + newC, 'info', 'Node'); |
|
|
715 |
addClass(node, newC); |
|
|
716 |
removeClass(node, oldC); |
|
|
717 |
}, |
|
|
718 |
|
|
|
719 |
/** |
|
|
720 |
* If the className exists on the node it is removed, if it doesn't exist it is added. |
|
|
721 |
* @method toggleClass |
|
|
722 |
* @param {HTMLElement} element The DOM element. |
|
|
723 |
* @param {String} className the class name to be toggled |
|
|
724 |
*/ |
|
|
725 |
toggleClass: function(node, className) { |
|
|
726 |
if (hasClass(node, className)) { |
|
|
727 |
removeClass(node, className); |
|
|
728 |
} else { |
|
|
729 |
addClass(node, className); |
|
|
730 |
} |
|
|
731 |
} |
|
|
732 |
}); |
|
|
733 |
|
|
|
734 |
hasClass = Y.DOM.hasClass; |
|
|
735 |
removeClass = Y.DOM.removeClass; |
|
|
736 |
addClass = Y.DOM.addClass; |
|
|
737 |
|
|
|
738 |
|
|
|
739 |
|
|
|
740 |
}, '3.0.0' ,{requires:['oop']}); |
|
|
741 |
YUI.add('dom-style', function(Y) { |
|
|
742 |
|
|
|
743 |
(function(Y) { |
|
|
744 |
/** |
|
|
745 |
* Add style management functionality to DOM. |
|
|
746 |
* @module dom |
|
|
747 |
* @submodule dom-style |
|
|
748 |
* @for DOM |
|
|
749 |
*/ |
|
|
750 |
|
|
|
751 |
var DOCUMENT_ELEMENT = 'documentElement', |
|
|
752 |
DEFAULT_VIEW = 'defaultView', |
|
|
753 |
OWNER_DOCUMENT = 'ownerDocument', |
|
|
754 |
STYLE = 'style', |
|
|
755 |
FLOAT = 'float', |
|
|
756 |
CSS_FLOAT = 'cssFloat', |
|
|
757 |
STYLE_FLOAT = 'styleFloat', |
|
|
758 |
TRANSPARENT = 'transparent', |
|
|
759 |
GET_COMPUTED_STYLE = 'getComputedStyle', |
|
|
760 |
|
|
|
761 |
DOCUMENT = Y.config.doc, |
|
|
762 |
UNDEFINED = undefined, |
|
|
763 |
|
|
|
764 |
re_color = /color$/i; |
|
|
765 |
|
|
|
766 |
|
|
|
767 |
Y.mix(Y.DOM, { |
|
|
768 |
CUSTOM_STYLES: { |
|
|
769 |
}, |
|
|
770 |
|
|
|
771 |
|
|
|
772 |
/** |
|
|
773 |
* Sets a style property for a given element. |
|
|
774 |
* @method setStyle |
|
|
775 |
* @param {HTMLElement} An HTMLElement to apply the style to. |
|
|
776 |
* @param {String} att The style property to set. |
|
|
777 |
* @param {String|Number} val The value. |
|
|
778 |
*/ |
|
|
779 |
setStyle: function(node, att, val, style) { |
|
|
780 |
style = style || node.style; |
|
|
781 |
var CUSTOM_STYLES = Y.DOM.CUSTOM_STYLES; |
|
|
782 |
|
|
|
783 |
if (style) { |
|
|
784 |
if (val === null) { |
|
|
785 |
val = ''; // normalize for unsetting |
|
|
786 |
} |
|
|
787 |
if (att in CUSTOM_STYLES) { |
|
|
788 |
if (CUSTOM_STYLES[att].set) { |
|
|
789 |
CUSTOM_STYLES[att].set(node, val, style); |
|
|
790 |
return; // NOTE: return |
|
|
791 |
} else if (typeof CUSTOM_STYLES[att] === 'string') { |
|
|
792 |
att = CUSTOM_STYLES[att]; |
|
|
793 |
} |
|
|
794 |
} |
|
|
795 |
style[att] = val; |
|
|
796 |
} |
|
|
797 |
}, |
|
|
798 |
|
|
|
799 |
/** |
|
|
800 |
* Returns the current style value for the given property. |
|
|
801 |
* @method getStyle |
|
|
802 |
* @param {HTMLElement} An HTMLElement to get the style from. |
|
|
803 |
* @param {String} att The style property to get. |
|
|
804 |
*/ |
|
|
805 |
getStyle: function(node, att) { |
|
|
806 |
var style = node[STYLE], |
|
|
807 |
CUSTOM_STYLES = Y.DOM.CUSTOM_STYLES, |
|
|
808 |
val = ''; |
|
|
809 |
|
|
|
810 |
if (style) { |
|
|
811 |
if (att in CUSTOM_STYLES) { |
|
|
812 |
if (CUSTOM_STYLES[att].get) { |
|
|
813 |
return CUSTOM_STYLES[att].get(node, att, style); // NOTE: return |
|
|
814 |
} else if (typeof CUSTOM_STYLES[att] === 'string') { |
|
|
815 |
att = CUSTOM_STYLES[att]; |
|
|
816 |
} |
|
|
817 |
} |
|
|
818 |
val = style[att]; |
|
|
819 |
if (val === '') { // TODO: is empty string sufficient? |
|
|
820 |
val = Y.DOM[GET_COMPUTED_STYLE](node, att); |
|
|
821 |
} |
|
|
822 |
} |
|
|
823 |
|
|
|
824 |
return val; |
|
|
825 |
}, |
|
|
826 |
|
|
|
827 |
/** |
|
|
828 |
* Sets multiple style properties. |
|
|
829 |
* @method setStyles |
|
|
830 |
* @param {HTMLElement} node An HTMLElement to apply the styles to. |
|
|
831 |
* @param {Object} hash An object literal of property:value pairs. |
|
|
832 |
*/ |
|
|
833 |
setStyles: function(node, hash) { |
|
|
834 |
var style = node.style; |
|
|
835 |
Y.each(hash, function(v, n) { |
|
|
836 |
Y.DOM.setStyle(node, n, v, style); |
|
|
837 |
}, Y.DOM); |
|
|
838 |
}, |
|
|
839 |
|
|
|
840 |
/** |
|
|
841 |
* Returns the computed style for the given node. |
|
|
842 |
* @method getComputedStyle |
|
|
843 |
* @param {HTMLElement} An HTMLElement to get the style from. |
|
|
844 |
* @param {String} att The style property to get. |
|
|
845 |
* @return {String} The computed value of the style property. |
|
|
846 |
*/ |
|
|
847 |
getComputedStyle: function(node, att) { |
|
|
848 |
var val = '', |
|
|
849 |
doc = node[OWNER_DOCUMENT]; |
|
|
850 |
|
|
|
851 |
if (node[STYLE]) { |
|
|
852 |
val = doc[DEFAULT_VIEW][GET_COMPUTED_STYLE](node, null)[att]; |
|
|
853 |
} |
|
|
854 |
return val; |
|
|
855 |
} |
|
|
856 |
}); |
|
|
857 |
|
|
|
858 |
// normalize reserved word float alternatives ("cssFloat" or "styleFloat") |
|
|
859 |
if (DOCUMENT[DOCUMENT_ELEMENT][STYLE][CSS_FLOAT] !== UNDEFINED) { |
|
|
860 |
Y.DOM.CUSTOM_STYLES[FLOAT] = CSS_FLOAT; |
|
|
861 |
} else if (DOCUMENT[DOCUMENT_ELEMENT][STYLE][STYLE_FLOAT] !== UNDEFINED) { |
|
|
862 |
Y.DOM.CUSTOM_STYLES[FLOAT] = STYLE_FLOAT; |
|
|
863 |
} |
|
|
864 |
|
|
|
865 |
// fix opera computedStyle default color unit (convert to rgb) |
|
|
866 |
if (Y.UA.opera) { |
|
|
867 |
Y.DOM[GET_COMPUTED_STYLE] = function(node, att) { |
|
|
868 |
var view = node[OWNER_DOCUMENT][DEFAULT_VIEW], |
|
|
869 |
val = view[GET_COMPUTED_STYLE](node, '')[att]; |
|
|
870 |
|
|
|
871 |
if (re_color.test(att)) { |
|
|
872 |
val = Y.Color.toRGB(val); |
|
|
873 |
} |
|
|
874 |
|
|
|
875 |
return val; |
|
|
876 |
}; |
|
|
877 |
|
|
|
878 |
} |
|
|
879 |
|
|
|
880 |
// safari converts transparent to rgba(), others use "transparent" |
|
|
881 |
if (Y.UA.webkit) { |
|
|
882 |
Y.DOM[GET_COMPUTED_STYLE] = function(node, att) { |
|
|
883 |
var view = node[OWNER_DOCUMENT][DEFAULT_VIEW], |
|
|
884 |
val = view[GET_COMPUTED_STYLE](node, '')[att]; |
|
|
885 |
|
|
|
886 |
if (val === 'rgba(0, 0, 0, 0)') { |
|
|
887 |
val = TRANSPARENT; |
|
|
888 |
} |
|
|
889 |
|
|
|
890 |
return val; |
|
|
891 |
}; |
|
|
892 |
|
|
|
893 |
} |
|
|
894 |
})(Y); |
|
|
895 |
(function(Y) { |
|
|
896 |
var PARSE_INT = parseInt, |
|
|
897 |
RE = RegExp; |
|
|
898 |
|
|
|
899 |
Y.Color = { |
|
|
900 |
KEYWORDS: { |
|
|
901 |
black: '000', |
|
|
902 |
silver: 'c0c0c0', |
|
|
903 |
gray: '808080', |
|
|
904 |
white: 'fff', |
|
|
905 |
maroon: '800000', |
|
|
906 |
red: 'f00', |
|
|
907 |
purple: '800080', |
|
|
908 |
fuchsia: 'f0f', |
|
|
909 |
green: '008000', |
|
|
910 |
lime: '0f0', |
|
|
911 |
olive: '808000', |
|
|
912 |
yellow: 'ff0', |
|
|
913 |
navy: '000080', |
|
|
914 |
blue: '00f', |
|
|
915 |
teal: '008080', |
|
|
916 |
aqua: '0ff' |
|
|
917 |
}, |
|
|
918 |
|
|
|
919 |
re_RGB: /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i, |
|
|
920 |
re_hex: /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i, |
|
|
921 |
re_hex3: /([0-9A-F])/gi, |
|
|
922 |
|
|
|
923 |
toRGB: function(val) { |
|
|
924 |
if (!Y.Color.re_RGB.test(val)) { |
|
|
925 |
val = Y.Color.toHex(val); |
|
|
926 |
} |
|
|
927 |
|
|
|
928 |
if(Y.Color.re_hex.exec(val)) { |
|
|
929 |
val = 'rgb(' + [ |
|
|
930 |
PARSE_INT(RE.$1, 16), |
|
|
931 |
PARSE_INT(RE.$2, 16), |
|
|
932 |
PARSE_INT(RE.$3, 16) |
|
|
933 |
].join(', ') + ')'; |
|
|
934 |
} |
|
|
935 |
return val; |
|
|
936 |
}, |
|
|
937 |
|
|
|
938 |
toHex: function(val) { |
|
|
939 |
val = Y.Color.KEYWORDS[val] || val; |
|
|
940 |
if (Y.Color.re_RGB.exec(val)) { |
|
|
941 |
val = [ |
|
|
942 |
Number(RE.$1).toString(16), |
|
|
943 |
Number(RE.$2).toString(16), |
|
|
944 |
Number(RE.$3).toString(16) |
|
|
945 |
]; |
|
|
946 |
|
|
|
947 |
for (var i = 0; i < val.length; i++) { |
|
|
948 |
if (val[i].length < 2) { |
|
|
949 |
val[i] = val[i].replace(Y.Color.re_hex3, '$1$1'); |
|
|
950 |
} |
|
|
951 |
} |
|
|
952 |
|
|
|
953 |
val = '#' + val.join(''); |
|
|
954 |
} |
|
|
955 |
|
|
|
956 |
if (val.length < 6) { |
|
|
957 |
val = val.replace(Y.Color.re_hex3, '$1$1'); |
|
|
958 |
} |
|
|
959 |
|
|
|
960 |
if (val !== 'transparent' && val.indexOf('#') < 0) { |
|
|
961 |
val = '#' + val; |
|
|
962 |
} |
|
|
963 |
|
|
|
964 |
return val.toLowerCase(); |
|
|
965 |
} |
|
|
966 |
}; |
|
|
967 |
})(Y); |
|
|
968 |
|
|
|
969 |
(function(Y) { |
|
|
970 |
var HAS_LAYOUT = 'hasLayout', |
|
|
971 |
PX = 'px', |
|
|
972 |
FILTER = 'filter', |
|
|
973 |
FILTERS = 'filters', |
|
|
974 |
OPACITY = 'opacity', |
|
|
975 |
AUTO = 'auto', |
|
|
976 |
|
|
|
977 |
BORDER_WIDTH = 'borderWidth', |
|
|
978 |
BORDER_TOP_WIDTH = 'borderTopWidth', |
|
|
979 |
BORDER_RIGHT_WIDTH = 'borderRightWidth', |
|
|
980 |
BORDER_BOTTOM_WIDTH = 'borderBottomWidth', |
|
|
981 |
BORDER_LEFT_WIDTH = 'borderLeftWidth', |
|
|
982 |
WIDTH = 'width', |
|
|
983 |
HEIGHT = 'height', |
|
|
984 |
TRANSPARENT = 'transparent', |
|
|
985 |
VISIBLE = 'visible', |
|
|
986 |
GET_COMPUTED_STYLE = 'getComputedStyle', |
|
|
987 |
UNDEFINED = undefined, |
|
|
988 |
documentElement = document.documentElement, |
|
|
989 |
|
|
|
990 |
// TODO: unit-less lineHeight (e.g. 1.22) |
|
|
991 |
re_unit = /^(\d[.\d]*)+(em|ex|px|gd|rem|vw|vh|vm|ch|mm|cm|in|pt|pc|deg|rad|ms|s|hz|khz|%){1}?/i, |
|
|
992 |
|
|
|
993 |
_getStyleObj = function(node) { |
|
|
994 |
return node.currentStyle || node.style; |
|
|
995 |
}, |
|
|
996 |
|
|
|
997 |
ComputedStyle = { |
|
|
998 |
CUSTOM_STYLES: {}, |
|
|
999 |
|
|
|
1000 |
get: function(el, property) { |
|
|
1001 |
var value = '', |
|
|
1002 |
current; |
|
|
1003 |
|
|
|
1004 |
if (el) { |
|
|
1005 |
current = _getStyleObj(el)[property]; |
|
|
1006 |
|
|
|
1007 |
if (property === OPACITY && Y.DOM.CUSTOM_STYLES[OPACITY]) { |
|
|
1008 |
value = Y.DOM.CUSTOM_STYLES[OPACITY].get(el); |
|
|
1009 |
} else if (!current || (current.indexOf && current.indexOf(PX) > -1)) { // no need to convert |
|
|
1010 |
value = current; |
|
|
1011 |
} else if (Y.DOM.IE.COMPUTED[property]) { // use compute function |
|
|
1012 |
value = Y.DOM.IE.COMPUTED[property](el, property); |
|
|
1013 |
} else if (re_unit.test(current)) { // convert to pixel |
|
|
1014 |
value = ComputedStyle.getPixel(el, property) + PX; |
|
|
1015 |
} else { |
|
|
1016 |
value = current; |
|
|
1017 |
} |
|
|
1018 |
} |
|
|
1019 |
|
|
|
1020 |
return value; |
|
|
1021 |
}, |
|
|
1022 |
|
|
|
1023 |
sizeOffsets: { |
|
|
1024 |
width: ['Left', 'Right'], |
|
|
1025 |
height: ['Top', 'Bottom'], |
|
|
1026 |
top: ['Top'], |
|
|
1027 |
bottom: ['Bottom'] |
|
|
1028 |
}, |
|
|
1029 |
|
|
|
1030 |
getOffset: function(el, prop) { |
|
|
1031 |
var current = _getStyleObj(el)[prop], // value of "width", "top", etc. |
|
|
1032 |
capped = prop.charAt(0).toUpperCase() + prop.substr(1), // "Width", "Top", etc. |
|
|
1033 |
offset = 'offset' + capped, // "offsetWidth", "offsetTop", etc. |
|
|
1034 |
pixel = 'pixel' + capped, // "pixelWidth", "pixelTop", etc. |
|
|
1035 |
sizeOffsets = ComputedStyle.sizeOffsets[prop], |
|
|
1036 |
value = ''; |
|
|
1037 |
|
|
|
1038 |
// IE pixelWidth incorrect for percent |
|
|
1039 |
// manually compute by subtracting padding and border from offset size |
|
|
1040 |
// NOTE: clientWidth/Height (size minus border) is 0 when current === AUTO so offsetHeight is used |
|
|
1041 |
// reverting to auto from auto causes position stacking issues (old impl) |
|
|
1042 |
if (current === AUTO || current.indexOf('%') > -1) { |
|
|
1043 |
value = el['offset' + capped]; |
|
|
1044 |
|
|
|
1045 |
if (sizeOffsets[0]) { |
|
|
1046 |
value -= ComputedStyle.getPixel(el, 'padding' + sizeOffsets[0]); |
|
|
1047 |
value -= ComputedStyle.getBorderWidth(el, 'border' + sizeOffsets[0] + 'Width', 1); |
|
|
1048 |
} |
|
|
1049 |
|
|
|
1050 |
if (sizeOffsets[1]) { |
|
|
1051 |
value -= ComputedStyle.getPixel(el, 'padding' + sizeOffsets[1]); |
|
|
1052 |
value -= ComputedStyle.getBorderWidth(el, 'border' + sizeOffsets[1] + 'Width', 1); |
|
|
1053 |
} |
|
|
1054 |
|
|
|
1055 |
} else { // use style.pixelWidth, etc. to convert to pixels |
|
|
1056 |
// need to map style.width to currentStyle (no currentStyle.pixelWidth) |
|
|
1057 |
if (!el.style[pixel] && !el.style[prop]) { |
|
|
1058 |
el.style[prop] = current; |
|
|
1059 |
} |
|
|
1060 |
value = el.style[pixel]; |
|
|
1061 |
|
|
|
1062 |
} |
|
|
1063 |
return value + PX; |
|
|
1064 |
}, |
|
|
1065 |
|
|
|
1066 |
borderMap: { |
|
|
1067 |
thin: '2px', |
|
|
1068 |
medium: '4px', |
|
|
1069 |
thick: '6px' |
|
|
1070 |
}, |
|
|
1071 |
|
|
|
1072 |
getBorderWidth: function(el, property, omitUnit) { |
|
|
1073 |
var unit = omitUnit ? '' : PX, |
|
|
1074 |
current = el.currentStyle[property]; |
|
|
1075 |
|
|
|
1076 |
if (current.indexOf(PX) < 0) { // look up keywords |
|
|
1077 |
if (ComputedStyle.borderMap[current]) { |
|
|
1078 |
current = ComputedStyle.borderMap[current]; |
|
|
1079 |
} else { |
|
|
1080 |
Y.log('borderWidth computing not implemented', 'warn', 'dom-ie-style'); |
|
|
1081 |
} |
|
|
1082 |
} |
|
|
1083 |
return (omitUnit) ? parseFloat(current) : current; |
|
|
1084 |
}, |
|
|
1085 |
|
|
|
1086 |
getPixel: function(node, att) { |
|
|
1087 |
// use pixelRight to convert to px |
|
|
1088 |
var val = null, |
|
|
1089 |
style = _getStyleObj(node), |
|
|
1090 |
styleRight = style.right, |
|
|
1091 |
current = style[att]; |
|
|
1092 |
|
|
|
1093 |
node.style.right = current; |
|
|
1094 |
val = node.style.pixelRight; |
|
|
1095 |
node.style.right = styleRight; // revert |
|
|
1096 |
|
|
|
1097 |
return val; |
|
|
1098 |
}, |
|
|
1099 |
|
|
|
1100 |
getMargin: function(node, att) { |
|
|
1101 |
var val, |
|
|
1102 |
style = _getStyleObj(node); |
|
|
1103 |
|
|
|
1104 |
if (style[att] == AUTO) { |
|
|
1105 |
val = 0; |
|
|
1106 |
} else { |
|
|
1107 |
val = ComputedStyle.getPixel(node, att); |
|
|
1108 |
} |
|
|
1109 |
return val + PX; |
|
|
1110 |
}, |
|
|
1111 |
|
|
|
1112 |
getVisibility: function(node, att) { |
|
|
1113 |
var current; |
|
|
1114 |
while ( (current = node.currentStyle) && current[att] == 'inherit') { // NOTE: assignment in test |
|
|
1115 |
node = node.parentNode; |
|
|
1116 |
} |
|
|
1117 |
return (current) ? current[att] : VISIBLE; |
|
|
1118 |
}, |
|
|
1119 |
|
|
|
1120 |
getColor: function(node, att) { |
|
|
1121 |
var current = _getStyleObj(node)[att]; |
|
|
1122 |
|
|
|
1123 |
if (!current || current === TRANSPARENT) { |
|
|
1124 |
Y.DOM.elementByAxis(node, 'parentNode', null, function(parent) { |
|
|
1125 |
current = _getStyleObj(parent)[att]; |
|
|
1126 |
if (current && current !== TRANSPARENT) { |
|
|
1127 |
node = parent; |
|
|
1128 |
return true; |
|
|
1129 |
} |
|
|
1130 |
}); |
|
|
1131 |
} |
|
|
1132 |
|
|
|
1133 |
return Y.Color.toRGB(current); |
|
|
1134 |
}, |
|
|
1135 |
|
|
|
1136 |
getBorderColor: function(node, att) { |
|
|
1137 |
var current = _getStyleObj(node), |
|
|
1138 |
val = current[att] || current.color; |
|
|
1139 |
return Y.Color.toRGB(Y.Color.toHex(val)); |
|
|
1140 |
} |
|
|
1141 |
}, |
|
|
1142 |
|
|
|
1143 |
//fontSize: getPixelFont, |
|
|
1144 |
IEComputed = {}; |
|
|
1145 |
|
|
|
1146 |
// use alpha filter for IE opacity |
|
|
1147 |
try { |
|
|
1148 |
if (documentElement.style[OPACITY] === UNDEFINED && |
|
|
1149 |
documentElement[FILTERS]) { |
|
|
1150 |
Y.DOM.CUSTOM_STYLES[OPACITY] = { |
|
|
1151 |
get: function(node) { |
|
|
1152 |
var val = 100; |
|
|
1153 |
try { // will error if no DXImageTransform |
|
|
1154 |
val = node[FILTERS]['DXImageTransform.Microsoft.Alpha'][OPACITY]; |
|
|
1155 |
|
|
|
1156 |
} catch(e) { |
|
|
1157 |
try { // make sure its in the document |
|
|
1158 |
val = node[FILTERS]('alpha')[OPACITY]; |
|
|
1159 |
} catch(err) { |
|
|
1160 |
Y.log('getStyle: IE opacity filter not found; returning 1', 'warn', 'dom-style'); |
|
|
1161 |
} |
|
|
1162 |
} |
|
|
1163 |
return val / 100; |
|
|
1164 |
}, |
|
|
1165 |
|
|
|
1166 |
set: function(node, val, style) { |
|
|
1167 |
var current, |
|
|
1168 |
styleObj; |
|
|
1169 |
|
|
|
1170 |
if (val === '') { // normalize inline style behavior |
|
|
1171 |
styleObj = _getStyleObj(node); |
|
|
1172 |
current = (OPACITY in styleObj) ? styleObj[OPACITY] : 1; // revert to original opacity |
|
|
1173 |
val = current; |
|
|
1174 |
} |
|
|
1175 |
|
|
|
1176 |
if (typeof style[FILTER] == 'string') { // in case not appended |
|
|
1177 |
style[FILTER] = 'alpha(' + OPACITY + '=' + val * 100 + ')'; |
|
|
1178 |
|
|
|
1179 |
if (!node.currentStyle || !node.currentStyle[HAS_LAYOUT]) { |
|
|
1180 |
style.zoom = 1; // needs layout |
|
|
1181 |
} |
|
|
1182 |
} |
|
|
1183 |
} |
|
|
1184 |
}; |
|
|
1185 |
} |
|
|
1186 |
} catch(e) { |
|
|
1187 |
Y.log('document.documentElement.filters error (activeX disabled)', 'warn', 'dom-style'); |
|
|
1188 |
} |
|
|
1189 |
|
|
|
1190 |
try { |
|
|
1191 |
document.createElement('div').style.height = '-1px'; |
|
|
1192 |
} catch(e) { // IE throws error on invalid style set; trap common cases |
|
|
1193 |
Y.DOM.CUSTOM_STYLES.height = { |
|
|
1194 |
set: function(node, val, style) { |
|
|
1195 |
var floatVal = parseFloat(val); |
|
|
1196 |
if (isNaN(floatVal) || floatVal >= 0) { |
|
|
1197 |
style.height = val; |
|
|
1198 |
} else { |
|
|
1199 |
Y.log('invalid style value for height: ' + val, 'warn', 'dom-style'); |
|
|
1200 |
} |
|
|
1201 |
} |
|
|
1202 |
}; |
|
|
1203 |
|
|
|
1204 |
Y.DOM.CUSTOM_STYLES.width = { |
|
|
1205 |
set: function(node, val, style) { |
|
|
1206 |
var floatVal = parseFloat(val); |
|
|
1207 |
if (isNaN(floatVal) || floatVal >= 0) { |
|
|
1208 |
style.width = val; |
|
|
1209 |
} else { |
|
|
1210 |
Y.log('invalid style value for width: ' + val, 'warn', 'dom-style'); |
|
|
1211 |
} |
|
|
1212 |
} |
|
|
1213 |
}; |
|
|
1214 |
} |
|
|
1215 |
|
|
|
1216 |
// TODO: top, right, bottom, left |
|
|
1217 |
IEComputed[WIDTH] = IEComputed[HEIGHT] = ComputedStyle.getOffset; |
|
|
1218 |
|
|
|
1219 |
IEComputed.color = IEComputed.backgroundColor = ComputedStyle.getColor; |
|
|
1220 |
|
|
|
1221 |
IEComputed[BORDER_WIDTH] = IEComputed[BORDER_TOP_WIDTH] = IEComputed[BORDER_RIGHT_WIDTH] = |
|
|
1222 |
IEComputed[BORDER_BOTTOM_WIDTH] = IEComputed[BORDER_LEFT_WIDTH] = |
|
|
1223 |
ComputedStyle.getBorderWidth; |
|
|
1224 |
|
|
|
1225 |
IEComputed.marginTop = IEComputed.marginRight = IEComputed.marginBottom = |
|
|
1226 |
IEComputed.marginLeft = ComputedStyle.getMargin; |
|
|
1227 |
|
|
|
1228 |
IEComputed.visibility = ComputedStyle.getVisibility; |
|
|
1229 |
IEComputed.borderColor = IEComputed.borderTopColor = |
|
|
1230 |
IEComputed.borderRightColor = IEComputed.borderBottomColor = |
|
|
1231 |
IEComputed.borderLeftColor = ComputedStyle.getBorderColor; |
|
|
1232 |
|
|
|
1233 |
if (!Y.config.win[GET_COMPUTED_STYLE]) { |
|
|
1234 |
Y.DOM[GET_COMPUTED_STYLE] = ComputedStyle.get; |
|
|
1235 |
} |
|
|
1236 |
|
|
|
1237 |
Y.namespace('DOM.IE'); |
|
|
1238 |
Y.DOM.IE.COMPUTED = IEComputed; |
|
|
1239 |
Y.DOM.IE.ComputedStyle = ComputedStyle; |
|
|
1240 |
|
|
|
1241 |
})(Y); |
|
|
1242 |
|
|
|
1243 |
|
|
|
1244 |
}, '3.0.0' ,{requires:['dom-base']}); |
|
|
1245 |
YUI.add('dom-screen', function(Y) { |
|
|
1246 |
|
|
|
1247 |
(function(Y) { |
|
|
1248 |
|
|
|
1249 |
/** |
|
|
1250 |
* Adds position and region management functionality to DOM. |
|
|
1251 |
* @module dom |
|
|
1252 |
* @submodule dom-screen |
|
|
1253 |
* @for DOM |
|
|
1254 |
*/ |
|
|
1255 |
|
|
|
1256 |
var DOCUMENT_ELEMENT = 'documentElement', |
|
|
1257 |
COMPAT_MODE = 'compatMode', |
|
|
1258 |
POSITION = 'position', |
|
|
1259 |
FIXED = 'fixed', |
|
|
1260 |
RELATIVE = 'relative', |
|
|
1261 |
LEFT = 'left', |
|
|
1262 |
TOP = 'top', |
|
|
1263 |
_BACK_COMPAT = 'BackCompat', |
|
|
1264 |
MEDIUM = 'medium', |
|
|
1265 |
BORDER_LEFT_WIDTH = 'borderLeftWidth', |
|
|
1266 |
BORDER_TOP_WIDTH = 'borderTopWidth', |
|
|
1267 |
GET_BOUNDING_CLIENT_RECT = 'getBoundingClientRect', |
|
|
1268 |
GET_COMPUTED_STYLE = 'getComputedStyle', |
|
|
1269 |
|
|
|
1270 |
// TODO: how about thead/tbody/tfoot/tr? |
|
|
1271 |
// TODO: does caption matter? |
|
|
1272 |
RE_TABLE = /^t(?:able|d|h)$/i; |
|
|
1273 |
|
|
|
1274 |
Y.mix(Y.DOM, { |
|
|
1275 |
/** |
|
|
1276 |
* Returns the inner height of the viewport (exludes scrollbar). |
|
|
1277 |
* @method winHeight |
|
|
1278 |
* @return {Number} The current height of the viewport. |
|
|
1279 |
*/ |
|
|
1280 |
winHeight: function(node) { |
|
|
1281 |
var h = Y.DOM._getWinSize(node).height; |
|
|
1282 |
Y.log('winHeight returning ' + h, 'info', 'dom-screen'); |
|
|
1283 |
return h; |
|
|
1284 |
}, |
|
|
1285 |
|
|
|
1286 |
/** |
|
|
1287 |
* Returns the inner width of the viewport (exludes scrollbar). |
|
|
1288 |
* @method winWidth |
|
|
1289 |
* @return {Number} The current width of the viewport. |
|
|
1290 |
*/ |
|
|
1291 |
winWidth: function(node) { |
|
|
1292 |
var w = Y.DOM._getWinSize(node).width; |
|
|
1293 |
Y.log('winWidth returning ' + w, 'info', 'dom-screen'); |
|
|
1294 |
return w; |
|
|
1295 |
}, |
|
|
1296 |
|
|
|
1297 |
/** |
|
|
1298 |
* Document height |
|
|
1299 |
* @method docHeight |
|
|
1300 |
* @return {Number} The current height of the document. |
|
|
1301 |
*/ |
|
|
1302 |
docHeight: function(node) { |
|
|
1303 |
var h = Y.DOM._getDocSize(node).height; |
|
|
1304 |
Y.log('docHeight returning ' + h, 'info', 'dom-screen'); |
|
|
1305 |
return Math.max(h, Y.DOM._getWinSize(node).height); |
|
|
1306 |
}, |
|
|
1307 |
|
|
|
1308 |
/** |
|
|
1309 |
* Document width |
|
|
1310 |
* @method docWidth |
|
|
1311 |
* @return {Number} The current width of the document. |
|
|
1312 |
*/ |
|
|
1313 |
docWidth: function(node) { |
|
|
1314 |
var w = Y.DOM._getDocSize(node).width; |
|
|
1315 |
Y.log('docWidth returning ' + w, 'info', 'dom-screen'); |
|
|
1316 |
return Math.max(w, Y.DOM._getWinSize(node).width); |
|
|
1317 |
}, |
|
|
1318 |
|
|
|
1319 |
/** |
|
|
1320 |
* Amount page has been scroll horizontally |
|
|
1321 |
* @method docScrollX |
|
|
1322 |
* @return {Number} The current amount the screen is scrolled horizontally. |
|
|
1323 |
*/ |
|
|
1324 |
docScrollX: function(node) { |
|
|
1325 |
var doc = Y.DOM._getDoc(node); |
|
|
1326 |
return Math.max(doc[DOCUMENT_ELEMENT].scrollLeft, doc.body.scrollLeft); |
|
|
1327 |
}, |
|
|
1328 |
|
|
|
1329 |
/** |
|
|
1330 |
* Amount page has been scroll vertically |
|
|
1331 |
* @method docScrollY |
|
|
1332 |
* @return {Number} The current amount the screen is scrolled vertically. |
|
|
1333 |
*/ |
|
|
1334 |
docScrollY: function(node) { |
|
|
1335 |
var doc = Y.DOM._getDoc(node); |
|
|
1336 |
return Math.max(doc[DOCUMENT_ELEMENT].scrollTop, doc.body.scrollTop); |
|
|
1337 |
}, |
|
|
1338 |
|
|
|
1339 |
/** |
|
|
1340 |
* Gets the current position of an element based on page coordinates. |
|
|
1341 |
* Element must be part of the DOM tree to have page coordinates |
|
|
1342 |
* (display:none or elements not appended return false). |
|
|
1343 |
* @method getXY |
|
|
1344 |
* @param element The target element |
|
|
1345 |
* @return {Array} The XY position of the element |
|
|
1346 |
|
|
|
1347 |
TODO: test inDocument/display? |
|
|
1348 |
*/ |
|
|
1349 |
getXY: function() { |
|
|
1350 |
if (document[DOCUMENT_ELEMENT][GET_BOUNDING_CLIENT_RECT]) { |
|
|
1351 |
return function(node) { |
|
|
1352 |
var xy = null, |
|
|
1353 |
scrollLeft, |
|
|
1354 |
scrollTop, |
|
|
1355 |
box, |
|
|
1356 |
off1, off2, |
|
|
1357 |
bLeft, bTop, |
|
|
1358 |
mode, |
|
|
1359 |
doc; |
|
|
1360 |
|
|
|
1361 |
if (node) { |
|
|
1362 |
if (Y.DOM.inDoc(node)) { |
|
|
1363 |
scrollLeft = Y.DOM.docScrollX(node); |
|
|
1364 |
scrollTop = Y.DOM.docScrollY(node); |
|
|
1365 |
box = node[GET_BOUNDING_CLIENT_RECT](); |
|
|
1366 |
doc = Y.DOM._getDoc(node); |
|
|
1367 |
xy = [box.left, box.top]; |
|
|
1368 |
|
|
|
1369 |
if (Y.UA.ie) { |
|
|
1370 |
off1 = 2; |
|
|
1371 |
off2 = 2; |
|
|
1372 |
mode = doc[COMPAT_MODE]; |
|
|
1373 |
bLeft = Y.DOM[GET_COMPUTED_STYLE](doc[DOCUMENT_ELEMENT], BORDER_LEFT_WIDTH); |
|
|
1374 |
bTop = Y.DOM[GET_COMPUTED_STYLE](doc[DOCUMENT_ELEMENT], BORDER_TOP_WIDTH); |
|
|
1375 |
|
|
|
1376 |
if (Y.UA.ie === 6) { |
|
|
1377 |
if (mode !== _BACK_COMPAT) { |
|
|
1378 |
off1 = 0; |
|
|
1379 |
off2 = 0; |
|
|
1380 |
} |
|
|
1381 |
} |
|
|
1382 |
|
|
|
1383 |
if ((mode == _BACK_COMPAT)) { |
|
|
1384 |
if (bLeft !== MEDIUM) { |
|
|
1385 |
off1 = parseInt(bLeft, 10); |
|
|
1386 |
} |
|
|
1387 |
if (bTop !== MEDIUM) { |
|
|
1388 |
off2 = parseInt(bTop, 10); |
|
|
1389 |
} |
|
|
1390 |
} |
|
|
1391 |
|
|
|
1392 |
xy[0] -= off1; |
|
|
1393 |
xy[1] -= off2; |
|
|
1394 |
|
|
|
1395 |
} |
|
|
1396 |
|
|
|
1397 |
if ((scrollTop || scrollLeft)) { |
|
|
1398 |
xy[0] += scrollLeft; |
|
|
1399 |
xy[1] += scrollTop; |
|
|
1400 |
} |
|
|
1401 |
} else { // default to current offsets |
|
|
1402 |
xy = Y.DOM._getOffset(node); |
|
|
1403 |
} |
|
|
1404 |
} |
|
|
1405 |
return xy; |
|
|
1406 |
}; |
|
|
1407 |
} else { |
|
|
1408 |
return function(node) { // manually calculate by crawling up offsetParents |
|
|
1409 |
//Calculate the Top and Left border sizes (assumes pixels) |
|
|
1410 |
var xy = null, |
|
|
1411 |
parentNode, |
|
|
1412 |
bCheck, |
|
|
1413 |
scrollTop, |
|
|
1414 |
scrollLeft; |
|
|
1415 |
|
|
|
1416 |
if (node) { |
|
|
1417 |
if (Y.DOM.inDoc(node)) { |
|
|
1418 |
xy = [node.offsetLeft, node.offsetTop]; |
|
|
1419 |
parentNode = node; |
|
|
1420 |
// TODO: refactor with !! or just falsey |
|
|
1421 |
bCheck = ((Y.UA.gecko || Y.UA.webkit > 519) ? true : false); |
|
|
1422 |
|
|
|
1423 |
// TODO: worth refactoring for TOP/LEFT only? |
|
|
1424 |
while ((parentNode = parentNode.offsetParent)) { |
|
|
1425 |
xy[0] += parentNode.offsetLeft; |
|
|
1426 |
xy[1] += parentNode.offsetTop; |
|
|
1427 |
if (bCheck) { |
|
|
1428 |
xy = Y.DOM._calcBorders(parentNode, xy); |
|
|
1429 |
} |
|
|
1430 |
} |
|
|
1431 |
|
|
|
1432 |
// account for any scrolled ancestors |
|
|
1433 |
if (Y.DOM.getStyle(node, POSITION) != FIXED) { |
|
|
1434 |
parentNode = node; |
|
|
1435 |
|
|
|
1436 |
while ((parentNode = parentNode.parentNode)) { |
|
|
1437 |
scrollTop = parentNode.scrollTop; |
|
|
1438 |
scrollLeft = parentNode.scrollLeft; |
|
|
1439 |
|
|
|
1440 |
//Firefox does something funky with borders when overflow is not visible. |
|
|
1441 |
if (Y.UA.gecko && (Y.DOM.getStyle(parentNode, 'overflow') !== 'visible')) { |
|
|
1442 |
xy = Y.DOM._calcBorders(parentNode, xy); |
|
|
1443 |
} |
|
|
1444 |
|
|
|
1445 |
|
|
|
1446 |
if (scrollTop || scrollLeft) { |
|
|
1447 |
xy[0] -= scrollLeft; |
|
|
1448 |
xy[1] -= scrollTop; |
|
|
1449 |
} |
|
|
1450 |
} |
|
|
1451 |
xy[0] += Y.DOM.docScrollX(node); |
|
|
1452 |
xy[1] += Y.DOM.docScrollY(node); |
|
|
1453 |
|
|
|
1454 |
} else { |
|
|
1455 |
//Fix FIXED position -- add scrollbars |
|
|
1456 |
xy[0] += Y.DOM.docScrollX(node); |
|
|
1457 |
xy[1] += Y.DOM.docScrollY(node); |
|
|
1458 |
} |
|
|
1459 |
} else { |
|
|
1460 |
xy = Y.DOM._getOffset(node); |
|
|
1461 |
} |
|
|
1462 |
} |
|
|
1463 |
|
|
|
1464 |
return xy; |
|
|
1465 |
}; |
|
|
1466 |
} |
|
|
1467 |
}(),// NOTE: Executing for loadtime branching |
|
|
1468 |
|
|
|
1469 |
_getOffset: function(node) { |
|
|
1470 |
var pos, |
|
|
1471 |
xy = null; |
|
|
1472 |
|
|
|
1473 |
if (node) { |
|
|
1474 |
pos = Y.DOM.getStyle(node, POSITION); |
|
|
1475 |
xy = [ |
|
|
1476 |
parseInt(Y.DOM[GET_COMPUTED_STYLE](node, LEFT), 10), |
|
|
1477 |
parseInt(Y.DOM[GET_COMPUTED_STYLE](node, TOP), 10) |
|
|
1478 |
]; |
|
|
1479 |
|
|
|
1480 |
if ( isNaN(xy[0]) ) { // in case of 'auto' |
|
|
1481 |
xy[0] = parseInt(Y.DOM.getStyle(node, LEFT), 10); // try inline |
|
|
1482 |
if ( isNaN(xy[0]) ) { // default to offset value |
|
|
1483 |
xy[0] = (pos === RELATIVE) ? 0 : node.offsetLeft || 0; |
|
|
1484 |
} |
|
|
1485 |
} |
|
|
1486 |
|
|
|
1487 |
if ( isNaN(xy[1]) ) { // in case of 'auto' |
|
|
1488 |
xy[1] = parseInt(Y.DOM.getStyle(node, TOP), 10); // try inline |
|
|
1489 |
if ( isNaN(xy[1]) ) { // default to offset value |
|
|
1490 |
xy[1] = (pos === RELATIVE) ? 0 : node.offsetTop || 0; |
|
|
1491 |
} |
|
|
1492 |
} |
|
|
1493 |
} |
|
|
1494 |
|
|
|
1495 |
return xy; |
|
|
1496 |
|
|
|
1497 |
}, |
|
|
1498 |
|
|
|
1499 |
/** |
|
|
1500 |
* Gets the current X position of an element based on page coordinates. |
|
|
1501 |
* Element must be part of the DOM tree to have page coordinates |
|
|
1502 |
* (display:none or elements not appended return false). |
|
|
1503 |
* @method getX |
|
|
1504 |
* @param element The target element |
|
|
1505 |
* @return {Int} The X position of the element |
|
|
1506 |
*/ |
|
|
1507 |
|
|
|
1508 |
getX: function(node) { |
|
|
1509 |
return Y.DOM.getXY(node)[0]; |
|
|
1510 |
}, |
|
|
1511 |
|
|
|
1512 |
/** |
|
|
1513 |
* Gets the current Y position of an element based on page coordinates. |
|
|
1514 |
* Element must be part of the DOM tree to have page coordinates |
|
|
1515 |
* (display:none or elements not appended return false). |
|
|
1516 |
* @method getY |
|
|
1517 |
* @param element The target element |
|
|
1518 |
* @return {Int} The Y position of the element |
|
|
1519 |
*/ |
|
|
1520 |
|
|
|
1521 |
getY: function(node) { |
|
|
1522 |
return Y.DOM.getXY(node)[1]; |
|
|
1523 |
}, |
|
|
1524 |
|
|
|
1525 |
/** |
|
|
1526 |
* Set the position of an html element in page coordinates. |
|
|
1527 |
* The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). |
|
|
1528 |
* @method setXY |
|
|
1529 |
* @param element The target element |
|
|
1530 |
* @param {Array} xy Contains X & Y values for new position (coordinates are page-based) |
|
|
1531 |
* @param {Boolean} noRetry By default we try and set the position a second time if the first fails |
|
|
1532 |
*/ |
|
|
1533 |
setXY: function(node, xy, noRetry) { |
|
|
1534 |
var setStyle = Y.DOM.setStyle, |
|
|
1535 |
pos, |
|
|
1536 |
delta, |
|
|
1537 |
newXY, |
|
|
1538 |
currentXY; |
|
|
1539 |
|
|
|
1540 |
if (node && xy) { |
|
|
1541 |
pos = Y.DOM.getStyle(node, POSITION); |
|
|
1542 |
|
|
|
1543 |
delta = Y.DOM._getOffset(node); |
|
|
1544 |
|
|
|
1545 |
if (pos == 'static') { // default to relative |
|
|
1546 |
pos = RELATIVE; |
|
|
1547 |
setStyle(node, POSITION, pos); |
|
|
1548 |
} |
|
|
1549 |
|
|
|
1550 |
currentXY = Y.DOM.getXY(node); |
|
|
1551 |
|
|
|
1552 |
if (xy[0] !== null) { |
|
|
1553 |
setStyle(node, LEFT, xy[0] - currentXY[0] + delta[0] + 'px'); |
|
|
1554 |
} |
|
|
1555 |
|
|
|
1556 |
if (xy[1] !== null) { |
|
|
1557 |
setStyle(node, TOP, xy[1] - currentXY[1] + delta[1] + 'px'); |
|
|
1558 |
} |
|
|
1559 |
|
|
|
1560 |
if (!noRetry) { |
|
|
1561 |
newXY = Y.DOM.getXY(node); |
|
|
1562 |
if (newXY[0] !== xy[0] || newXY[1] !== xy[1]) { |
|
|
1563 |
Y.DOM.setXY(node, xy, true); |
|
|
1564 |
} |
|
|
1565 |
} |
|
|
1566 |
|
|
|
1567 |
Y.log('setXY setting position to ' + xy, 'info', 'dom-screen'); |
|
|
1568 |
} else { |
|
|
1569 |
Y.log('setXY failed to set ' + node + ' to ' + xy, 'info', 'dom-screen'); |
|
|
1570 |
} |
|
|
1571 |
}, |
|
|
1572 |
|
|
|
1573 |
/** |
|
|
1574 |
* Set the X position of an html element in page coordinates, regardless of how the element is positioned. |
|
|
1575 |
* The element(s) must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). |
|
|
1576 |
* @method setX |
|
|
1577 |
* @param element The target element |
|
|
1578 |
* @param {Int} x The X values for new position (coordinates are page-based) |
|
|
1579 |
*/ |
|
|
1580 |
setX: function(node, x) { |
|
|
1581 |
return Y.DOM.setXY(node, [x, null]); |
|
|
1582 |
}, |
|
|
1583 |
|
|
|
1584 |
/** |
|
|
1585 |
* Set the Y position of an html element in page coordinates, regardless of how the element is positioned. |
|
|
1586 |
* The element(s) must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). |
|
|
1587 |
* @method setY |
|
|
1588 |
* @param element The target element |
|
|
1589 |
* @param {Int} y The Y values for new position (coordinates are page-based) |
|
|
1590 |
*/ |
|
|
1591 |
setY: function(node, y) { |
|
|
1592 |
return Y.DOM.setXY(node, [null, y]); |
|
|
1593 |
}, |
|
|
1594 |
|
|
|
1595 |
_calcBorders: function(node, xy2) { |
|
|
1596 |
var t = parseInt(Y.DOM[GET_COMPUTED_STYLE](node, BORDER_TOP_WIDTH), 10) || 0, |
|
|
1597 |
l = parseInt(Y.DOM[GET_COMPUTED_STYLE](node, BORDER_LEFT_WIDTH), 10) || 0; |
|
|
1598 |
if (Y.UA.gecko) { |
|
|
1599 |
if (RE_TABLE.test(node.tagName)) { |
|
|
1600 |
t = 0; |
|
|
1601 |
l = 0; |
|
|
1602 |
} |
|
|
1603 |
} |
|
|
1604 |
xy2[0] += l; |
|
|
1605 |
xy2[1] += t; |
|
|
1606 |
return xy2; |
|
|
1607 |
}, |
|
|
1608 |
|
|
|
1609 |
_getWinSize: function(node) { |
|
|
1610 |
var doc = Y.DOM._getDoc(), |
|
|
1611 |
win = doc.defaultView || doc.parentWindow, |
|
|
1612 |
mode = doc[COMPAT_MODE], |
|
|
1613 |
h = win.innerHeight, |
|
|
1614 |
w = win.innerWidth, |
|
|
1615 |
root = doc[DOCUMENT_ELEMENT]; |
|
|
1616 |
|
|
|
1617 |
if ( mode && !Y.UA.opera ) { // IE, Gecko |
|
|
1618 |
if (mode != 'CSS1Compat') { // Quirks |
|
|
1619 |
root = doc.body; |
|
|
1620 |
} |
|
|
1621 |
h = root.clientHeight; |
|
|
1622 |
w = root.clientWidth; |
|
|
1623 |
} |
|
|
1624 |
return { height: h, width: w }; |
|
|
1625 |
}, |
|
|
1626 |
|
|
|
1627 |
_getDocSize: function(node) { |
|
|
1628 |
var doc = Y.DOM._getDoc(), |
|
|
1629 |
root = doc[DOCUMENT_ELEMENT]; |
|
|
1630 |
|
|
|
1631 |
if (doc[COMPAT_MODE] != 'CSS1Compat') { |
|
|
1632 |
root = doc.body; |
|
|
1633 |
} |
|
|
1634 |
|
|
|
1635 |
return { height: root.scrollHeight, width: root.scrollWidth }; |
|
|
1636 |
} |
|
|
1637 |
}); |
|
|
1638 |
})(Y); |
|
|
1639 |
(function(Y) { |
|
|
1640 |
var TOP = 'top', |
|
|
1641 |
RIGHT = 'right', |
|
|
1642 |
BOTTOM = 'bottom', |
|
|
1643 |
LEFT = 'left', |
|
|
1644 |
|
|
|
1645 |
getOffsets = function(r1, r2) { |
|
|
1646 |
var t = Math.max(r1[TOP], r2[TOP]), |
|
|
1647 |
r = Math.min(r1[RIGHT], r2[RIGHT]), |
|
|
1648 |
b = Math.min(r1[BOTTOM], r2[BOTTOM]), |
|
|
1649 |
l = Math.max(r1[LEFT], r2[LEFT]), |
|
|
1650 |
ret = {}; |
|
|
1651 |
|
|
|
1652 |
ret[TOP] = t; |
|
|
1653 |
ret[RIGHT] = r; |
|
|
1654 |
ret[BOTTOM] = b; |
|
|
1655 |
ret[LEFT] = l; |
|
|
1656 |
return ret; |
|
|
1657 |
}, |
|
|
1658 |
|
|
|
1659 |
DOM = Y.DOM; |
|
|
1660 |
|
|
|
1661 |
Y.mix(DOM, { |
|
|
1662 |
/** |
|
|
1663 |
* Returns an Object literal containing the following about this element: (top, right, bottom, left) |
|
|
1664 |
* @method region |
|
|
1665 |
* @param {HTMLElement} element The DOM element. |
|
|
1666 |
@return {Object} Object literal containing the following about this element: (top, right, bottom, left) |
|
|
1667 |
*/ |
|
|
1668 |
region: function(node) { |
|
|
1669 |
var xy = DOM.getXY(node), |
|
|
1670 |
ret = false; |
|
|
1671 |
|
|
|
1672 |
if (node && xy) { |
|
|
1673 |
ret = DOM._getRegion( |
|
|
1674 |
xy[1], // top |
|
|
1675 |
xy[0] + node.offsetWidth, // right |
|
|
1676 |
xy[1] + node.offsetHeight, // bottom |
|
|
1677 |
xy[0] // left |
|
|
1678 |
); |
|
|
1679 |
} |
|
|
1680 |
|
|
|
1681 |
return ret; |
|
|
1682 |
}, |
|
|
1683 |
|
|
|
1684 |
/** |
|
|
1685 |
* Find the intersect information for the passes nodes. |
|
|
1686 |
* @method intersect |
|
|
1687 |
* @param {HTMLElement} element The first element |
|
|
1688 |
* @param {HTMLElement | Object} element2 The element or region to check the interect with |
|
|
1689 |
* @param {Object} altRegion An object literal containing the region for the first element if we already have the data (for performance i.e. DragDrop) |
|
|
1690 |
@return {Object} Object literal containing the following intersection data: (top, right, bottom, left, area, yoff, xoff, inRegion) |
|
|
1691 |
*/ |
|
|
1692 |
intersect: function(node, node2, altRegion) { |
|
|
1693 |
var r = altRegion || DOM.region(node), region = {}, |
|
|
1694 |
n = node2, |
|
|
1695 |
off; |
|
|
1696 |
|
|
|
1697 |
if (n.tagName) { |
|
|
1698 |
region = DOM.region(n); |
|
|
1699 |
} else if (Y.Lang.isObject(node2)) { |
|
|
1700 |
region = node2; |
|
|
1701 |
} else { |
|
|
1702 |
return false; |
|
|
1703 |
} |
|
|
1704 |
|
|
|
1705 |
off = getOffsets(region, r); |
|
|
1706 |
return { |
|
|
1707 |
top: off[TOP], |
|
|
1708 |
right: off[RIGHT], |
|
|
1709 |
bottom: off[BOTTOM], |
|
|
1710 |
left: off[LEFT], |
|
|
1711 |
area: ((off[BOTTOM] - off[TOP]) * (off[RIGHT] - off[LEFT])), |
|
|
1712 |
yoff: ((off[BOTTOM] - off[TOP])), |
|
|
1713 |
xoff: (off[RIGHT] - off[LEFT]), |
|
|
1714 |
inRegion: DOM.inRegion(node, node2, false, altRegion) |
|
|
1715 |
}; |
|
|
1716 |
|
|
|
1717 |
}, |
|
|
1718 |
/** |
|
|
1719 |
* Check if any part of this node is in the passed region |
|
|
1720 |
* @method inRegion |
|
|
1721 |
* @param {Object} node2 The node to get the region from or an Object literal of the region |
|
|
1722 |
* $param {Boolean} all Should all of the node be inside the region |
|
|
1723 |
* @param {Object} altRegion An object literal containing the region for this node if we already have the data (for performance i.e. DragDrop) |
|
|
1724 |
* @return {Boolean} True if in region, false if not. |
|
|
1725 |
*/ |
|
|
1726 |
inRegion: function(node, node2, all, altRegion) { |
|
|
1727 |
var region = {}, |
|
|
1728 |
r = altRegion || DOM.region(node), |
|
|
1729 |
n = node2, |
|
|
1730 |
off; |
|
|
1731 |
|
|
|
1732 |
if (n.tagName) { |
|
|
1733 |
region = DOM.region(n); |
|
|
1734 |
} else if (Y.Lang.isObject(node2)) { |
|
|
1735 |
region = node2; |
|
|
1736 |
} else { |
|
|
1737 |
return false; |
|
|
1738 |
} |
|
|
1739 |
|
|
|
1740 |
if (all) { |
|
|
1741 |
return ( |
|
|
1742 |
r[LEFT] >= region[LEFT] && |
|
|
1743 |
r[RIGHT] <= region[RIGHT] && |
|
|
1744 |
r[TOP] >= region[TOP] && |
|
|
1745 |
r[BOTTOM] <= region[BOTTOM] ); |
|
|
1746 |
} else { |
|
|
1747 |
off = getOffsets(region, r); |
|
|
1748 |
if (off[BOTTOM] >= off[TOP] && off[RIGHT] >= off[LEFT]) { |
|
|
1749 |
return true; |
|
|
1750 |
} else { |
|
|
1751 |
return false; |
|
|
1752 |
} |
|
|
1753 |
|
|
|
1754 |
} |
|
|
1755 |
}, |
|
|
1756 |
|
|
|
1757 |
/** |
|
|
1758 |
* Check if any part of this element is in the viewport |
|
|
1759 |
* @method inViewportRegion |
|
|
1760 |
* @param {HTMLElement} element The DOM element. |
|
|
1761 |
* @param {Boolean} all Should all of the node be inside the region |
|
|
1762 |
* @param {Object} altRegion An object literal containing the region for this node if we already have the data (for performance i.e. DragDrop) |
|
|
1763 |
* @return {Boolean} True if in region, false if not. |
|
|
1764 |
*/ |
|
|
1765 |
inViewportRegion: function(node, all, altRegion) { |
|
|
1766 |
return DOM.inRegion(node, DOM.viewportRegion(node), all, altRegion); |
|
|
1767 |
|
|
|
1768 |
}, |
|
|
1769 |
|
|
|
1770 |
_getRegion: function(t, r, b, l) { |
|
|
1771 |
var region = {}; |
|
|
1772 |
|
|
|
1773 |
region[TOP] = region[1] = t; |
|
|
1774 |
region[LEFT] = region[0] = l; |
|
|
1775 |
region[BOTTOM] = b; |
|
|
1776 |
region[RIGHT] = r; |
|
|
1777 |
region.width = region[RIGHT] - region[LEFT]; |
|
|
1778 |
region.height = region[BOTTOM] - region[TOP]; |
|
|
1779 |
|
|
|
1780 |
return region; |
|
|
1781 |
}, |
|
|
1782 |
|
|
|
1783 |
/** |
|
|
1784 |
* Returns an Object literal containing the following about the visible region of viewport: (top, right, bottom, left) |
|
|
1785 |
* @method viewportRegion |
|
|
1786 |
@return {Object} Object literal containing the following about the visible region of the viewport: (top, right, bottom, left) |
|
|
1787 |
*/ |
|
|
1788 |
viewportRegion: function(node) { |
|
|
1789 |
node = node || Y.config.doc.documentElement; |
|
|
1790 |
var ret = false, |
|
|
1791 |
scrollX, |
|
|
1792 |
scrollY; |
|
|
1793 |
|
|
|
1794 |
if (node) { |
|
|
1795 |
scrollX = DOM.docScrollX(node); |
|
|
1796 |
scrollY = DOM.docScrollY(node); |
|
|
1797 |
|
|
|
1798 |
ret = DOM._getRegion(scrollY, // top |
|
|
1799 |
DOM.winWidth(node) + scrollX, // right |
|
|
1800 |
scrollY + DOM.winHeight(node), // bottom |
|
|
1801 |
scrollX); // left |
|
|
1802 |
} |
|
|
1803 |
|
|
|
1804 |
return ret; |
|
|
1805 |
} |
|
|
1806 |
}); |
|
|
1807 |
})(Y); |
|
|
1808 |
|
|
|
1809 |
|
|
|
1810 |
}, '3.0.0' ,{requires:['dom-base', 'dom-style']}); |
|
|
1811 |
YUI.add('selector-native', function(Y) { |
|
|
1812 |
|
|
|
1813 |
(function(Y) { |
|
|
1814 |
/** |
|
|
1815 |
* The selector-native module provides support for native querySelector |
|
|
1816 |
* @module dom |
|
|
1817 |
* @submodule selector-native |
|
|
1818 |
* @for Selector |
|
|
1819 |
*/ |
|
|
1820 |
|
|
|
1821 |
/** |
|
|
1822 |
* Provides support for using CSS selectors to query the DOM |
|
|
1823 |
* @class Selector |
|
|
1824 |
* @static |
|
|
1825 |
* @for Selector |
|
|
1826 |
*/ |
|
|
1827 |
|
|
|
1828 |
Y.namespace('Selector'); // allow native module to standalone |
|
|
1829 |
|
|
|
1830 |
var COMPARE_DOCUMENT_POSITION = 'compareDocumentPosition', |
|
|
1831 |
OWNER_DOCUMENT = 'ownerDocument', |
|
|
1832 |
TMP_PREFIX = 'yui-tmp-', |
|
|
1833 |
g_counter = 0; |
|
|
1834 |
|
|
|
1835 |
var Selector = { |
|
|
1836 |
_foundCache: [], |
|
|
1837 |
|
|
|
1838 |
useNative: true, |
|
|
1839 |
|
|
|
1840 |
_compare: ('sourceIndex' in document.documentElement) ? |
|
|
1841 |
function(nodeA, nodeB) { |
|
|
1842 |
var a = nodeA.sourceIndex, |
|
|
1843 |
b = nodeB.sourceIndex; |
|
|
1844 |
|
|
|
1845 |
if (a === b) { |
|
|
1846 |
return 0; |
|
|
1847 |
} else if (a > b) { |
|
|
1848 |
return 1; |
|
|
1849 |
} |
|
|
1850 |
|
|
|
1851 |
return -1; |
|
|
1852 |
|
|
|
1853 |
} : (document.documentElement[COMPARE_DOCUMENT_POSITION] ? |
|
|
1854 |
function(nodeA, nodeB) { |
|
|
1855 |
if (nodeA[COMPARE_DOCUMENT_POSITION](nodeB) & 4) { |
|
|
1856 |
return -1; |
|
|
1857 |
} else { |
|
|
1858 |
return 1; |
|
|
1859 |
} |
|
|
1860 |
} : |
|
|
1861 |
function(nodeA, nodeB) { |
|
|
1862 |
var rangeA, rangeB, compare; |
|
|
1863 |
if (nodeA && nodeB) { |
|
|
1864 |
rangeA = nodeA[OWNER_DOCUMENT].createRange(); |
|
|
1865 |
rangeA.setStart(nodeA, 0); |
|
|
1866 |
rangeB = nodeB[OWNER_DOCUMENT].createRange(); |
|
|
1867 |
rangeB.setStart(nodeB, 0); |
|
|
1868 |
compare = rangeA.compareBoundaryPoints(1, rangeB); // 1 === Range.START_TO_END |
|
|
1869 |
} |
|
|
1870 |
|
|
|
1871 |
return compare; |
|
|
1872 |
|
|
|
1873 |
}), |
|
|
1874 |
|
|
|
1875 |
_sort: function(nodes) { |
|
|
1876 |
if (nodes) { |
|
|
1877 |
nodes = Y.Array(nodes, 0, true); |
|
|
1878 |
if (nodes.sort) { |
|
|
1879 |
nodes.sort(Selector._compare); |
|
|
1880 |
} |
|
|
1881 |
} |
|
|
1882 |
|
|
|
1883 |
return nodes; |
|
|
1884 |
}, |
|
|
1885 |
|
|
|
1886 |
_deDupe: function(nodes) { |
|
|
1887 |
var ret = [], |
|
|
1888 |
i, node; |
|
|
1889 |
|
|
|
1890 |
for (i = 0; (node = nodes[i++]);) { |
|
|
1891 |
if (!node._found) { |
|
|
1892 |
ret[ret.length] = node; |
|
|
1893 |
node._found = true; |
|
|
1894 |
} |
|
|
1895 |
} |
|
|
1896 |
|
|
|
1897 |
for (i = 0; (node = ret[i++]);) { |
|
|
1898 |
node._found = null; |
|
|
1899 |
node.removeAttribute('_found'); |
|
|
1900 |
} |
|
|
1901 |
|
|
|
1902 |
return ret; |
|
|
1903 |
}, |
|
|
1904 |
|
|
|
1905 |
/** |
|
|
1906 |
* Retrieves a set of nodes based on a given CSS selector. |
|
|
1907 |
* @method query |
|
|
1908 |
* |
|
|
1909 |
* @param {string} selector The CSS Selector to test the node against. |
|
|
1910 |
* @param {HTMLElement} root optional An HTMLElement to start the query from. Defaults to Y.config.doc |
|
|
1911 |
* @param {Boolean} firstOnly optional Whether or not to return only the first match. |
|
|
1912 |
* @return {Array} An array of nodes that match the given selector. |
|
|
1913 |
* @static |
|
|
1914 |
*/ |
|
|
1915 |
query: function(selector, root, firstOnly, skipNative) { |
|
|
1916 |
root = root || Y.config.doc; |
|
|
1917 |
var ret = [], |
|
|
1918 |
useNative = (Y.Selector.useNative && document.querySelector && !skipNative), |
|
|
1919 |
queries = [[selector, root]], |
|
|
1920 |
query, |
|
|
1921 |
result, |
|
|
1922 |
i, |
|
|
1923 |
fn = (useNative) ? Y.Selector._nativeQuery : Y.Selector._bruteQuery; |
|
|
1924 |
|
|
|
1925 |
if (selector && fn) { |
|
|
1926 |
// split group into seperate queries |
|
|
1927 |
if (!skipNative && // already done if skipping |
|
|
1928 |
(!useNative || root.tagName)) { // split native when element scoping is needed |
|
|
1929 |
queries = Selector._splitQueries(selector, root); |
|
|
1930 |
} |
|
|
1931 |
|
|
|
1932 |
for (i = 0; (query = queries[i++]);) { |
|
|
1933 |
result = fn(query[0], query[1], firstOnly); |
|
|
1934 |
if (!firstOnly) { // coerce DOM Collection to Array |
|
|
1935 |
result = Y.Array(result, 0, true); |
|
|
1936 |
} |
|
|
1937 |
if (result) { |
|
|
1938 |
ret = ret.concat(result); |
|
|
1939 |
} |
|
|
1940 |
} |
|
|
1941 |
|
|
|
1942 |
if (queries.length > 1) { // remove dupes and sort by doc order |
|
|
1943 |
ret = Selector._sort(Selector._deDupe(ret)); |
|
|
1944 |
} |
|
|
1945 |
} |
|
|
1946 |
|
|
|
1947 |
Y.log('query: ' + selector + ' returning: ' + ret.length, 'info', 'Selector'); |
|
|
1948 |
return (firstOnly) ? (ret[0] || null) : ret; |
|
|
1949 |
|
|
|
1950 |
}, |
|
|
1951 |
|
|
|
1952 |
// allows element scoped queries to begin with combinator |
|
|
1953 |
// e.g. query('> p', document.body) === query('body > p') |
|
|
1954 |
_splitQueries: function(selector, node) { |
|
|
1955 |
var groups = selector.split(','), |
|
|
1956 |
queries = [], |
|
|
1957 |
prefix = '', |
|
|
1958 |
i, len; |
|
|
1959 |
|
|
|
1960 |
if (node) { |
|
|
1961 |
// enforce for element scoping |
|
|
1962 |
if (node.tagName) { |
|
|
1963 |
node.id = node.id || Y.guid(); |
|
|
1964 |
prefix = '#' + node.id + ' '; |
|
|
1965 |
} |
|
|
1966 |
|
|
|
1967 |
for (i = 0, len = groups.length; i < len; ++i) { |
|
|
1968 |
selector = prefix + groups[i]; |
|
|
1969 |
queries.push([selector, node]); |
|
|
1970 |
} |
|
|
1971 |
} |
|
|
1972 |
|
|
|
1973 |
return queries; |
|
|
1974 |
}, |
|
|
1975 |
|
|
|
1976 |
_nativeQuery: function(selector, root, one) { |
|
|
1977 |
try { |
|
|
1978 |
//Y.log('trying native query with: ' + selector, 'info', 'selector-native'); |
|
|
1979 |
return root['querySelector' + (one ? '' : 'All')](selector); |
|
|
1980 |
} catch(e) { // fallback to brute if available |
|
|
1981 |
//Y.log('native query error; reverting to brute query with: ' + selector, 'info', 'selector-native'); |
|
|
1982 |
return Y.Selector.query(selector, root, one, true); // redo with skipNative true |
|
|
1983 |
} |
|
|
1984 |
}, |
|
|
1985 |
|
|
|
1986 |
filter: function(nodes, selector) { |
|
|
1987 |
var ret = [], |
|
|
1988 |
i, node; |
|
|
1989 |
|
|
|
1990 |
if (nodes && selector) { |
|
|
1991 |
for (i = 0; (node = nodes[i++]);) { |
|
|
1992 |
if (Y.Selector.test(node, selector)) { |
|
|
1993 |
ret[ret.length] = node; |
|
|
1994 |
} |
|
|
1995 |
} |
|
|
1996 |
} else { |
|
|
1997 |
Y.log('invalid filter input (nodes: ' + nodes + |
|
|
1998 |
', selector: ' + selector + ')', 'warn', 'Selector'); |
|
|
1999 |
} |
|
|
2000 |
|
|
|
2001 |
return ret; |
|
|
2002 |
}, |
|
|
2003 |
|
|
|
2004 |
test: function(node, selector, root) { |
|
|
2005 |
var ret = false, |
|
|
2006 |
groups = selector.split(','), |
|
|
2007 |
item, |
|
|
2008 |
i, group; |
|
|
2009 |
|
|
|
2010 |
if (node && node.tagName) { // only test HTMLElements |
|
|
2011 |
root = root || node.ownerDocument; |
|
|
2012 |
|
|
|
2013 |
if (!node.id) { |
|
|
2014 |
node.id = TMP_PREFIX + g_counter++; |
|
|
2015 |
} |
|
|
2016 |
for (i = 0; (group = groups[i++]);) { // TODO: off-dom test |
|
|
2017 |
group += '#' + node.id; // add ID for uniqueness |
|
|
2018 |
item = Y.Selector.query(group, root, true); |
|
|
2019 |
ret = (item === node); |
|
|
2020 |
if (ret) { |
|
|
2021 |
break; |
|
|
2022 |
} |
|
|
2023 |
} |
|
|
2024 |
} |
|
|
2025 |
|
|
|
2026 |
return ret; |
|
|
2027 |
} |
|
|
2028 |
}; |
|
|
2029 |
|
|
|
2030 |
Y.mix(Y.Selector, Selector, true); |
|
|
2031 |
|
|
|
2032 |
})(Y); |
|
|
2033 |
|
|
|
2034 |
|
|
|
2035 |
}, '3.0.0' ,{requires:['dom-base']}); |
|
|
2036 |
YUI.add('selector-css2', function(Y) { |
|
|
2037 |
|
|
|
2038 |
/** |
|
|
2039 |
* The selector module provides helper methods allowing CSS2 Selectors to be used with DOM elements. |
|
|
2040 |
* @module dom |
|
|
2041 |
* @submodule selector-css2 |
|
|
2042 |
* @for Selector |
|
|
2043 |
*/ |
|
|
2044 |
|
|
|
2045 |
/** |
|
|
2046 |
* Provides helper methods for collecting and filtering DOM elements. |
|
|
2047 |
*/ |
|
|
2048 |
|
|
|
2049 |
var PARENT_NODE = 'parentNode', |
|
|
2050 |
TAG_NAME = 'tagName', |
|
|
2051 |
ATTRIBUTES = 'attributes', |
|
|
2052 |
COMBINATOR = 'combinator', |
|
|
2053 |
PSEUDOS = 'pseudos', |
|
|
2054 |
|
|
|
2055 |
Selector = Y.Selector, |
|
|
2056 |
|
|
|
2057 |
SelectorCSS2 = { |
|
|
2058 |
SORT_RESULTS: true, |
|
|
2059 |
_children: function(node, tag) { |
|
|
2060 |
var ret = node.children, |
|
|
2061 |
i, |
|
|
2062 |
children = [], |
|
|
2063 |
childNodes, |
|
|
2064 |
child; |
|
|
2065 |
|
|
|
2066 |
if (node.children && tag && node.children.tags) { |
|
|
2067 |
children = node.children.tags(tag); |
|
|
2068 |
} else if ((!ret && node[TAG_NAME]) || (ret && tag)) { // only HTMLElements have children |
|
|
2069 |
childNodes = ret || node.childNodes; |
|
|
2070 |
ret = []; |
|
|
2071 |
for (i = 0; (child = childNodes[i++]);) { |
|
|
2072 |
if (child.tagName) { |
|
|
2073 |
if (!tag || tag === child.tagName) { |
|
|
2074 |
ret.push(child); |
|
|
2075 |
} |
|
|
2076 |
} |
|
|
2077 |
} |
|
|
2078 |
} |
|
|
2079 |
|
|
|
2080 |
return ret || []; |
|
|
2081 |
}, |
|
|
2082 |
|
|
|
2083 |
_regexCache: {}, |
|
|
2084 |
|
|
|
2085 |
_re: { |
|
|
2086 |
attr: /(\[.*\])/g, |
|
|
2087 |
pseudos: /:([\-\w]+(?:\(?:['"]?(.+)['"]?\)))*/i |
|
|
2088 |
}, |
|
|
2089 |
|
|
|
2090 |
/** |
|
|
2091 |
* Mapping of shorthand tokens to corresponding attribute selector |
|
|
2092 |
* @property shorthand |
|
|
2093 |
* @type object |
|
|
2094 |
*/ |
|
|
2095 |
shorthand: { |
|
|
2096 |
'\\#(-?[_a-z]+[-\\w]*)': '[id=$1]', |
|
|
2097 |
'\\.(-?[_a-z]+[-\\w]*)': '[className~=$1]' |
|
|
2098 |
}, |
|
|
2099 |
|
|
|
2100 |
/** |
|
|
2101 |
* List of operators and corresponding boolean functions. |
|
|
2102 |
* These functions are passed the attribute and the current node's value of the attribute. |
|
|
2103 |
* @property operators |
|
|
2104 |
* @type object |
|
|
2105 |
*/ |
|
|
2106 |
operators: { |
|
|
2107 |
'': function(node, attr) { return Y.DOM.getAttribute(node, attr) !== ''; }, // Just test for existence of attribute |
|
|
2108 |
//'': '.+', |
|
|
2109 |
//'=': '^{val}$', // equality |
|
|
2110 |
'~=': '(?:^|\\s+){val}(?:\\s+|$)', // space-delimited |
|
|
2111 |
'|=': '^{val}-?' // optional hyphen-delimited |
|
|
2112 |
}, |
|
|
2113 |
|
|
|
2114 |
pseudos: { |
|
|
2115 |
'first-child': function(node) { |
|
|
2116 |
return Y.Selector._children(node[PARENT_NODE])[0] === node; |
|
|
2117 |
} |
|
|
2118 |
}, |
|
|
2119 |
|
|
|
2120 |
_bruteQuery: function(selector, root, firstOnly) { |
|
|
2121 |
var ret = [], |
|
|
2122 |
nodes = [], |
|
|
2123 |
tokens = Selector._tokenize(selector), |
|
|
2124 |
token = tokens[tokens.length - 1], |
|
|
2125 |
rootDoc = Y.DOM._getDoc(root), |
|
|
2126 |
id, |
|
|
2127 |
className, |
|
|
2128 |
tagName; |
|
|
2129 |
|
|
|
2130 |
|
|
|
2131 |
// if we have an initial ID, set to root when in document |
|
|
2132 |
if (tokens[0] && rootDoc === root && |
|
|
2133 |
(id = tokens[0].id) && |
|
|
2134 |
rootDoc.getElementById(id)) { |
|
|
2135 |
root = rootDoc.getElementById(id); |
|
|
2136 |
} |
|
|
2137 |
|
|
|
2138 |
if (token) { |
|
|
2139 |
// prefilter nodes |
|
|
2140 |
id = token.id; |
|
|
2141 |
className = token.className; |
|
|
2142 |
tagName = token.tagName || '*'; |
|
|
2143 |
|
|
|
2144 |
// try ID first |
|
|
2145 |
if (id) { |
|
|
2146 |
if (rootDoc.getElementById(id)) { // if in document |
|
|
2147 |
nodes = [rootDoc.getElementById(id)]; // TODO: DOM.byId? |
|
|
2148 |
} |
|
|
2149 |
// try className if supported |
|
|
2150 |
} else if (className) { |
|
|
2151 |
nodes = root.getElementsByClassName(className); |
|
|
2152 |
} else if (tagName) { // default to tagName |
|
|
2153 |
nodes = root.getElementsByTagName(tagName || '*'); |
|
|
2154 |
} |
|
|
2155 |
|
|
|
2156 |
if (nodes.length) { |
|
|
2157 |
ret = Selector._filterNodes(nodes, tokens, firstOnly); |
|
|
2158 |
} |
|
|
2159 |
} |
|
|
2160 |
|
|
|
2161 |
return ret; |
|
|
2162 |
}, |
|
|
2163 |
|
|
|
2164 |
_filterNodes: function(nodes, tokens, firstOnly) { |
|
|
2165 |
var i = 0, |
|
|
2166 |
j, |
|
|
2167 |
len = tokens.length, |
|
|
2168 |
n = len - 1, |
|
|
2169 |
result = [], |
|
|
2170 |
node = nodes[0], |
|
|
2171 |
tmpNode = node, |
|
|
2172 |
getters = Y.Selector.getters, |
|
|
2173 |
operator, |
|
|
2174 |
combinator, |
|
|
2175 |
token, |
|
|
2176 |
path, |
|
|
2177 |
pass, |
|
|
2178 |
//FUNCTION = 'function', |
|
|
2179 |
value, |
|
|
2180 |
tests, |
|
|
2181 |
test; |
|
|
2182 |
|
|
|
2183 |
//do { |
|
|
2184 |
for (i = 0; (tmpNode = node = nodes[i++]);) { |
|
|
2185 |
n = len - 1; |
|
|
2186 |
path = null; |
|
|
2187 |
|
|
|
2188 |
testLoop: |
|
|
2189 |
while (tmpNode && tmpNode.tagName) { |
|
|
2190 |
token = tokens[n]; |
|
|
2191 |
tests = token.tests; |
|
|
2192 |
j = tests.length; |
|
|
2193 |
if (j && !pass) { |
|
|
2194 |
while ((test = tests[--j])) { |
|
|
2195 |
operator = test[1]; |
|
|
2196 |
if (getters[test[0]]) { |
|
|
2197 |
value = getters[test[0]](tmpNode, test[0]); |
|
|
2198 |
} else { |
|
|
2199 |
value = tmpNode[test[0]]; |
|
|
2200 |
// use getAttribute for non-standard attributes |
|
|
2201 |
if (value === undefined && tmpNode.getAttribute) { |
|
|
2202 |
value = tmpNode.getAttribute(test[0]); |
|
|
2203 |
} |
|
|
2204 |
} |
|
|
2205 |
|
|
|
2206 |
if ((operator === '=' && value !== test[2]) || // fast path for equality |
|
|
2207 |
(operator.test && !operator.test(value)) || // regex test |
|
|
2208 |
(operator.call && !operator(tmpNode, test[0]))) { // function test |
|
|
2209 |
|
|
|
2210 |
// skip non element nodes or non-matching tags |
|
|
2211 |
if ((tmpNode = tmpNode[path])) { |
|
|
2212 |
while (tmpNode && |
|
|
2213 |
(!tmpNode.tagName || |
|
|
2214 |
(token.tagName && token.tagName !== tmpNode.tagName)) |
|
|
2215 |
) { |
|
|
2216 |
tmpNode = tmpNode[path]; |
|
|
2217 |
} |
|
|
2218 |
} |
|
|
2219 |
continue testLoop; |
|
|
2220 |
} |
|
|
2221 |
} |
|
|
2222 |
} |
|
|
2223 |
|
|
|
2224 |
n--; // move to next token |
|
|
2225 |
// now that we've passed the test, move up the tree by combinator |
|
|
2226 |
if (!pass && (combinator = token.combinator)) { |
|
|
2227 |
path = combinator.axis; |
|
|
2228 |
tmpNode = tmpNode[path]; |
|
|
2229 |
|
|
|
2230 |
// skip non element nodes |
|
|
2231 |
while (tmpNode && !tmpNode.tagName) { |
|
|
2232 |
tmpNode = tmpNode[path]; |
|
|
2233 |
} |
|
|
2234 |
|
|
|
2235 |
if (combinator.direct) { // one pass only |
|
|
2236 |
path = null; |
|
|
2237 |
} |
|
|
2238 |
|
|
|
2239 |
} else { // success if we made it this far |
|
|
2240 |
result.push(node); |
|
|
2241 |
if (firstOnly) { |
|
|
2242 |
return result; |
|
|
2243 |
} |
|
|
2244 |
break; |
|
|
2245 |
} |
|
|
2246 |
} |
|
|
2247 |
}// while (tmpNode = node = nodes[++i]); |
|
|
2248 |
node = tmpNode = null; |
|
|
2249 |
return result; |
|
|
2250 |
}, |
|
|
2251 |
|
|
|
2252 |
_getRegExp: function(str, flags) { |
|
|
2253 |
var regexCache = Selector._regexCache; |
|
|
2254 |
flags = flags || ''; |
|
|
2255 |
if (!regexCache[str + flags]) { |
|
|
2256 |
regexCache[str + flags] = new RegExp(str, flags); |
|
|
2257 |
} |
|
|
2258 |
return regexCache[str + flags]; |
|
|
2259 |
}, |
|
|
2260 |
|
|
|
2261 |
combinators: { |
|
|
2262 |
' ': { |
|
|
2263 |
axis: 'parentNode' |
|
|
2264 |
}, |
|
|
2265 |
|
|
|
2266 |
'>': { |
|
|
2267 |
axis: 'parentNode', |
|
|
2268 |
direct: true |
|
|
2269 |
}, |
|
|
2270 |
|
|
|
2271 |
|
|
|
2272 |
'+': { |
|
|
2273 |
axis: 'previousSibling', |
|
|
2274 |
direct: true |
|
|
2275 |
} |
|
|
2276 |
}, |
|
|
2277 |
|
|
|
2278 |
_parsers: [ |
|
|
2279 |
{ |
|
|
2280 |
name: ATTRIBUTES, |
|
|
2281 |
re: /^\[([a-z]+\w*)+([~\|\^\$\*!=]=?)?['"]?([^\]]*?)['"]?\]/i, |
|
|
2282 |
fn: function(match, token) { |
|
|
2283 |
var operator = match[2] || '', |
|
|
2284 |
operators = Y.Selector.operators, |
|
|
2285 |
test; |
|
|
2286 |
|
|
|
2287 |
// add prefiltering for ID and CLASS |
|
|
2288 |
if ((match[1] === 'id' && operator === '=') || |
|
|
2289 |
(match[1] === 'className' && |
|
|
2290 |
document.getElementsByClassName && |
|
|
2291 |
(operator === '~=' || operator === '='))) { |
|
|
2292 |
token.prefilter = match[1]; |
|
|
2293 |
token[match[1]] = match[3]; |
|
|
2294 |
} |
|
|
2295 |
|
|
|
2296 |
// add tests |
|
|
2297 |
if (operator in operators) { |
|
|
2298 |
test = operators[operator]; |
|
|
2299 |
if (typeof test === 'string') { |
|
|
2300 |
test = Y.Selector._getRegExp(test.replace('{val}', match[3])); |
|
|
2301 |
} |
|
|
2302 |
match[2] = test; |
|
|
2303 |
} |
|
|
2304 |
if (!token.last || token.prefilter !== match[1]) { |
|
|
2305 |
return match.slice(1); |
|
|
2306 |
} |
|
|
2307 |
} |
|
|
2308 |
|
|
|
2309 |
}, |
|
|
2310 |
{ |
|
|
2311 |
name: TAG_NAME, |
|
|
2312 |
re: /^((?:-?[_a-z]+[\w-]*)|\*)/i, |
|
|
2313 |
fn: function(match, token) { |
|
|
2314 |
var tag = match[1].toUpperCase(); |
|
|
2315 |
token.tagName = tag; |
|
|
2316 |
|
|
|
2317 |
if (tag !== '*' && (!token.last || token.prefilter)) { |
|
|
2318 |
return [TAG_NAME, '=', tag]; |
|
|
2319 |
} |
|
|
2320 |
if (!token.prefilter) { |
|
|
2321 |
token.prefilter = 'tagName'; |
|
|
2322 |
} |
|
|
2323 |
} |
|
|
2324 |
}, |
|
|
2325 |
{ |
|
|
2326 |
name: COMBINATOR, |
|
|
2327 |
re: /^\s*([>+~]|\s)\s*/, |
|
|
2328 |
fn: function(match, token) { |
|
|
2329 |
} |
|
|
2330 |
}, |
|
|
2331 |
{ |
|
|
2332 |
name: PSEUDOS, |
|
|
2333 |
re: /^:([\-\w]+)(?:\(['"]?(.+)['"]?\))*/i, |
|
|
2334 |
fn: function(match, token) { |
|
|
2335 |
var test = Selector[PSEUDOS][match[1]]; |
|
|
2336 |
if (test) { // reorder match array |
|
|
2337 |
return [match[2], test]; |
|
|
2338 |
} else { // selector token not supported (possibly missing CSS3 module) |
|
|
2339 |
return false; |
|
|
2340 |
} |
|
|
2341 |
} |
|
|
2342 |
} |
|
|
2343 |
], |
|
|
2344 |
|
|
|
2345 |
_getToken: function(token) { |
|
|
2346 |
return { |
|
|
2347 |
tagName: null, |
|
|
2348 |
id: null, |
|
|
2349 |
className: null, |
|
|
2350 |
attributes: {}, |
|
|
2351 |
combinator: null, |
|
|
2352 |
tests: [] |
|
|
2353 |
}; |
|
|
2354 |
}, |
|
|
2355 |
|
|
|
2356 |
/** |
|
|
2357 |
Break selector into token units per simple selector. |
|
|
2358 |
Combinator is attached to the previous token. |
|
|
2359 |
*/ |
|
|
2360 |
_tokenize: function(selector) { |
|
|
2361 |
selector = selector || ''; |
|
|
2362 |
selector = Selector._replaceShorthand(Y.Lang.trim(selector)); |
|
|
2363 |
var token = Selector._getToken(), // one token per simple selector (left selector holds combinator) |
|
|
2364 |
query = selector, // original query for debug report |
|
|
2365 |
tokens = [], // array of tokens |
|
|
2366 |
found = false, // whether or not any matches were found this pass |
|
|
2367 |
match, // the regex match |
|
|
2368 |
test, |
|
|
2369 |
i, parser; |
|
|
2370 |
|
|
|
2371 |
/* |
|
|
2372 |
Search for selector patterns, store, and strip them from the selector string |
|
|
2373 |
until no patterns match (invalid selector) or we run out of chars. |
|
|
2374 |
|
|
|
2375 |
Multiple attributes and pseudos are allowed, in any order. |
|
|
2376 |
for example: |
|
|
2377 |
'form:first-child[type=button]:not(button)[lang|=en]' |
|
|
2378 |
*/ |
|
|
2379 |
outer: |
|
|
2380 |
do { |
|
|
2381 |
found = false; // reset after full pass |
|
|
2382 |
for (i = 0; (parser = Selector._parsers[i++]);) { |
|
|
2383 |
if ( (match = parser.re.exec(selector)) ) { // note assignment |
|
|
2384 |
if (parser !== COMBINATOR ) { |
|
|
2385 |
token.selector = selector; |
|
|
2386 |
} |
|
|
2387 |
selector = selector.replace(match[0], ''); // strip current match from selector |
|
|
2388 |
if (!selector.length) { |
|
|
2389 |
token.last = true; |
|
|
2390 |
} |
|
|
2391 |
|
|
|
2392 |
if (Selector._attrFilters[match[1]]) { // convert class to className, etc. |
|
|
2393 |
match[1] = Selector._attrFilters[match[1]]; |
|
|
2394 |
} |
|
|
2395 |
|
|
|
2396 |
test = parser.fn(match, token); |
|
|
2397 |
if (test === false) { // selector not supported |
|
|
2398 |
found = false; |
|
|
2399 |
break outer; |
|
|
2400 |
} else if (test) { |
|
|
2401 |
token.tests.push(test); |
|
|
2402 |
} |
|
|
2403 |
|
|
|
2404 |
if (!selector.length || parser.name === COMBINATOR) { |
|
|
2405 |
tokens.push(token); |
|
|
2406 |
token = Selector._getToken(token); |
|
|
2407 |
if (parser.name === COMBINATOR) { |
|
|
2408 |
token.combinator = Y.Selector.combinators[match[1]]; |
|
|
2409 |
} |
|
|
2410 |
} |
|
|
2411 |
found = true; |
|
|
2412 |
} |
|
|
2413 |
} |
|
|
2414 |
} while (found && selector.length); |
|
|
2415 |
|
|
|
2416 |
if (!found || selector.length) { // not fully parsed |
|
|
2417 |
Y.log('query: ' + query + ' contains unsupported token in: ' + selector, 'warn', 'Selector'); |
|
|
2418 |
tokens = []; |
|
|
2419 |
} |
|
|
2420 |
return tokens; |
|
|
2421 |
}, |
|
|
2422 |
|
|
|
2423 |
_replaceShorthand: function(selector) { |
|
|
2424 |
var shorthand = Selector.shorthand, |
|
|
2425 |
attrs = selector.match(Selector._re.attr), // pull attributes to avoid false pos on "." and "#" |
|
|
2426 |
pseudos = selector.match(Selector._re.pseudos), // pull attributes to avoid false pos on "." and "#" |
|
|
2427 |
re, i, len; |
|
|
2428 |
|
|
|
2429 |
if (pseudos) { |
|
|
2430 |
selector = selector.replace(Selector._re.pseudos, '!!REPLACED_PSEUDO!!'); |
|
|
2431 |
} |
|
|
2432 |
|
|
|
2433 |
if (attrs) { |
|
|
2434 |
selector = selector.replace(Selector._re.attr, '!!REPLACED_ATTRIBUTE!!'); |
|
|
2435 |
} |
|
|
2436 |
|
|
|
2437 |
for (re in shorthand) { |
|
|
2438 |
if (shorthand.hasOwnProperty(re)) { |
|
|
2439 |
selector = selector.replace(Selector._getRegExp(re, 'gi'), shorthand[re]); |
|
|
2440 |
} |
|
|
2441 |
} |
|
|
2442 |
|
|
|
2443 |
if (attrs) { |
|
|
2444 |
for (i = 0, len = attrs.length; i < len; ++i) { |
|
|
2445 |
selector = selector.replace('!!REPLACED_ATTRIBUTE!!', attrs[i]); |
|
|
2446 |
} |
|
|
2447 |
} |
|
|
2448 |
if (pseudos) { |
|
|
2449 |
for (i = 0, len = pseudos.length; i < len; ++i) { |
|
|
2450 |
selector = selector.replace('!!REPLACED_PSEUDO!!', pseudos[i]); |
|
|
2451 |
} |
|
|
2452 |
} |
|
|
2453 |
return selector; |
|
|
2454 |
}, |
|
|
2455 |
|
|
|
2456 |
_attrFilters: { |
|
|
2457 |
'class': 'className', |
|
|
2458 |
'for': 'htmlFor' |
|
|
2459 |
}, |
|
|
2460 |
|
|
|
2461 |
getters: { |
|
|
2462 |
href: function(node, attr) { |
|
|
2463 |
return Y.DOM.getAttribute(node, attr); |
|
|
2464 |
} |
|
|
2465 |
} |
|
|
2466 |
}; |
|
|
2467 |
|
|
|
2468 |
Y.mix(Y.Selector, SelectorCSS2, true); |
|
|
2469 |
Y.Selector.getters.src = Y.Selector.getters.rel = Y.Selector.getters.href; |
|
|
2470 |
|
|
|
2471 |
// IE wants class with native queries |
|
|
2472 |
if (Y.Selector.useNative && document.querySelector) { |
|
|
2473 |
Y.Selector.shorthand['\\.(-?[_a-z]+[-\\w]*)'] = '[class~=$1]'; |
|
|
2474 |
} |
|
|
2475 |
|
|
|
2476 |
|
|
|
2477 |
|
|
|
2478 |
}, '3.0.0' ,{requires:['selector-native']}); |
|
|
2479 |
|
|
|
2480 |
|
|
|
2481 |
YUI.add('selector', function(Y){}, '3.0.0' ,{use:['selector-native', 'selector-css2']}); |
|
|
2482 |
|
|
|
2483 |
|
|
|
2484 |
|
|
|
2485 |
YUI.add('dom', function(Y){}, '3.0.0' ,{use:['dom-base', 'dom-style', 'dom-screen', 'selector']}); |
|
|
2486 |
|