Diffstat (limited to 'frontend/gamma/js/Clipperz/YUI') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/YUI/DomHelper.js | 481 | ||||
-rw-r--r-- | frontend/gamma/js/Clipperz/YUI/DomQuery.js | 714 | ||||
-rw-r--r-- | frontend/gamma/js/Clipperz/YUI/Utils.js | 98 |
3 files changed, 1293 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/YUI/DomHelper.js b/frontend/gamma/js/Clipperz/YUI/DomHelper.js new file mode 100644 index 0000000..dbd8c93 --- a/dev/null +++ b/frontend/gamma/js/Clipperz/YUI/DomHelper.js | |||
@@ -0,0 +1,481 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz's Javascript Crypto Library. | ||
6 | Javascript Crypto Library provides web developers with an extensive | ||
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | ||
11 | refer to http://www.clipperz.com | ||
12 | |||
13 | * Javascript Crypto Library is free software: you can redistribute | ||
14 | it and/or modify it under the terms of the GNU Affero General Public | ||
15 | License as published by the Free Software Foundation, either version | ||
16 | 3 of the License, or (at your option) any later version. | ||
17 | |||
18 | * Javascript Crypto Library is distributed in the hope that it will | ||
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
21 | See the GNU Affero General Public License for more details. | ||
22 | |||
23 | * You should have received a copy of the GNU Affero General Public | ||
24 | License along with Javascript Crypto Library. If not, see | ||
25 | <http://www.gnu.org/licenses/>. | ||
26 | |||
27 | */ | ||
28 | |||
29 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | ||
30 | if (typeof(Clipperz.YUI) == 'undefined') { Clipperz.YUI = {}; } | ||
31 | |||
32 | |||
33 | /** | ||
34 | * @class Clipperz.ext.DomHelper | ||
35 | * Utility class for working with DOM and/or Templates. It transparently supports using HTML fragments or DOM. | ||
36 | * For more information see <a href="http://www.jackslocum.com/yui/2006/10/06/domhelper-create-elements-using-dom-html-fragments-or-templates/">this blog post with examples</a>. | ||
37 | * @singleton | ||
38 | */ | ||
39 | Clipperz.YUI.DomHelper = new function(){ | ||
40 | /**@private*/ | ||
41 | var d = document; | ||
42 | var tempTableEl = null; | ||
43 | /** True to force the use of DOM instead of html fragments @type Boolean */ | ||
44 | this.useDom = false; | ||
45 | var emptyTags = /^(?:base|basefont|br|frame|hr|img|input|isindex|link|meta|nextid|range|spacer|wbr|audioscope|area|param|keygen|col|limittext|spot|tab|over|right|left|choose|atop|of)$/i; | ||
46 | /** | ||
47 | * Applies a style specification to an element | ||
48 | * @param {String/HTMLElement} el The element to apply styles to | ||
49 | * @param {String/Object/Function} styles A style specification string eg "width:100px", or object in the form {width:"100px"}, or | ||
50 | * a function which returns such a specification. | ||
51 | */ | ||
52 | this.applyStyles = function(el, styles){ | ||
53 | if(styles){ | ||
54 | var D = YAHOO.util.Dom; | ||
55 | if (typeof styles == "string"){ | ||
56 | var re = /\s?([a-z\-]*)\:([^;]*);?/gi; | ||
57 | var matches; | ||
58 | while ((matches = re.exec(styles)) != null){ | ||
59 | D.setStyle(el, matches[1], matches[2]); | ||
60 | } | ||
61 | }else if (typeof styles == "object"){ | ||
62 | for (var style in styles){ | ||
63 | D.setStyle(el, style, styles[style]); | ||
64 | } | ||
65 | }else if (typeof styles == "function"){ | ||
66 | Clipperz.YUI.DomHelper.applyStyles(el, styles.call()); | ||
67 | } | ||
68 | } | ||
69 | }; | ||
70 | |||
71 | // build as innerHTML where available | ||
72 | /** @ignore */ | ||
73 | var createHtml = function(o){ | ||
74 | var b = ''; | ||
75 | |||
76 | if(typeof(o['html']) != 'undefined') { | ||
77 | o['html'] = Clipperz.Base.sanitizeString(o['html']); | ||
78 | } else if (typeof(o['htmlString']) != 'undefined') { | ||
79 | o['html'] = o['htmlString']; | ||
80 | delete o.htmlString; | ||
81 | } | ||
82 | |||
83 | if (MochiKit.Base.isArrayLike(o)) { | ||
84 | for (var i = 0, l = o.length; i < l; i++) { | ||
85 | b += createHtml(o[i]); | ||
86 | } | ||
87 | return b; | ||
88 | } | ||
89 | |||
90 | b += '<' + o.tag; | ||
91 | for(var attr in o){ | ||
92 | if(attr == 'tag' || attr == 'children' || attr == 'html' || typeof o[attr] == 'function') continue; | ||
93 | if(attr == 'style'){ | ||
94 | var s = o['style']; | ||
95 | if(typeof s == 'function'){ | ||
96 | s = s.call(); | ||
97 | } | ||
98 | if(typeof s == 'string'){ | ||
99 | b += ' style="' + s + '"'; | ||
100 | }else if(typeof s == 'object'){ | ||
101 | b += ' style="'; | ||
102 | for(var key in s){ | ||
103 | if(typeof s[key] != 'function'){ | ||
104 | b += key + ':' + s[key] + ';'; | ||
105 | } | ||
106 | } | ||
107 | b += '"'; | ||
108 | } | ||
109 | }else{ | ||
110 | if(attr == 'cls'){ | ||
111 | b += ' class="' + o['cls'] + '"'; | ||
112 | }else if(attr == 'htmlFor'){ | ||
113 | b += ' for="' + o['htmlFor'] + '"'; | ||
114 | }else{ | ||
115 | b += ' ' + attr + '="' + o[attr] + '"'; | ||
116 | } | ||
117 | } | ||
118 | } | ||
119 | if(emptyTags.test(o.tag)){ | ||
120 | b += ' />'; | ||
121 | }else{ | ||
122 | b += '>'; | ||
123 | if(o.children){ | ||
124 | for(var i = 0, len = o.children.length; i < len; i++) { | ||
125 | b += createHtml(o.children[i], b); | ||
126 | } | ||
127 | } | ||
128 | if(o.html){ | ||
129 | b += o.html; | ||
130 | } | ||
131 | b += '</' + o.tag + '>'; | ||
132 | } | ||
133 | return b; | ||
134 | } | ||
135 | |||
136 | // build as dom | ||
137 | /** @ignore */ | ||
138 | var createDom = function(o, parentNode){ | ||
139 | var el = d.createElement(o.tag); | ||
140 | var useSet = el.setAttribute ? true : false; // In IE some elements don't have setAttribute | ||
141 | for(var attr in o){ | ||
142 | if(attr == 'tag' || attr == 'children' || attr == 'html' || attr == 'style' || typeof o[attr] == 'function') continue; | ||
143 | if(attr=='cls'){ | ||
144 | el.className = o['cls']; | ||
145 | }else{ | ||
146 | if(useSet) el.setAttribute(attr, o[attr]); | ||
147 | else el[attr] = o[attr]; | ||
148 | } | ||
149 | } | ||
150 | Clipperz.YUI.DomHelper.applyStyles(el, o.style); | ||
151 | if(o.children){ | ||
152 | for(var i = 0, len = o.children.length; i < len; i++) { | ||
153 | createDom(o.children[i], el); | ||
154 | } | ||
155 | } | ||
156 | if(o.html){ | ||
157 | el.innerHTML = o.html; | ||
158 | } | ||
159 | if(parentNode){ | ||
160 | parentNode.appendChild(el); | ||
161 | } | ||
162 | return el; | ||
163 | }; | ||
164 | |||
165 | /** | ||
166 | * @ignore | ||
167 | * Nasty code for IE's broken table implementation | ||
168 | */ | ||
169 | var insertIntoTable = function(tag, where, el, html){ | ||
170 | if(!tempTableEl){ | ||
171 | tempTableEl = document.createElement('div'); | ||
172 | } | ||
173 | var nodes; | ||
174 | if(tag == 'table' || tag == 'tbody'){ | ||
175 | tempTableEl.innerHTML = '<table><tbody>'+html+'</tbody></table>'; | ||
176 | nodes = tempTableEl.firstChild.firstChild.childNodes; | ||
177 | }else{ | ||
178 | tempTableEl.innerHTML = '<table><tbody><tr>'+html+'</tr></tbody></table>'; | ||
179 | nodes = tempTableEl.firstChild.firstChild.firstChild.childNodes; | ||
180 | } | ||
181 | if (where == 'beforebegin') { | ||
182 | nodes.reverse(); | ||
183 | // el.parentNode.insertBefore(node, el); | ||
184 | MochiKit.Base.map(function(aNode) {el.parentNode.insertBefore(aNode, el)}, nodes); | ||
185 | } else if (where == 'afterbegin') { | ||
186 | nodes.reverse(); | ||
187 | // el.insertBefore(node, el.firstChild); | ||
188 | MochiKit.Base.map(function(aNode) {el.insertBefore(aNode, el.firstChild)}, nodes); | ||
189 | } else if (where == 'beforeend') { | ||
190 | // el.appendChild(node); | ||
191 | MochiKit.Base.map(function(aNode) {el.appendChild(aNode)}, nodes); | ||
192 | } else if (where == 'afterend') { | ||
193 | // el.parentNode.insertBefore(node, el.nextSibling); | ||
194 | MochiKit.Base.map(function(aNode) {el.parentNode.insertBefore(aNode, el.nextSibling)}, nodes); | ||
195 | } | ||
196 | |||
197 | return nodes; | ||
198 | } | ||
199 | |||
200 | /** | ||
201 | * Inserts an HTML fragment into the Dom | ||
202 | * @param {String} where Where to insert the html in relation to el - beforeBegin, afterBegin, beforeEnd, afterEnd. | ||
203 | * @param {HTMLElement} el The context element | ||
204 | * @param {String} html The HTML fragmenet | ||
205 | * @return {HTMLElement} The new node | ||
206 | */ | ||
207 | this.insertHtml = function(where, el, html){ | ||
208 | where = where.toLowerCase(); | ||
209 | // if(el.insertAdjacentHTML){ | ||
210 | if(Clipperz_IEisBroken){ | ||
211 | var tag = el.tagName.toLowerCase(); | ||
212 | if(tag == 'table' || tag == 'tbody' || tag == 'tr'){ | ||
213 | return insertIntoTable(tag, where, el, html); | ||
214 | } | ||
215 | switch(where){ | ||
216 | case 'beforebegin': | ||
217 | el.insertAdjacentHTML(where, html); | ||
218 | return el.previousSibling; | ||
219 | case 'afterbegin': | ||
220 | el.insertAdjacentHTML(where, html); | ||
221 | return el.firstChild; | ||
222 | case 'beforeend': | ||
223 | el.insertAdjacentHTML(where, html); | ||
224 | return el.lastChild; | ||
225 | case 'afterend': | ||
226 | el.insertAdjacentHTML(where, html); | ||
227 | return el.nextSibling; | ||
228 | } | ||
229 | throw 'Illegal insertion point -> "' + where + '"'; | ||
230 | } | ||
231 | var range = el.ownerDocument.createRange(); | ||
232 | var frag; | ||
233 | switch(where){ | ||
234 | case 'beforebegin': | ||
235 | range.setStartBefore(el); | ||
236 | frag = range.createContextualFragment(html); | ||
237 | el.parentNode.insertBefore(frag, el); | ||
238 | return el.previousSibling; | ||
239 | case 'afterbegin': | ||
240 | if(el.firstChild){ // faster | ||
241 | range.setStartBefore(el.firstChild); | ||
242 | }else{ | ||
243 | range.selectNodeContents(el); | ||
244 | range.collapse(true); | ||
245 | } | ||
246 | frag = range.createContextualFragment(html); | ||
247 | el.insertBefore(frag, el.firstChild); | ||
248 | return el.firstChild; | ||
249 | case 'beforeend': | ||
250 | if(el.lastChild){ | ||
251 | range.setStartAfter(el.lastChild); // faster | ||
252 | }else{ | ||
253 | range.selectNodeContents(el); | ||
254 | range.collapse(false); | ||
255 | } | ||
256 | frag = range.createContextualFragment(html); | ||
257 | el.appendChild(frag); | ||
258 | return el.lastChild; | ||
259 | case 'afterend': | ||
260 | range.setStartAfter(el); | ||
261 | frag = range.createContextualFragment(html); | ||
262 | el.parentNode.insertBefore(frag, el.nextSibling); | ||
263 | return el.nextSibling; | ||
264 | } | ||
265 | throw 'Illegal insertion point -> "' + where + '"'; | ||
266 | }; | ||
267 | |||
268 | /** | ||
269 | * Creates new Dom element(s) and inserts them before el | ||
270 | * @param {String/HTMLElement/Element} el The context element | ||
271 | * @param {Object} o The Dom object spec (and children) | ||
272 | * @param {<i>Boolean</i>} returnElement (optional) true to return a YAHOO.Element | ||
273 | * @return {HTMLElement} The new node | ||
274 | */ | ||
275 | this.insertBefore = function(el, o, returnElement){ | ||
276 | el = el.dom ? el.dom : YAHOO.util.Dom.get(el); | ||
277 | var newNode; | ||
278 | if(this.useDom){ | ||
279 | newNode = createDom(o, null); | ||
280 | el.parentNode.insertBefore(newNode, el); | ||
281 | }else{ | ||
282 | var html = createHtml(o); | ||
283 | newNode = this.insertHtml('beforeBegin', el, html); | ||
284 | } | ||
285 | return returnElement ? YAHOO.Element.get(newNode, true) : newNode; | ||
286 | }; | ||
287 | |||
288 | /** | ||
289 | * Creates new Dom element(s) and inserts them after el | ||
290 | * @param {String/HTMLElement/Element} el The context element | ||
291 | * @param {Object} o The Dom object spec (and children) | ||
292 | * @param {<i>Boolean</i>} returnElement (optional) true to return a YAHOO.Element | ||
293 | * @return {HTMLElement} The new node | ||
294 | */ | ||
295 | this.insertAfter = function(el, o, returnElement){ | ||
296 | el = el.dom ? el.dom : YAHOO.util.Dom.get(el); | ||
297 | var newNode; | ||
298 | if(this.useDom){ | ||
299 | newNode = createDom(o, null); | ||
300 | el.parentNode.insertBefore(newNode, el.nextSibling); | ||
301 | }else{ | ||
302 | var html = createHtml(o); | ||
303 | newNode = this.insertHtml('afterEnd', el, html); | ||
304 | } | ||
305 | return returnElement ? YAHOO.Element.get(newNode, true) : newNode; | ||
306 | }; | ||
307 | |||
308 | /** | ||
309 | * Creates new Dom element(s) and appends them to el | ||
310 | * @param {String/HTMLElement/Element} el The context element | ||
311 | * @param {Object} o The Dom object spec (and children) | ||
312 | * @param {<i>Boolean</i>} returnElement (optional) true to return a YAHOO.Element | ||
313 | * @return {HTMLElement} The new node | ||
314 | */ | ||
315 | this.append = function(el, o, returnElement){ | ||
316 | el = el.dom ? el.dom : YAHOO.util.Dom.get(el); | ||
317 | var newNode; | ||
318 | if(this.useDom){ | ||
319 | newNode = createDom(o, null); | ||
320 | el.appendChild(newNode); | ||
321 | }else{ | ||
322 | var html = createHtml(o); | ||
323 | newNode = this.insertHtml('beforeEnd', el, html); | ||
324 | } | ||
325 | return returnElement ? YAHOO.Element.get(newNode, true) : newNode; | ||
326 | }; | ||
327 | |||
328 | /** | ||
329 | * Creates new Dom element(s) and overwrites the contents of el with them | ||
330 | * @param {String/HTMLElement/Element} el The context element | ||
331 | * @param {Object} o The Dom object spec (and children) | ||
332 | * @param {<i>Boolean</i>} returnElement (optional) true to return a YAHOO.Element | ||
333 | * @return {HTMLElement} The new node | ||
334 | */ | ||
335 | this.overwrite = function(el, o, returnElement){ | ||
336 | el = el.dom ? el.dom : YAHOO.util.Dom.get(el); | ||
337 | el.innerHTML = createHtml(o); | ||
338 | return returnElement ? YAHOO.Element.get(el.firstChild, true) : el.firstChild; | ||
339 | }; | ||
340 | |||
341 | /** | ||
342 | * Creates a new Clipperz.YUI.DomHelper.Template from the Dom object spec | ||
343 | * @param {Object} o The Dom object spec (and children) | ||
344 | * @return {Clipperz.YUI.DomHelper.Template} The new template | ||
345 | */ | ||
346 | this.createTemplate = function(o){ | ||
347 | var html = createHtml(o); | ||
348 | return new Clipperz.YUI.DomHelper.Template(html); | ||
349 | }; | ||
350 | }(); | ||
351 | |||
352 | /** | ||
353 | * @class Clipperz.YUI.DomHelper.Template | ||
354 | * Represents an HTML fragment template. | ||
355 | * For more information see <a href="http://www.jackslocum.com/yui/2006/10/06/domhelper-create-elements-using-dom-html-fragments-or-templates/">this blog post with examples</a>. | ||
356 | * <br> | ||
357 | * <b>This class is also available as Clipperz.YUI.Template</b>. | ||
358 | * @constructor | ||
359 | * @param {String/Array} html The HTML fragment or an array of fragments to join('') or multiple arguments to join('') | ||
360 | */ | ||
361 | Clipperz.YUI.DomHelper.Template = function(html){ | ||
362 | if(html instanceof Array){ | ||
363 | html = html.join(''); | ||
364 | }else if(arguments.length > 1){ | ||
365 | html = Array.prototype.join.call(arguments, ''); | ||
366 | } | ||
367 | /**@private*/ | ||
368 | this.html = html; | ||
369 | }; | ||
370 | Clipperz.YUI.DomHelper.Template.prototype = { | ||
371 | /** | ||
372 | * Returns an HTML fragment of this template with the specified values applied | ||
373 | * @param {Object} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'}) | ||
374 | * @return {String} | ||
375 | */ | ||
376 | applyTemplate : function(values){ | ||
377 | if(this.compiled){ | ||
378 | return this.compiled(values); | ||
379 | } | ||
380 | var empty = ''; | ||
381 | var fn = function(match, index){ | ||
382 | if(typeof values[index] != 'undefined'){ | ||
383 | return values[index]; | ||
384 | }else{ | ||
385 | return empty; | ||
386 | } | ||
387 | } | ||
388 | return this.html.replace(this.re, fn); | ||
389 | }, | ||
390 | |||
391 | /** | ||
392 | * The regular expression used to match template variables | ||
393 | * @type RegExp | ||
394 | * @property | ||
395 | */ | ||
396 | re : /\{([\w|-]+)\}/g, | ||
397 | |||
398 | /** | ||
399 | * Compiles the template into an internal function, eliminating the RegEx overhead | ||
400 | */ | ||
401 | compile : function(){ | ||
402 | var body = ["this.compiled = function(values){ return ['"]; | ||
403 | body.push(this.html.replace(this.re, "', values['$1'], '")); | ||
404 | body.push("'].join('');};"); | ||
405 | eval(body.join('')); | ||
406 | return this; | ||
407 | }, | ||
408 | |||
409 | /** | ||
410 | * Applies the supplied values to the template and inserts the new node(s) before el | ||
411 | * @param {String/HTMLElement/Element} el The context element | ||
412 | * @param {Object} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'}) | ||
413 | * @param {<i>Boolean</i>} returnElement (optional) true to return a YAHOO.Element | ||
414 | * @return {HTMLElement} The new node | ||
415 | */ | ||
416 | insertBefore: function(el, values, returnElement){ | ||
417 | el = el.dom ? el.dom : YAHOO.util.Dom.get(el); | ||
418 | var newNode = Clipperz.YUI.DomHelper.insertHtml('beforeBegin', el, this.applyTemplate(values)); | ||
419 | return returnElement ? YAHOO.Element.get(newNode, true) : newNode; | ||
420 | }, | ||
421 | |||
422 | /** | ||
423 | * Applies the supplied values to the template and inserts the new node(s) after el | ||
424 | * @param {String/HTMLElement/Element} el The context element | ||
425 | * @param {Object} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'}) | ||
426 | * @param {<i>Boolean</i>} returnElement (optional) true to return a YAHOO.Element | ||
427 | * @return {HTMLElement} The new node | ||
428 | */ | ||
429 | insertAfter : function(el, values, returnElement){ | ||
430 | el = el.dom ? el.dom : YAHOO.util.Dom.get(el); | ||
431 | var newNode = Clipperz.YUI.DomHelper.insertHtml('afterEnd', el, this.applyTemplate(values)); | ||
432 | return returnElement ? YAHOO.Element.get(newNode, true) : newNode; | ||
433 | }, | ||
434 | |||
435 | /** | ||
436 | * Applies the supplied values to the template and append the new node(s) to el | ||
437 | * @param {String/HTMLElement/Element} el The context element | ||
438 | * @param {Object} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'}) | ||
439 | * @param {<i>Boolean</i>} returnElement (optional) true to return a YAHOO.Element | ||
440 | * @return {HTMLElement} The new node | ||
441 | */ | ||
442 | append : function(el, values, returnElement){ | ||
443 | var sanitizedValues; | ||
444 | var key; | ||
445 | |||
446 | // sanitizedValues = MochiKit.Base.map(sanitizedValues) | ||
447 | //console.log("values", values); | ||
448 | sanitizedValues = {}; | ||
449 | for (key in values) { | ||
450 | sanitizedValues[key] = Clipperz.Base.sanitizeString(values[key]); | ||
451 | } | ||
452 | //console.log("sanitizedValues", sanitizedValues); | ||
453 | // el = el.dom ? el.dom : YAHOO.util.Dom.get(el); | ||
454 | el = (typeof el == 'string') ? YAHOO.util.Dom.get(el) : el; | ||
455 | //Clipperz.log(this.applyTemplate(sanitizedValues)); | ||
456 | var newNode = Clipperz.YUI.DomHelper.insertHtml('beforeEnd', el, this.applyTemplate(sanitizedValues)); | ||
457 | // return returnElement ? YAHOO.Element.get(newNode, true) : newNode; | ||
458 | return newNode; | ||
459 | }, | ||
460 | |||
461 | /** | ||
462 | * Applies the supplied values to the template and overwrites the content of el with the new node(s) | ||
463 | * @param {String/HTMLElement/Element} el The context element | ||
464 | * @param {Object} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'}) | ||
465 | * @param {<i>Boolean</i>} returnElement (optional) true to return a YAHOO.Element | ||
466 | * @return {HTMLElement} The new node | ||
467 | */ | ||
468 | overwrite : function(el, values, returnElement){ | ||
469 | el = el.dom ? el.dom : YAHOO.util.Dom.get(el); | ||
470 | el.innerHTML = ''; | ||
471 | var newNode = Clipperz.YUI.DomHelper.insertHtml('beforeEnd', el, this.applyTemplate(values)); | ||
472 | return returnElement ? YAHOO.Element.get(newNode, true) : newNode; | ||
473 | } | ||
474 | }; | ||
475 | /** | ||
476 | * Alias for applyTemplate | ||
477 | * @method | ||
478 | */ | ||
479 | Clipperz.YUI.DomHelper.Template.prototype.apply = Clipperz.YUI.DomHelper.Template.prototype.applyTemplate; | ||
480 | |||
481 | Clipperz.YUI.Template = Clipperz.YUI.DomHelper.Template; | ||
diff --git a/frontend/gamma/js/Clipperz/YUI/DomQuery.js b/frontend/gamma/js/Clipperz/YUI/DomQuery.js new file mode 100644 index 0000000..4a143ab --- a/dev/null +++ b/frontend/gamma/js/Clipperz/YUI/DomQuery.js | |||
@@ -0,0 +1,714 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz's Javascript Crypto Library. | ||
6 | Javascript Crypto Library provides web developers with an extensive | ||
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | ||
11 | refer to http://www.clipperz.com | ||
12 | |||
13 | * Javascript Crypto Library is free software: you can redistribute | ||
14 | it and/or modify it under the terms of the GNU Affero General Public | ||
15 | License as published by the Free Software Foundation, either version | ||
16 | 3 of the License, or (at your option) any later version. | ||
17 | |||
18 | * Javascript Crypto Library is distributed in the hope that it will | ||
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
21 | See the GNU Affero General Public License for more details. | ||
22 | |||
23 | * You should have received a copy of the GNU Affero General Public | ||
24 | License along with Javascript Crypto Library. If not, see | ||
25 | <http://www.gnu.org/licenses/>. | ||
26 | |||
27 | */ | ||
28 | |||
29 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | ||
30 | if (typeof(Clipperz.YUI) == 'undefined') { Clipperz.YUI = {}; } | ||
31 | |||
32 | |||
33 | /* | ||
34 | * yui-ext 0.40 | ||
35 | * Copyright(c) 2006, Jack Slocum. | ||
36 | */ | ||
37 | |||
38 | /** | ||
39 | * @class Clipperz.YUI.DomQuery | ||
40 | * Provides high performance selector/xpath processing by compiling queries into reusable functions. | ||
41 | * New pseudo classes and matchers can be plugged. It works on HTML and XML documents (if a content node is passed in). | ||
42 | * @singleton | ||
43 | */ | ||
44 | Clipperz.YUI.DomQuery = function(){ | ||
45 | var cache = {}, simpleCache = {}, valueCache = {}; | ||
46 | var nonSpace = /\S/; | ||
47 | var trimRe = /^\s*(.*?)\s*$/; | ||
48 | var tplRe = /\{(\d+)\}/g; | ||
49 | var modeRe = /^(\s?[\/>]\s?|\s|$)/; | ||
50 | var clsRes = {}; | ||
51 | |||
52 | function child(p, index){ | ||
53 | var i = 0; | ||
54 | var n = p.firstChild; | ||
55 | while(n){ | ||
56 | if(n.nodeType == 1){ | ||
57 | i++; | ||
58 | if(i == index){ | ||
59 | return n; | ||
60 | } | ||
61 | } | ||
62 | n = n.nextSibling; | ||
63 | } | ||
64 | return null; | ||
65 | }; | ||
66 | |||
67 | function next(d){ | ||
68 | var n = d.nextSibling; | ||
69 | while(n && n.nodeType != 1){ | ||
70 | n = n.nextSibling; | ||
71 | } | ||
72 | return n; | ||
73 | }; | ||
74 | |||
75 | function prev(d){ | ||
76 | var n = d.previousSibling; | ||
77 | while(n && n.nodeType != 1){ | ||
78 | n = n.previousSibling; | ||
79 | } | ||
80 | return n; | ||
81 | }; | ||
82 | |||
83 | function clean(d){ | ||
84 | var n = d.firstChild, ni = -1; | ||
85 | while(n){ | ||
86 | var nx = n.nextSibling; | ||
87 | if(n.nodeType == 3 && !nonSpace.test(n.nodeValue)){ | ||
88 | d.removeChild(n); | ||
89 | }else{ | ||
90 | n.nodeIndex = ++ni; | ||
91 | } | ||
92 | n = nx; | ||
93 | } | ||
94 | return this; | ||
95 | }; | ||
96 | |||
97 | function byClassName(c, a, v){ | ||
98 | if(!v){ | ||
99 | return c; | ||
100 | } | ||
101 | var re = clsRes[v]; | ||
102 | if(!re){ | ||
103 | re = new RegExp('(?:^|\\s)(?:' + v + ')(?:\\s|$)'); | ||
104 | clsRes[v] = re; | ||
105 | } | ||
106 | var r = []; | ||
107 | for(var i = 0, ci; ci = c[i]; i++){ | ||
108 | if(re.test(ci.className)){ | ||
109 | r[r.length] = ci; | ||
110 | } | ||
111 | } | ||
112 | return r; | ||
113 | }; | ||
114 | |||
115 | function convert(c){ | ||
116 | if(c.slice){ | ||
117 | return c; | ||
118 | } | ||
119 | var r = []; | ||
120 | for(var i = 0, l = c.length; i < l; i++){ | ||
121 | r[r.length] = c[i]; | ||
122 | } | ||
123 | return r; | ||
124 | }; | ||
125 | |||
126 | function attrValue(n, attr){ | ||
127 | if(!n.tagName && typeof n.length != 'undefined'){ | ||
128 | n = n[0]; | ||
129 | } | ||
130 | if(!n){ | ||
131 | return null; | ||
132 | } | ||
133 | if(attr == 'for'){ | ||
134 | return n.htmlFor; | ||
135 | } | ||
136 | if(attr == 'class' || attr == 'className'){ | ||
137 | return n.className; | ||
138 | } | ||
139 | return n.getAttribute(attr) || n[attr]; | ||
140 | |||
141 | }; | ||
142 | |||
143 | function getNodes(ns, mode, tagName){ | ||
144 | var result = [], cs; | ||
145 | if(!ns){ | ||
146 | return result; | ||
147 | } | ||
148 | mode = mode ? mode.replace(trimRe, '$1') : ''; | ||
149 | tagName = tagName || '*'; | ||
150 | if(ns.tagName || ns == document){ | ||
151 | ns = [ns]; | ||
152 | } | ||
153 | if(mode != '/' && mode != '>'){ | ||
154 | for(var i = 0, ni; ni = ns[i]; i++){ | ||
155 | cs = ni.getElementsByTagName(tagName); | ||
156 | result = concat(result, cs); | ||
157 | } | ||
158 | }else{ | ||
159 | for(var i = 0, ni; ni = ns[i]; i++){ | ||
160 | var cn = ni.getElementsByTagName(tagName); | ||
161 | for(var j = 0, cj; cj = cn[j]; j++){ | ||
162 | if(cj.parentNode == ni){ | ||
163 | result[result.length] = cj; | ||
164 | } | ||
165 | } | ||
166 | } | ||
167 | |||
168 | } | ||
169 | return result; | ||
170 | }; | ||
171 | |||
172 | function concat(a, b){ | ||
173 | if(b.slice){ | ||
174 | return a.concat(b); | ||
175 | } | ||
176 | for(var i = 0, l = b.length; i < l; i++){ | ||
177 | a[a.length] = b[i]; | ||
178 | } | ||
179 | return a; | ||
180 | } | ||
181 | |||
182 | function byTag(cs, tagName){ | ||
183 | if(cs.tagName || cs == document){ | ||
184 | cs = [cs]; | ||
185 | } | ||
186 | if(!tagName){ | ||
187 | return cs; | ||
188 | } | ||
189 | var r = []; tagName = tagName.toLowerCase(); | ||
190 | for(var i = 0, ci; ci = cs[i]; i++){ | ||
191 | if(ci.nodeType == 1 && ci.tagName.toLowerCase()==tagName){ | ||
192 | r[r.length] = ci; | ||
193 | } | ||
194 | } | ||
195 | return r; | ||
196 | }; | ||
197 | |||
198 | function byId(cs, attr, id){ | ||
199 | if(cs.tagName || cs == document){ | ||
200 | cs = [cs]; | ||
201 | } | ||
202 | if(!id){ | ||
203 | return cs; | ||
204 | } | ||
205 | var r = []; | ||
206 | for(var i = 0, l = cs.length; i < l; i++){ | ||
207 | var ci = cs[i]; | ||
208 | if(ci && ci.id == id){ | ||
209 | r[r.length] = ci; | ||
210 | } | ||
211 | } | ||
212 | return r; | ||
213 | }; | ||
214 | |||
215 | function byAttribute(cs, attr, value, op, custom){ | ||
216 | var r = [], st = custom=='{'; | ||
217 | var f = Clipperz.YUI.DomQuery.operators[op]; | ||
218 | for(var i = 0, l = cs.length; i < l; i++){ | ||
219 | var a; | ||
220 | if(st){ | ||
221 | a = Clipperz.YUI.DomQuery.getStyle(cs[i], attr); | ||
222 | } | ||
223 | else if(attr == 'class' || attr == 'className'){ | ||
224 | a = cs[i].className; | ||
225 | }else if(attr == 'for'){ | ||
226 | a = cs[i].htmlFor; | ||
227 | }else{ | ||
228 | a = cs[i].getAttribute(attr); | ||
229 | } | ||
230 | if((f && f(a, value)) || (!f && a)){ | ||
231 | r[r.length] = cs[i]; | ||
232 | } | ||
233 | } | ||
234 | return r; | ||
235 | }; | ||
236 | |||
237 | function byPseudo(cs, name, value){ | ||
238 | return Clipperz.YUI.DomQuery.pseudos[name](cs, value); | ||
239 | }; | ||
240 | |||
241 | // This is for IE MSXML which does not support expandos. | ||
242 | // IE runs the same speed using setAttribute, however FF slows way down | ||
243 | // and Safari completely fails so they need to continue to use expandos. | ||
244 | // Branched at load time for faster execution. | ||
245 | var isIE = window.ActiveXObject; | ||
246 | var addAttr = isIE ? | ||
247 | function(n, a, v){ | ||
248 | n.setAttribute(a, v); | ||
249 | } : | ||
250 | function(n, a, v){ | ||
251 | n[a] = v; | ||
252 | }; | ||
253 | var getAttr = isIE ? | ||
254 | function(n, a){ | ||
255 | return n.getAttribute(a); | ||
256 | } : | ||
257 | function(n, a){ | ||
258 | return n[a]; | ||
259 | }; | ||
260 | var clearAttr = isIE ? | ||
261 | function(n, a){ | ||
262 | n.removeAttribute(a); | ||
263 | } : | ||
264 | function(n, a, v){ | ||
265 | delete n[a]; | ||
266 | }; | ||
267 | |||
268 | function nodup(cs){ | ||
269 | if(!cs.length){ | ||
270 | return cs; | ||
271 | } | ||
272 | addAttr(cs[0], '_nodup', true); | ||
273 | var r = [cs[0]]; | ||
274 | for(var i = 1, len = cs.length; i < len; i++){ | ||
275 | var c = cs[i]; | ||
276 | if(!getAttr(c, '_nodup')){ | ||
277 | addAttr(c, '_nodup', true); | ||
278 | r[r.length] = c; | ||
279 | } | ||
280 | } | ||
281 | for(var i = 0, len = cs.length; i < len; i++){ | ||
282 | clearAttr(cs[i], '_nodup'); | ||
283 | } | ||
284 | return r; | ||
285 | } | ||
286 | |||
287 | function quickDiff(c1, c2){ | ||
288 | if(!c1.length){ | ||
289 | return c2; | ||
290 | } | ||
291 | for(var i = 0, len = c1.length; i < len; i++){ | ||
292 | addAttr(c1[i], '_qdiff', true); | ||
293 | } | ||
294 | var r = []; | ||
295 | for(var i = 0, len = c2.length; i < len; i++){ | ||
296 | if(!getAttr(c2[i], '_qdiff')){ | ||
297 | r[r.length] = c2[i]; | ||
298 | } | ||
299 | } | ||
300 | for(var i = 0, len = c1.length; i < len; i++){ | ||
301 | clearAttr(c1[i], '_qdiff'); | ||
302 | } | ||
303 | return r; | ||
304 | } | ||
305 | |||
306 | function quickId(ns, mode, root, id){ | ||
307 | if(ns == root){ | ||
308 | var d = root.ownerDocument || root; | ||
309 | return d.getElementById(id); | ||
310 | } | ||
311 | ns = getNodes(ns, mode, '*'); | ||
312 | return byId(ns, null, id); | ||
313 | } | ||
314 | |||
315 | return { | ||
316 | getStyle : function(el, name){ | ||
317 | return YAHOO.util.Dom.getStyle(el, name); | ||
318 | }, | ||
319 | /** | ||
320 | * Compiles a selector/xpath query into a reusable function. The returned function | ||
321 | * takes one parameter "root" (optional), which is the context node from where the query should start. | ||
322 | * @param {String} selector The selector/xpath query | ||
323 | * @param {String} type (optional) Either 'select' (the default) or 'simple' for a simple selector match | ||
324 | * @return {Function} | ||
325 | */ | ||
326 | compile : function(path, type){ | ||
327 | // strip leading slashes | ||
328 | while(path.substr(0, 1)=='/'){ | ||
329 | path = path.substr(1); | ||
330 | } | ||
331 | type = type || 'select'; | ||
332 | |||
333 | var fn = ['var f = function(root){\n var mode; var n = root || document;\n']; | ||
334 | var q = path, mode, lq; | ||
335 | var tk = Clipperz.YUI.DomQuery.matchers; | ||
336 | var tklen = tk.length; | ||
337 | var mm; | ||
338 | while(q && lq != q){ | ||
339 | lq = q; | ||
340 | var tm = q.match(/^(#)?([\w-\*]+)/); | ||
341 | if(type == 'select'){ | ||
342 | if(tm){ | ||
343 | if(tm[1] == '#'){ | ||
344 | fn[fn.length] = 'n = quickId(n, mode, root, "'+tm[2]+'");'; | ||
345 | }else{ | ||
346 | fn[fn.length] = 'n = getNodes(n, mode, "'+tm[2]+'");'; | ||
347 | } | ||
348 | q = q.replace(tm[0], ''); | ||
349 | }else{ | ||
350 | fn[fn.length] = 'n = getNodes(n, mode, "*");'; | ||
351 | } | ||
352 | }else{ | ||
353 | if(tm){ | ||
354 | if(tm[1] == '#'){ | ||
355 | fn[fn.length] = 'n = byId(n, null, "'+tm[2]+'");'; | ||
356 | }else{ | ||
357 | fn[fn.length] = 'n = byTag(n, "'+tm[2]+'");'; | ||
358 | } | ||
359 | q = q.replace(tm[0], ''); | ||
360 | } | ||
361 | } | ||
362 | while(!(mm = q.match(modeRe))){ | ||
363 | var matched = false; | ||
364 | for(var j = 0; j < tklen; j++){ | ||
365 | var t = tk[j]; | ||
366 | var m = q.match(t.re); | ||
367 | if(m){ | ||
368 | fn[fn.length] = t.select.replace(tplRe, function(x, i){ | ||
369 | return m[i]; | ||
370 | }); | ||
371 | q = q.replace(m[0], ''); | ||
372 | matched = true; | ||
373 | break; | ||
374 | } | ||
375 | } | ||
376 | // prevent infinite loop on bad selector | ||
377 | if(!matched){ | ||
378 | throw 'Error parsing selector, parsing failed at "' + q + '"'; | ||
379 | } | ||
380 | } | ||
381 | if(mm[1]){ | ||
382 | fn[fn.length] = 'mode="'+mm[1]+'";'; | ||
383 | q = q.replace(mm[1], ''); | ||
384 | } | ||
385 | } | ||
386 | fn[fn.length] = 'return nodup(n);\n}'; | ||
387 | eval(fn.join('')); | ||
388 | return f; | ||
389 | }, | ||
390 | |||
391 | /** | ||
392 | * Selects a group of elements. | ||
393 | * @param {String} selector The selector/xpath query | ||
394 | * @param {Node} root (optional) The start of the query (defaults to document). | ||
395 | * @return {Array} | ||
396 | */ | ||
397 | select : function(path, root, type){ | ||
398 | if(!root || root == document){ | ||
399 | root = document; | ||
400 | } | ||
401 | if(typeof root == 'string'){ | ||
402 | root = document.getElementById(root); | ||
403 | } | ||
404 | var paths = path.split(','); | ||
405 | var results = []; | ||
406 | for(var i = 0, len = paths.length; i < len; i++){ | ||
407 | var p = paths[i].replace(trimRe, '$1'); | ||
408 | if(!cache[p]){ | ||
409 | cache[p] = Clipperz.YUI.DomQuery.compile(p); | ||
410 | if(!cache[p]){ | ||
411 | throw p + ' is not a valid selector'; | ||
412 | } | ||
413 | } | ||
414 | var result = cache[p](root); | ||
415 | if(result && result != document){ | ||
416 | results = results.concat(result); | ||
417 | } | ||
418 | } | ||
419 | return results; | ||
420 | }, | ||
421 | |||
422 | /** | ||
423 | * Selects a single element. | ||
424 | * @param {String} selector The selector/xpath query | ||
425 | * @param {Node} root (optional) The start of the query (defaults to document). | ||
426 | * @return {Element} | ||
427 | */ | ||
428 | selectNode : function(path, root){ | ||
429 | return Clipperz.YUI.DomQuery.select(path, root)[0]; | ||
430 | }, | ||
431 | |||
432 | /** | ||
433 | * Selects the value of a node, optionally replacing null with the defaultValue. | ||
434 | * @param {String} selector The selector/xpath query | ||
435 | * @param {Node} root (optional) The start of the query (defaults to document). | ||
436 | * @param {String} defaultValue | ||
437 | */ | ||
438 | selectValue : function(path, root, defaultValue){ | ||
439 | path = path.replace(trimRe, '$1'); | ||
440 | if(!valueCache[path]){ | ||
441 | valueCache[path] = Clipperz.YUI.DomQuery.compile(path, 'simple'); | ||
442 | } | ||
443 | var n = valueCache[path](root); | ||
444 | n = n[0] ? n[0] : n; | ||
445 | var v = (n && n.firstChild ? n.firstChild.nodeValue : null); | ||
446 | return (v === null ? defaultValue : v); | ||
447 | }, | ||
448 | |||
449 | /** | ||
450 | * Selects the value of a node, parsing integers and floats. | ||
451 | * @param {String} selector The selector/xpath query | ||
452 | * @param {Node} root (optional) The start of the query (defaults to document). | ||
453 | * @param {Number} defaultValue | ||
454 | * @return {Number} | ||
455 | */ | ||
456 | selectNumber : function(path, root, defaultValue){ | ||
457 | var v = Clipperz.YUI.DomQuery.selectValue(path, root, defaultValue || 0); | ||
458 | return parseFloat(v); | ||
459 | }, | ||
460 | |||
461 | /** | ||
462 | * Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child) | ||
463 | * @param {String/HTMLElement/Array} el An element id, element or array of elements | ||
464 | * @param {String} selector The simple selector to test | ||
465 | * @return {Boolean} | ||
466 | */ | ||
467 | is : function(el, ss){ | ||
468 | if(typeof el == 'string'){ | ||
469 | el = document.getElementById(el); | ||
470 | } | ||
471 | var isArray = (el instanceof Array); | ||
472 | var result = Clipperz.YUI.DomQuery.filter(isArray ? el : [el], ss); | ||
473 | return isArray ? (result.length == el.length) : (result.length > 0); | ||
474 | }, | ||
475 | |||
476 | /** | ||
477 | * Filters an array of elements to only include matches of a simple selector (e.g. div.some-class or span:first-child) | ||
478 | * @param {Array} el An array of elements to filter | ||
479 | * @param {String} selector The simple selector to test | ||
480 | * @param {Boolean} nonMatches If true, it returns the elements that DON'T match | ||
481 | * the selector instead of the ones that match | ||
482 | * @return {Array} | ||
483 | */ | ||
484 | filter : function(els, ss, nonMatches){ | ||
485 | ss = ss.replace(trimRe, '$1'); | ||
486 | if(!simpleCache[ss]){ | ||
487 | simpleCache[ss] = Clipperz.YUI.DomQuery.compile(ss, 'simple'); | ||
488 | } | ||
489 | var result = simpleCache[ss](els); | ||
490 | return nonMatches ? quickDiff(result, els) : result; | ||
491 | }, | ||
492 | |||
493 | /** | ||
494 | * Collection of matching regular expressions and code snippets. | ||
495 | */ | ||
496 | matchers : [{ | ||
497 | re: /^\.([\w-]+)/, | ||
498 | select: 'n = byClassName(n, null, "{1}");' | ||
499 | }, { | ||
500 | re: /^\:([\w-]+)(?:\(((?:[^\s>\/]*|.*?))\))?/, | ||
501 | select: 'n = byPseudo(n, "{1}", "{2}");' | ||
502 | },{ | ||
503 | re: /^(?:([\[\{])(?:@)?([\w-]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/, | ||
504 | select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");' | ||
505 | }, { | ||
506 | re: /^#([\w-]+)/, | ||
507 | select: 'n = byId(n, null, "{1}");' | ||
508 | },{ | ||
509 | re: /^@([\w-]+)/, | ||
510 | select: 'return {firstChild:{nodeValue:attrValue(n, "{1}")}};' | ||
511 | } | ||
512 | ], | ||
513 | |||
514 | /** | ||
515 | * Collection of operator comparison functions. The default operators are =, !=, ^=, $=, *= and %=. | ||
516 | * New operators can be added as long as the match the format <i>c</i>= where <i>c<i> is any character other than space, > <. | ||
517 | */ | ||
518 | operators : { | ||
519 | '=' : function(a, v){ | ||
520 | return a == v; | ||
521 | }, | ||
522 | '!=' : function(a, v){ | ||
523 | return a != v; | ||
524 | }, | ||
525 | '^=' : function(a, v){ | ||
526 | return a && a.substr(0, v.length) == v; | ||
527 | }, | ||
528 | '$=' : function(a, v){ | ||
529 | return a && a.substr(a.length-v.length) == v; | ||
530 | }, | ||
531 | '*=' : function(a, v){ | ||
532 | return a && a.indexOf(v) !== -1; | ||
533 | }, | ||
534 | '%=' : function(a, v){ | ||
535 | return (a % v) == 0; | ||
536 | } | ||
537 | }, | ||
538 | |||
539 | /** | ||
540 | * Collection of "pseudo class" processors. Each processor is passed the current nodeset (array) | ||
541 | * and the argument (if any) supplied in the selector. | ||
542 | */ | ||
543 | pseudos : { | ||
544 | 'first-child' : function(c){ | ||
545 | var r = []; | ||
546 | for(var i = 0, l = c.length; i < l; i++){ | ||
547 | var ci = c[i]; | ||
548 | if(!prev(ci)){ | ||
549 | r[r.length] = ci; | ||
550 | } | ||
551 | } | ||
552 | return r; | ||
553 | }, | ||
554 | |||
555 | 'last-child' : function(c){ | ||
556 | var r = []; | ||
557 | for(var i = 0, l = c.length; i < l; i++){ | ||
558 | var ci = c[i]; | ||
559 | if(!next(ci)){ | ||
560 | r[r.length] = ci; | ||
561 | } | ||
562 | } | ||
563 | return r; | ||
564 | }, | ||
565 | |||
566 | 'nth-child' : function(c, a){ | ||
567 | var r = []; | ||
568 | if(a != 'odd' && a != 'even'){ | ||
569 | for(var i = 0, ci; ci = c[i]; i++){ | ||
570 | var m = child(ci.parentNode, a); | ||
571 | if(m == ci){ | ||
572 | r[r.length] = m; | ||
573 | } | ||
574 | } | ||
575 | return r; | ||
576 | } | ||
577 | var p; | ||
578 | // first let's clean up the parent nodes | ||
579 | for(var i = 0, l = c.length; i < l; i++){ | ||
580 | var cp = c[i].parentNode; | ||
581 | if(cp != p){ | ||
582 | clean(cp); | ||
583 | p = cp; | ||
584 | } | ||
585 | } | ||
586 | // then lets see if we match | ||
587 | for(var i = 0, l = c.length; i < l; i++){ | ||
588 | var ci = c[i], m = false; | ||
589 | if(a == 'odd'){ | ||
590 | m = ((ci.nodeIndex+1) % 2 == 1); | ||
591 | }else if(a == 'even'){ | ||
592 | m = ((ci.nodeIndex+1) % 2 == 0); | ||
593 | } | ||
594 | if(m){ | ||
595 | r[r.length] = ci; | ||
596 | } | ||
597 | } | ||
598 | return r; | ||
599 | }, | ||
600 | |||
601 | 'only-child' : function(c){ | ||
602 | var r = []; | ||
603 | for(var i = 0, l = c.length; i < l; i++){ | ||
604 | var ci = c[i]; | ||
605 | if(!prev(ci) && !next(ci)){ | ||
606 | r[r.length] = ci; | ||
607 | } | ||
608 | } | ||
609 | return r; | ||
610 | }, | ||
611 | |||
612 | 'empty' : function(c){ | ||
613 | var r = []; | ||
614 | for(var i = 0, l = c.length; i < l; i++){ | ||
615 | var ci = c[i]; | ||
616 | if(!ci.firstChild){ | ||
617 | r[r.length] = ci; | ||
618 | } | ||
619 | } | ||
620 | return r; | ||
621 | }, | ||
622 | |||
623 | 'contains' : function(c, v){ | ||
624 | var r = []; | ||
625 | for(var i = 0, l = c.length; i < l; i++){ | ||
626 | var ci = c[i]; | ||
627 | if(ci.innerHTML.indexOf(v) !== -1){ | ||
628 | r[r.length] = ci; | ||
629 | } | ||
630 | } | ||
631 | return r; | ||
632 | }, | ||
633 | |||
634 | 'checked' : function(c){ | ||
635 | var r = []; | ||
636 | for(var i = 0, l = c.length; i < l; i++){ | ||
637 | if(c[i].checked == 'checked'){ | ||
638 | r[r.length] = c[i]; | ||
639 | } | ||
640 | } | ||
641 | return r; | ||
642 | }, | ||
643 | |||
644 | 'not' : function(c, ss){ | ||
645 | return Clipperz.YUI.DomQuery.filter(c, ss, true); | ||
646 | }, | ||
647 | |||
648 | 'odd' : function(c){ | ||
649 | return this['nth-child'](c, 'odd'); | ||
650 | }, | ||
651 | |||
652 | 'even' : function(c){ | ||
653 | return this['nth-child'](c, 'even'); | ||
654 | }, | ||
655 | |||
656 | 'nth' : function(c, a){ | ||
657 | return c[a-1]; | ||
658 | }, | ||
659 | |||
660 | 'first' : function(c){ | ||
661 | return c[0]; | ||
662 | }, | ||
663 | |||
664 | 'last' : function(c){ | ||
665 | return c[c.length-1]; | ||
666 | }, | ||
667 | |||
668 | 'has' : function(c, ss){ | ||
669 | var s = Clipperz.YUI.DomQuery.select; | ||
670 | var r = []; | ||
671 | for(var i = 0, ci; ci = c[i]; i++){ | ||
672 | if(s(ss, ci).length > 0){ | ||
673 | r[r.length] = ci; | ||
674 | } | ||
675 | } | ||
676 | return r; | ||
677 | }, | ||
678 | |||
679 | 'next' : function(c, ss){ | ||
680 | var is = Clipperz.YUI.DomQuery.is; | ||
681 | var r = []; | ||
682 | for(var i = 0, ci; ci = c[i]; i++){ | ||
683 | var n = next(ci); | ||
684 | if(n && is(n, ss)){ | ||
685 | r[r.length] = ci; | ||
686 | } | ||
687 | } | ||
688 | return r; | ||
689 | }, | ||
690 | |||
691 | 'prev' : function(c, ss){ | ||
692 | var is = Clipperz.YUI.DomQuery.is; | ||
693 | var r = []; | ||
694 | for(var i = 0, ci; ci = c[i]; i++){ | ||
695 | var n = prev(ci); | ||
696 | if(n && is(n, ss)){ | ||
697 | r[r.length] = ci; | ||
698 | } | ||
699 | } | ||
700 | return r; | ||
701 | } | ||
702 | } | ||
703 | }; | ||
704 | }(); | ||
705 | |||
706 | /** | ||
707 | * Selects an array of DOM nodes by CSS/XPath selector. Shorthand of {@link Clipperz.YUI.DomQuery#select} | ||
708 | * @param {String} path The selector/xpath query | ||
709 | * @param {Node} root (optional) The start of the query (defaults to document). | ||
710 | * @return {Array} | ||
711 | * @member Ext | ||
712 | * @method query | ||
713 | */ | ||
714 | Clipperz.YUI.query = Clipperz.YUI.DomQuery.select; | ||
diff --git a/frontend/gamma/js/Clipperz/YUI/Utils.js b/frontend/gamma/js/Clipperz/YUI/Utils.js new file mode 100644 index 0000000..4d4a5f9 --- a/dev/null +++ b/frontend/gamma/js/Clipperz/YUI/Utils.js | |||
@@ -0,0 +1,98 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz's Javascript Crypto Library. | ||
6 | Javascript Crypto Library provides web developers with an extensive | ||
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | ||
11 | refer to http://www.clipperz.com | ||
12 | |||
13 | * Javascript Crypto Library is free software: you can redistribute | ||
14 | it and/or modify it under the terms of the GNU Affero General Public | ||
15 | License as published by the Free Software Foundation, either version | ||
16 | 3 of the License, or (at your option) any later version. | ||
17 | |||
18 | * Javascript Crypto Library is distributed in the hope that it will | ||
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
21 | See the GNU Affero General Public License for more details. | ||
22 | |||
23 | * You should have received a copy of the GNU Affero General Public | ||
24 | License along with Javascript Crypto Library. If not, see | ||
25 | <http://www.gnu.org/licenses/>. | ||
26 | |||
27 | */ | ||
28 | |||
29 | if (typeof YAHOO == 'undefined') { YAHOO = {}; }; | ||
30 | if (typeof YAHOO.util == 'undefined') { YAHOO.util = {}; }; | ||
31 | if (typeof YAHOO.util.Dom == 'undefined') { YAHOO.util.Dom = {}; }; | ||
32 | |||
33 | YAHOO.extend = function(subc, superc, overrides) { | ||
34 | var F = function() {}; | ||
35 | F.prototype=superc.prototype; | ||
36 | subc.prototype=new F(); | ||
37 | subc.prototype.constructor=subc; | ||
38 | subc.superclass=superc.prototype; | ||
39 | if (superc.prototype.constructor == Object.prototype.constructor) { | ||
40 | superc.prototype.constructor=superc; | ||
41 | } | ||
42 | |||
43 | if (overrides) { | ||
44 | for (var i in overrides) { | ||
45 | subc.prototype[i]=overrides[i]; | ||
46 | } | ||
47 | } | ||
48 | }; | ||
49 | |||
50 | YAHOO.override = function(origclass, overrides){ | ||
51 | if(overrides){ | ||
52 | var p = origclass.prototype; | ||
53 | for(var method in overrides){ | ||
54 | p[method] = overrides[method]; | ||
55 | } | ||
56 | } | ||
57 | }; | ||
58 | |||
59 | YAHOO.extendX = function(subclass, superclass, overrides){ | ||
60 | YAHOO.extend(subclass, superclass); | ||
61 | subclass.override = function(o){ | ||
62 | YAHOO.override(subclass, o); | ||
63 | }; | ||
64 | if(!subclass.prototype.override){ | ||
65 | subclass.prototype.override = function(o){ | ||
66 | for(var method in o){ | ||
67 | this[method] = o[method]; | ||
68 | } | ||
69 | }; | ||
70 | } | ||
71 | if(overrides){ | ||
72 | subclass.override(overrides); | ||
73 | }; | ||
74 | |||
75 | }; | ||
76 | |||
77 | YAHOO.util.Dom.get = function(el) { | ||
78 | if (!el) { return null; } // nothing to work with | ||
79 | |||
80 | if (typeof el != 'string' && !(el instanceof Array) ) { // assuming HTMLElement or HTMLCollection, so pass back as is | ||
81 | return el; | ||
82 | } | ||
83 | |||
84 | if (typeof el == 'string') { // ID | ||
85 | return document.getElementById(el); | ||
86 | } | ||
87 | else { // array of ID's and/or elements | ||
88 | var collection = []; | ||
89 | for (var i = 0, len = el.length; i < len; ++i) { | ||
90 | collection[collection.length] = YAHOO.util.Dom.get(el[i]); | ||
91 | } | ||
92 | |||
93 | return collection; | ||
94 | } | ||
95 | |||
96 | return null; // safety, should never happen | ||
97 | }; | ||
98 | |||