Diffstat (limited to 'frontend/beta/js/Clipperz/YUI/DomHelper.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/YUI/DomHelper.js | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/beta/js/Clipperz/YUI/DomHelper.js b/frontend/beta/js/Clipperz/YUI/DomHelper.js index 05edc49..2c0ba34 100644 --- a/frontend/beta/js/Clipperz/YUI/DomHelper.js +++ b/frontend/beta/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.ext) == 'undefined') { Clipperz.ext = {}; } | 25 | if (typeof(Clipperz.ext) == 'undefined') { Clipperz.ext = {}; } |
28 | 26 | ||
29 | /** | 27 | /** |
30 | * @class Clipperz.YUI.DomHelper | 28 | * @class Clipperz.YUI.DomHelper |
31 | * Utility class for working with DOM and/or Templates. It transparently supports using HTML fragments or DOM. | 29 | * Utility class for working with DOM and/or Templates. It transparently supports using HTML fragments or DOM. |
32 | * 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>. | 30 | * 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>. |
33 | * @singleton | 31 | * @singleton |
34 | */ | 32 | */ |
35 | Clipperz.YUI.DomHelper = new function(){ | 33 | Clipperz.YUI.DomHelper = new function(){ |
36 | /**@private*/ | 34 | /**@private*/ |
37 | var d = document; | 35 | var d = document; |
38 | var tempTableEl = null; | 36 | var tempTableEl = null; |
39 | /** True to force the use of DOM instead of html fragments @type Boolean */ | 37 | /** True to force the use of DOM instead of html fragments @type Boolean */ |
40 | this.useDom = false; | 38 | this.useDom = false; |
41 | 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; | 39 | 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; |
42 | /** | 40 | /** |
43 | * Applies a style specification to an element | 41 | * Applies a style specification to an element |
44 | * @param {String/HTMLElement} el The element to apply styles to | 42 | * @param {String/HTMLElement} el The element to apply styles to |
45 | * @param {String/Object/Function} styles A style specification string eg "width:100px", or object in the form {width:"100px"}, or | 43 | * @param {String/Object/Function} styles A style specification string eg "width:100px", or object in the form {width:"100px"}, or |
46 | * a function which returns such a specification. | 44 | * a function which returns such a specification. |
47 | */ | 45 | */ |
48 | this.applyStyles = function(el, styles){ | 46 | this.applyStyles = function(el, styles){ |
49 | if(styles){ | 47 | if(styles){ |
50 | var D = YAHOO.util.Dom; | 48 | var D = YAHOO.util.Dom; |
51 | if (typeof styles == "string"){ | 49 | if (typeof styles == "string"){ |
52 | var re = /\s?([a-z\-]*)\:([^;]*);?/gi; | 50 | var re = /\s?([a-z\-]*)\:([^;]*);?/gi; |
53 | var matches; | 51 | var matches; |
54 | while ((matches = re.exec(styles)) != null){ | 52 | while ((matches = re.exec(styles)) != null){ |
55 | D.setStyle(el, matches[1], matches[2]); | 53 | D.setStyle(el, matches[1], matches[2]); |
56 | } | 54 | } |
57 | }else if (typeof styles == "object"){ | 55 | }else if (typeof styles == "object"){ |
58 | for (var style in styles){ | 56 | for (var style in styles){ |
59 | D.setStyle(el, style, styles[style]); | 57 | D.setStyle(el, style, styles[style]); |
60 | } | 58 | } |
61 | }else if (typeof styles == "function"){ | 59 | }else if (typeof styles == "function"){ |
62 | Clipperz.YUI.DomHelper.applyStyles(el, styles.call()); | 60 | Clipperz.YUI.DomHelper.applyStyles(el, styles.call()); |
63 | } | 61 | } |
64 | } | 62 | } |
65 | }; | 63 | }; |
66 | 64 | ||
67 | // build as innerHTML where available | 65 | // build as innerHTML where available |
68 | /** @ignore */ | 66 | /** @ignore */ |
69 | var createHtml = function(o){ | 67 | var createHtml = function(o){ |
70 | var b = ''; | 68 | var b = ''; |
71 | 69 | ||
72 | if(typeof(o['html']) != 'undefined') { | 70 | if(typeof(o['html']) != 'undefined') { |
73 | o['html'] = Clipperz.Base.sanitizeString(o['html']); | 71 | o['html'] = Clipperz.Base.sanitizeString(o['html']); |
74 | } else if (typeof(o['htmlString']) != 'undefined') { | 72 | } else if (typeof(o['htmlString']) != 'undefined') { |
75 | o['html'] = o['htmlString']; | 73 | o['html'] = o['htmlString']; |
76 | delete o.htmlString; | 74 | delete o.htmlString; |
77 | } | 75 | } |
78 | 76 | ||
79 | b += '<' + o.tag; | 77 | b += '<' + o.tag; |
80 | for(var attr in o){ | 78 | for(var attr in o){ |
81 | if(attr == 'tag' || attr == 'children' || attr == 'html' || typeof o[attr] == 'function') continue; | 79 | if(attr == 'tag' || attr == 'children' || attr == 'html' || typeof o[attr] == 'function') continue; |
82 | if(attr == 'style'){ | 80 | if(attr == 'style'){ |
83 | var s = o['style']; | 81 | var s = o['style']; |
84 | if(typeof s == 'function'){ | 82 | if(typeof s == 'function'){ |
85 | s = s.call(); | 83 | s = s.call(); |
86 | } | 84 | } |
87 | if(typeof s == 'string'){ | 85 | if(typeof s == 'string'){ |
88 | b += ' style="' + s + '"'; | 86 | b += ' style="' + s + '"'; |
89 | }else if(typeof s == 'object'){ | 87 | }else if(typeof s == 'object'){ |
90 | b += ' style="'; | 88 | b += ' style="'; |
91 | for(var key in s){ | 89 | for(var key in s){ |
92 | if(typeof s[key] != 'function'){ | 90 | if(typeof s[key] != 'function'){ |
93 | b += key + ':' + s[key] + ';'; | 91 | b += key + ':' + s[key] + ';'; |
94 | } | 92 | } |
95 | } | 93 | } |
96 | b += '"'; | 94 | b += '"'; |
97 | } | 95 | } |
98 | }else{ | 96 | }else{ |
99 | if(attr == 'cls'){ | 97 | if(attr == 'cls'){ |
100 | b += ' class="' + o['cls'] + '"'; | 98 | b += ' class="' + o['cls'] + '"'; |
101 | }else if(attr == 'htmlFor'){ | 99 | }else if(attr == 'htmlFor'){ |
102 | b += ' for="' + o['htmlFor'] + '"'; | 100 | b += ' for="' + o['htmlFor'] + '"'; |
103 | }else{ | 101 | }else{ |
104 | b += ' ' + attr + '="' + o[attr] + '"'; | 102 | b += ' ' + attr + '="' + o[attr] + '"'; |
105 | } | 103 | } |
106 | } | 104 | } |
107 | } | 105 | } |
108 | if(emptyTags.test(o.tag)){ | 106 | if(emptyTags.test(o.tag)){ |
109 | b += ' />'; | 107 | b += ' />'; |
110 | }else{ | 108 | }else{ |
111 | b += '>'; | 109 | b += '>'; |
112 | if(o.children){ | 110 | if(o.children){ |
113 | for(var i = 0, len = o.children.length; i < len; i++) { | 111 | for(var i = 0, len = o.children.length; i < len; i++) { |
114 | b += createHtml(o.children[i], b); | 112 | b += createHtml(o.children[i], b); |
115 | } | 113 | } |
116 | } | 114 | } |
117 | if(o.html){ | 115 | if(o.html){ |
118 | b += o.html; | 116 | b += o.html; |