summaryrefslogtreecommitdiff
path: root/frontend/delta/js/Clipperz/DOM.js
Unidiff
Diffstat (limited to 'frontend/delta/js/Clipperz/DOM.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/delta/js/Clipperz/DOM.js134
1 files changed, 134 insertions, 0 deletions
diff --git a/frontend/delta/js/Clipperz/DOM.js b/frontend/delta/js/Clipperz/DOM.js
new file mode 100644
index 0000000..1d52a4b
--- a/dev/null
+++ b/frontend/delta/js/Clipperz/DOM.js
@@ -0,0 +1,134 @@
1/*
2
3Copyright 2008-2013 Clipperz Srl
4
5This file is part of Clipperz, the online password manager.
6For further information about its features and functionalities please
7refer to http://www.clipperz.com.
8
9* Clipperz is free software: you can redistribute it and/or modify it
10 under the terms of the GNU Affero General Public License as published
11 by the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14* Clipperz is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 See the GNU Affero General Public License for more details.
18
19* You should have received a copy of the GNU Affero General Public
20 License along with Clipperz. If not, see http://www.gnu.org/licenses/.
21
22*/
23
24if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
25if (typeof(Clipperz.DOM) == 'undefined') { Clipperz.DOM = {}; }
26
27Clipperz.DOM.VERSION = "0.1";
28Clipperz.DOM.NAME = "Clipperz.DOM";
29
30MochiKit.Base.update(Clipperz.DOM, {
31
32 //-------------------------------------------------------------------------
33
34 '__repr__': function () {
35 return "[" + this.NAME + " " + this.VERSION + "]";
36 },
37
38 //-------------------------------------------------------------------------
39
40 'toString': function () {
41 return this.__repr__();
42 },
43
44 //-------------------------------------------------------------------------
45
46 'selectOptionMatchingValue': function (aSelectElement, aValue, shouldUseCaseInsensitiveTest) {
47 var selectedOptionIndex;
48 var i, c;
49
50 selectedOptionIndex = -1;
51
52 c = aSelectElement.options.length;
53 for (i=0; (i<c) && (selectedOptionIndex == -1); i++) {
54 if (shouldUseCaseInsensitiveTest == true) {
55 if (aSelectElement.options[i].value.toLowerCase() == aValue.toLowerCase()) {
56 selectedOptionIndex = i;
57 }
58 } else {
59 if (aSelectElement.options[i].value == aValue) {
60 selectedOptionIndex = i;
61 }
62 }
63 }
64
65 if (selectedOptionIndex != -1) {
66 aSelectElement.selectedIndex = selectedOptionIndex;
67 }
68 },
69
70 //-------------------------------------------------------------------------
71
72 'setFormContents': function(aNode, someValues) {
73 var node;
74 var values;
75 var i, c;
76
77 values = {};
78 c = someValues[0].length;
79 for (i=0; i<c; i++) {
80 values[someValues[0][i]] = someValues[1][i];
81 }
82
83 // var m = MochiKit.Base;
84 // var self = MochiKit.DOM;
85 if (typeof(aNode) == "undefined" || aNode === null) {
86 node = MochiKit.DOM._document.body;
87 } else {
88 node = MochiKit.DOM.getElement(aNode);
89 }
90
91 MochiKit.Base.nodeWalk(node, function(aNode) {
92 var result;
93 var name;
94
95 result = null;
96 name = aNode.name;
97 if (MochiKit.Base.isNotEmpty(name) && (typeof(values[name]) != 'undefined')) {
98 var tagName;
99
100 tagName = aNode.tagName.toUpperCase();
101 if (tagName === "INPUT" && (aNode.type == "radio" || aNode.type == "checkbox")) {
102 aNode.checked = values[name];
103 } else if (tagName === "SELECT") {
104 if (aNode.type == "select-one") {
105 Clipperz.DOM.selectOptionMatchingValue(aNode, values[name]);
106 } else { //aNode.type == "select-multiple"
107 Clipperz.logWarning("### unhandled Select.type = 'select-multiple' condition");
108 }
109 } else if (tagName === "FORM" || tagName === "P" || tagName === "SPAN" || tagName === "DIV") {
110 result = aNode.childNodes;
111 } else {
112 aNode.value = values[name]
113 }
114 } else {
115 result = aNode.childNodes;
116 }
117
118 return result;
119 });
120 },
121
122 //-------------------------------------------------------------------------
123
124 'get': MochiKit.DOM.getElement,
125
126 //-------------------------------------------------------------------------
127
128 'Helper': Clipperz.YUI.DomHelper,
129
130 //-------------------------------------------------------------------------
131 __syntaxFix__: "syntax fix"
132
133});
134