author | Clipperz <info@clipperz.com> | 2013-01-31 13:42:04 (UTC) |
---|---|---|
committer | Clipperz <info@clipperz.com> | 2013-01-31 13:42:04 (UTC) |
commit | 07d0357beef5d9328a2dd8d07ad7b39c87ac55e4 (patch) (unidiff) | |
tree | f7a4aed8848302db153c2a211f8e58b944eb4c5b /frontend/gamma/js/Clipperz/YUI/DomHelper.js | |
parent | 767a3dcf48b6ac911c088af5dd7738a728eb6b99 (diff) | |
download | clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.zip clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.tar.gz clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.tar.bz2 |
Updated Copyright claims
- updated reference dates;
- removed reference to Community Edition;
- normalized logging using Clipperz.log[Warn|Error|Debug]
Diffstat (limited to 'frontend/gamma/js/Clipperz/YUI/DomHelper.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/YUI/DomHelper.js | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/frontend/gamma/js/Clipperz/YUI/DomHelper.js b/frontend/gamma/js/Clipperz/YUI/DomHelper.js index 87c74f5..0a1f9fe 100644 --- a/frontend/gamma/js/Clipperz/YUI/DomHelper.js +++ b/frontend/gamma/js/Clipperz/YUI/DomHelper.js | |||
@@ -1,118 +1,116 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer to http://www.clipperz.com. |
9 | 8 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 9 | * Clipperz is free software: you can redistribute it and/or modify it |
11 | it and/or modify it under the terms of the GNU Affero General Public | 10 | under the terms of the GNU Affero General Public License as published |
12 | License as published by the Free Software Foundation, either version | 11 | by the Free Software Foundation, either version 3 of the License, or |
13 | 3 of the License, or (at your option) any later version. | 12 | (at your option) any later version. |
14 | 13 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 14 | * Clipperz is distributed in the hope that it will be useful, but |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 17 | See the GNU Affero General Public License for more details. |
19 | 18 | ||
20 | * You should have received a copy of the GNU Affero General Public | 19 | * You should have received a copy of the GNU Affero General Public |
21 | License along with Clipperz Community Edition. If not, see | 20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. |
22 | <http://www.gnu.org/licenses/>. | ||
23 | 21 | ||
24 | */ | 22 | */ |
25 | 23 | ||
26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 24 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | if (typeof(Clipperz.YUI) == 'undefined') { Clipperz.YUI = {}; } | 25 | if (typeof(Clipperz.YUI) == 'undefined') { Clipperz.YUI = {}; } |
28 | 26 | ||
29 | 27 | ||
30 | /** | 28 | /** |
31 | * @class Clipperz.ext.DomHelper | 29 | * @class Clipperz.ext.DomHelper |
32 | * Utility class for working with DOM and/or Templates. It transparently supports using HTML fragments or DOM. | 30 | * Utility class for working with DOM and/or Templates. It transparently supports using HTML fragments or DOM. |
33 | * 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>. | 31 | * 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>. |
34 | * @singleton | 32 | * @singleton |
35 | */ | 33 | */ |
36 | Clipperz.YUI.DomHelper = new function(){ | 34 | Clipperz.YUI.DomHelper = new function(){ |
37 | /**@private*/ | 35 | /**@private*/ |
38 | var d = document; | 36 | var d = document; |
39 | var tempTableEl = null; | 37 | var tempTableEl = null; |
40 | /** True to force the use of DOM instead of html fragments @type Boolean */ | 38 | /** True to force the use of DOM instead of html fragments @type Boolean */ |
41 | this.useDom = false; | 39 | this.useDom = false; |
42 | 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; | 40 | 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; |
43 | /** | 41 | /** |
44 | * Applies a style specification to an element | 42 | * Applies a style specification to an element |
45 | * @param {String/HTMLElement} el The element to apply styles to | 43 | * @param {String/HTMLElement} el The element to apply styles to |
46 | * @param {String/Object/Function} styles A style specification string eg "width:100px", or object in the form {width:"100px"}, or | 44 | * @param {String/Object/Function} styles A style specification string eg "width:100px", or object in the form {width:"100px"}, or |
47 | * a function which returns such a specification. | 45 | * a function which returns such a specification. |
48 | */ | 46 | */ |
49 | this.applyStyles = function(el, styles){ | 47 | this.applyStyles = function(el, styles){ |
50 | if(styles){ | 48 | if(styles){ |
51 | var D = YAHOO.util.Dom; | 49 | var D = YAHOO.util.Dom; |
52 | if (typeof styles == "string"){ | 50 | if (typeof styles == "string"){ |
53 | var re = /\s?([a-z\-]*)\:([^;]*);?/gi; | 51 | var re = /\s?([a-z\-]*)\:([^;]*);?/gi; |
54 | var matches; | 52 | var matches; |
55 | while ((matches = re.exec(styles)) != null){ | 53 | while ((matches = re.exec(styles)) != null){ |
56 | D.setStyle(el, matches[1], matches[2]); | 54 | D.setStyle(el, matches[1], matches[2]); |
57 | } | 55 | } |
58 | }else if (typeof styles == "object"){ | 56 | }else if (typeof styles == "object"){ |
59 | for (var style in styles){ | 57 | for (var style in styles){ |
60 | D.setStyle(el, style, styles[style]); | 58 | D.setStyle(el, style, styles[style]); |
61 | } | 59 | } |
62 | }else if (typeof styles == "function"){ | 60 | }else if (typeof styles == "function"){ |
63 | Clipperz.YUI.DomHelper.applyStyles(el, styles.call()); | 61 | Clipperz.YUI.DomHelper.applyStyles(el, styles.call()); |
64 | } | 62 | } |
65 | } | 63 | } |
66 | }; | 64 | }; |
67 | 65 | ||
68 | // build as innerHTML where available | 66 | // build as innerHTML where available |
69 | /** @ignore */ | 67 | /** @ignore */ |
70 | var createHtml = function(o){ | 68 | var createHtml = function(o){ |
71 | var b = ''; | 69 | var b = ''; |
72 | 70 | ||
73 | if(typeof(o['html']) != 'undefined') { | 71 | if(typeof(o['html']) != 'undefined') { |
74 | o['html'] = Clipperz.Base.sanitizeString(o['html']); | 72 | o['html'] = Clipperz.Base.sanitizeString(o['html']); |
75 | } else if (typeof(o['htmlString']) != 'undefined') { | 73 | } else if (typeof(o['htmlString']) != 'undefined') { |
76 | o['html'] = o['htmlString']; | 74 | o['html'] = o['htmlString']; |
77 | delete o.htmlString; | 75 | delete o.htmlString; |
78 | } | 76 | } |
79 | 77 | ||
80 | if (MochiKit.Base.isArrayLike(o)) { | 78 | if (MochiKit.Base.isArrayLike(o)) { |
81 | for (var i = 0, l = o.length; i < l; i++) { | 79 | for (var i = 0, l = o.length; i < l; i++) { |
82 | b += createHtml(o[i]); | 80 | b += createHtml(o[i]); |
83 | } | 81 | } |
84 | return b; | 82 | return b; |
85 | } | 83 | } |
86 | 84 | ||
87 | b += '<' + o.tag; | 85 | b += '<' + o.tag; |
88 | for(var attr in o){ | 86 | for(var attr in o){ |
89 | if(attr == 'tag' || attr == 'children' || attr == 'html' || typeof o[attr] == 'function') continue; | 87 | if(attr == 'tag' || attr == 'children' || attr == 'html' || typeof o[attr] == 'function') continue; |
90 | if(attr == 'style'){ | 88 | if(attr == 'style'){ |
91 | var s = o['style']; | 89 | var s = o['style']; |
92 | if(typeof s == 'function'){ | 90 | if(typeof s == 'function'){ |
93 | s = s.call(); | 91 | s = s.call(); |
94 | } | 92 | } |
95 | if(typeof s == 'string'){ | 93 | if(typeof s == 'string'){ |
96 | b += ' style="' + s + '"'; | 94 | b += ' style="' + s + '"'; |
97 | }else if(typeof s == 'object'){ | 95 | }else if(typeof s == 'object'){ |
98 | b += ' style="'; | 96 | b += ' style="'; |
99 | for(var key in s){ | 97 | for(var key in s){ |
100 | if(typeof s[key] != 'function'){ | 98 | if(typeof s[key] != 'function'){ |
101 | b += key + ':' + s[key] + ';'; | 99 | b += key + ':' + s[key] + ';'; |
102 | } | 100 | } |
103 | } | 101 | } |
104 | b += '"'; | 102 | b += '"'; |
105 | } | 103 | } |
106 | }else{ | 104 | }else{ |
107 | if(attr == 'cls'){ | 105 | if(attr == 'cls'){ |
108 | b += ' class="' + o['cls'] + '"'; | 106 | b += ' class="' + o['cls'] + '"'; |
109 | }else if(attr == 'htmlFor'){ | 107 | }else if(attr == 'htmlFor'){ |
110 | b += ' for="' + o['htmlFor'] + '"'; | 108 | b += ' for="' + o['htmlFor'] + '"'; |
111 | }else{ | 109 | }else{ |
112 | b += ' ' + attr + '="' + o[attr] + '"'; | 110 | b += ' ' + attr + '="' + o[attr] + '"'; |
113 | } | 111 | } |
114 | } | 112 | } |
115 | } | 113 | } |
116 | if(emptyTags.test(o.tag)){ | 114 | if(emptyTags.test(o.tag)){ |
117 | b += ' />'; | 115 | b += ' />'; |
118 | }else{ | 116 | }else{ |
@@ -347,132 +345,127 @@ Clipperz.YUI.DomHelper = new function(){ | |||
347 | }(); | 345 | }(); |
348 | 346 | ||
349 | /** | 347 | /** |
350 | * @class Clipperz.YUI.DomHelper.Template | 348 | * @class Clipperz.YUI.DomHelper.Template |
351 | * Represents an HTML fragment template. | 349 | * Represents an HTML fragment template. |
352 | * 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>. | 350 | * 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>. |
353 | * <br> | 351 | * <br> |
354 | * <b>This class is also available as Clipperz.YUI.Template</b>. | 352 | * <b>This class is also available as Clipperz.YUI.Template</b>. |
355 | * @constructor | 353 | * @constructor |
356 | * @param {String/Array} html The HTML fragment or an array of fragments to join('') or multiple arguments to join('') | 354 | * @param {String/Array} html The HTML fragment or an array of fragments to join('') or multiple arguments to join('') |
357 | */ | 355 | */ |
358 | Clipperz.YUI.DomHelper.Template = function(html){ | 356 | Clipperz.YUI.DomHelper.Template = function(html){ |
359 | if(html instanceof Array){ | 357 | if(html instanceof Array){ |
360 | html = html.join(''); | 358 | html = html.join(''); |
361 | }else if(arguments.length > 1){ | 359 | }else if(arguments.length > 1){ |
362 | html = Array.prototype.join.call(arguments, ''); | 360 | html = Array.prototype.join.call(arguments, ''); |
363 | } | 361 | } |
364 | /**@private*/ | 362 | /**@private*/ |
365 | this.html = html; | 363 | this.html = html; |
366 | }; | 364 | }; |
367 | Clipperz.YUI.DomHelper.Template.prototype = { | 365 | Clipperz.YUI.DomHelper.Template.prototype = { |
368 | /** | 366 | /** |
369 | * Returns an HTML fragment of this template with the specified values applied | 367 | * Returns an HTML fragment of this template with the specified values applied |
370 | * @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'}) | 368 | * @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'}) |
371 | * @return {String} | 369 | * @return {String} |
372 | */ | 370 | */ |
373 | applyTemplate : function(values){ | 371 | applyTemplate : function(values){ |
374 | if(this.compiled){ | 372 | if(this.compiled){ |
375 | return this.compiled(values); | 373 | return this.compiled(values); |
376 | } | 374 | } |
377 | var empty = ''; | 375 | var empty = ''; |
378 | var fn = function(match, index){ | 376 | var fn = function(match, index){ |
379 | if(typeof values[index] != 'undefined'){ | 377 | if(typeof values[index] != 'undefined'){ |
380 | return values[index]; | 378 | return values[index]; |
381 | }else{ | 379 | }else{ |
382 | return empty; | 380 | return empty; |
383 | } | 381 | } |
384 | } | 382 | } |
385 | return this.html.replace(this.re, fn); | 383 | return this.html.replace(this.re, fn); |
386 | }, | 384 | }, |
387 | 385 | ||
388 | /** | 386 | /** |
389 | * The regular expression used to match template variables | 387 | * The regular expression used to match template variables |
390 | * @type RegExp | 388 | * @type RegExp |
391 | * @property | 389 | * @property |
392 | */ | 390 | */ |
393 | re : /\{([\w|-]+)\}/g, | 391 | re : /\{([\w|-]+)\}/g, |
394 | 392 | ||
395 | /** | 393 | /** |
396 | * Compiles the template into an internal function, eliminating the RegEx overhead | 394 | * Compiles the template into an internal function, eliminating the RegEx overhead |
397 | */ | 395 | */ |
398 | compile : function(){ | 396 | compile : function(){ |
399 | var body = ["this.compiled = function(values){ return ['"]; | 397 | var body = ["this.compiled = function(values){ return ['"]; |
400 | body.push(this.html.replace(this.re, "', values['$1'], '")); | 398 | body.push(this.html.replace(this.re, "', values['$1'], '")); |
401 | body.push("'].join('');};"); | 399 | body.push("'].join('');};"); |
402 | eval(body.join('')); | 400 | eval(body.join('')); |
403 | return this; | 401 | return this; |
404 | }, | 402 | }, |
405 | 403 | ||
406 | /** | 404 | /** |
407 | * Applies the supplied values to the template and inserts the new node(s) before el | 405 | * Applies the supplied values to the template and inserts the new node(s) before el |
408 | * @param {String/HTMLElement/Element} el The context element | 406 | * @param {String/HTMLElement/Element} el The context element |
409 | * @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'}) | 407 | * @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'}) |
410 | * @param {<i>Boolean</i>} returnElement (optional) true to return a YAHOO.Element | 408 | * @param {<i>Boolean</i>} returnElement (optional) true to return a YAHOO.Element |
411 | * @return {HTMLElement} The new node | 409 | * @return {HTMLElement} The new node |
412 | */ | 410 | */ |
413 | insertBefore: function(el, values, returnElement){ | 411 | insertBefore: function(el, values, returnElement){ |
414 | el = el.dom ? el.dom : YAHOO.util.Dom.get(el); | 412 | el = el.dom ? el.dom : YAHOO.util.Dom.get(el); |
415 | var newNode = Clipperz.YUI.DomHelper.insertHtml('beforeBegin', el, this.applyTemplate(values)); | 413 | var newNode = Clipperz.YUI.DomHelper.insertHtml('beforeBegin', el, this.applyTemplate(values)); |
416 | return returnElement ? YAHOO.Element.get(newNode, true) : newNode; | 414 | return returnElement ? YAHOO.Element.get(newNode, true) : newNode; |
417 | }, | 415 | }, |
418 | 416 | ||
419 | /** | 417 | /** |
420 | * Applies the supplied values to the template and inserts the new node(s) after el | 418 | * Applies the supplied values to the template and inserts the new node(s) after el |
421 | * @param {String/HTMLElement/Element} el The context element | 419 | * @param {String/HTMLElement/Element} el The context element |
422 | * @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'}) | 420 | * @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'}) |
423 | * @param {<i>Boolean</i>} returnElement (optional) true to return a YAHOO.Element | 421 | * @param {<i>Boolean</i>} returnElement (optional) true to return a YAHOO.Element |
424 | * @return {HTMLElement} The new node | 422 | * @return {HTMLElement} The new node |
425 | */ | 423 | */ |
426 | insertAfter : function(el, values, returnElement){ | 424 | insertAfter : function(el, values, returnElement){ |
427 | el = el.dom ? el.dom : YAHOO.util.Dom.get(el); | 425 | el = el.dom ? el.dom : YAHOO.util.Dom.get(el); |
428 | var newNode = Clipperz.YUI.DomHelper.insertHtml('afterEnd', el, this.applyTemplate(values)); | 426 | var newNode = Clipperz.YUI.DomHelper.insertHtml('afterEnd', el, this.applyTemplate(values)); |
429 | return returnElement ? YAHOO.Element.get(newNode, true) : newNode; | 427 | return returnElement ? YAHOO.Element.get(newNode, true) : newNode; |
430 | }, | 428 | }, |
431 | 429 | ||
432 | /** | 430 | /** |
433 | * Applies the supplied values to the template and append the new node(s) to el | 431 | * Applies the supplied values to the template and append the new node(s) to el |
434 | * @param {String/HTMLElement/Element} el The context element | 432 | * @param {String/HTMLElement/Element} el The context element |
435 | * @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'}) | 433 | * @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'}) |
436 | * @param {<i>Boolean</i>} returnElement (optional) true to return a YAHOO.Element | 434 | * @param {<i>Boolean</i>} returnElement (optional) true to return a YAHOO.Element |
437 | * @return {HTMLElement} The new node | 435 | * @return {HTMLElement} The new node |
438 | */ | 436 | */ |
439 | append : function(el, values, returnElement){ | 437 | append : function(el, values, returnElement){ |
440 | var sanitizedValues; | 438 | var sanitizedValues; |
441 | var key; | 439 | var key; |
442 | 440 | ||
443 | // sanitizedValues = MochiKit.Base.map(sanitizedValues) | ||
444 | //console.log("values", values); | ||
445 | sanitizedValues = {}; | 441 | sanitizedValues = {}; |
446 | for (key in values) { | 442 | for (key in values) { |
447 | sanitizedValues[key] = Clipperz.Base.sanitizeString(values[key]); | 443 | sanitizedValues[key] = Clipperz.Base.sanitizeString(values[key]); |
448 | } | 444 | } |
449 | //console.log("sanitizedValues", sanitizedValues); | ||
450 | // el = el.dom ? el.dom : YAHOO.util.Dom.get(el); | ||
451 | el = (typeof el == 'string') ? YAHOO.util.Dom.get(el) : el; | 445 | el = (typeof el == 'string') ? YAHOO.util.Dom.get(el) : el; |
452 | //Clipperz.log(this.applyTemplate(sanitizedValues)); | ||
453 | var newNode = Clipperz.YUI.DomHelper.insertHtml('beforeEnd', el, this.applyTemplate(sanitizedValues)); | 446 | var newNode = Clipperz.YUI.DomHelper.insertHtml('beforeEnd', el, this.applyTemplate(sanitizedValues)); |
454 | // return returnElement ? YAHOO.Element.get(newNode, true) : newNode; | 447 | |
455 | return newNode; | 448 | return newNode; |
456 | }, | 449 | }, |
457 | 450 | ||
458 | /** | 451 | /** |
459 | * Applies the supplied values to the template and overwrites the content of el with the new node(s) | 452 | * Applies the supplied values to the template and overwrites the content of el with the new node(s) |
460 | * @param {String/HTMLElement/Element} el The context element | 453 | * @param {String/HTMLElement/Element} el The context element |
461 | * @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'}) | 454 | * @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'}) |
462 | * @param {<i>Boolean</i>} returnElement (optional) true to return a YAHOO.Element | 455 | * @param {<i>Boolean</i>} returnElement (optional) true to return a YAHOO.Element |
463 | * @return {HTMLElement} The new node | 456 | * @return {HTMLElement} The new node |
464 | */ | 457 | */ |
465 | overwrite : function(el, values, returnElement){ | 458 | overwrite : function(el, values, returnElement){ |
466 | el = el.dom ? el.dom : YAHOO.util.Dom.get(el); | 459 | el = el.dom ? el.dom : YAHOO.util.Dom.get(el); |
467 | el.innerHTML = ''; | 460 | el.innerHTML = ''; |
468 | var newNode = Clipperz.YUI.DomHelper.insertHtml('beforeEnd', el, this.applyTemplate(values)); | 461 | var newNode = Clipperz.YUI.DomHelper.insertHtml('beforeEnd', el, this.applyTemplate(values)); |
469 | return returnElement ? YAHOO.Element.get(newNode, true) : newNode; | 462 | return returnElement ? YAHOO.Element.get(newNode, true) : newNode; |
470 | } | 463 | } |
471 | }; | 464 | }; |
472 | /** | 465 | /** |
473 | * Alias for applyTemplate | 466 | * Alias for applyTemplate |
474 | * @method | 467 | * @method |
475 | */ | 468 | */ |
476 | Clipperz.YUI.DomHelper.Template.prototype.apply = Clipperz.YUI.DomHelper.Template.prototype.applyTemplate; | 469 | Clipperz.YUI.DomHelper.Template.prototype.apply = Clipperz.YUI.DomHelper.Template.prototype.applyTemplate; |
477 | 470 | ||
478 | Clipperz.YUI.Template = Clipperz.YUI.DomHelper.Template; | 471 | Clipperz.YUI.Template = Clipperz.YUI.DomHelper.Template; |