|
1 | | -if (!m_helper) |
2 | | -{ |
3 | | - var m_helper = { |
4 | | - removeNode : function(id) { |
5 | | - var el = document.getElementById(id); |
6 | | - if (el) { |
7 | | - el.parentNode.removeChild(el); |
8 | | - } |
9 | | - }, |
10 | | - |
11 | | - insertAfter : function(item, target) { |
12 | | - var parent = target.parentNode; |
13 | | - if (target.nextElementSibling) { |
14 | | - parent.insertBefore(item, target.nextElementSibling); |
15 | | - } else { |
16 | | - parent.appendChild(item); |
17 | | - } |
18 | | - }, |
19 | | - |
20 | | - hide : function(element) { |
21 | | - element.style.display = 'none'; |
22 | | - }, |
23 | | - |
24 | | - hideAll : function(array) { |
25 | | - for(var i = 0; i< array.length; i++) { |
26 | | - this.hide(array[i]); |
27 | | - } |
28 | | - }, |
29 | | - |
30 | | - show : function(element) { |
31 | | - element.style.display = 'block'; |
32 | | - }, |
33 | | - |
34 | | - showAll : function(array) { |
35 | | - for(var i = 0; i< array.length; i++) { |
36 | | - this.show(array[i]); |
37 | | - } |
38 | | - }, |
39 | | - |
40 | | - parent : function(element, id) { |
41 | | - var parent = element.parentElement; |
42 | | - while (parent && parent.tagName != 'BODY') { |
43 | | - if (parent.id == id) { |
44 | | - return parent; |
45 | | - } |
46 | | - |
47 | | - parent = parent.parentElement; |
48 | | - } |
49 | | - |
50 | | - return null; |
51 | | - }, |
52 | | - |
53 | | - //data : { tag, id, class, attributes : { key : value }, data : { key : value } } |
54 | | - create : function(data) { |
55 | | - var result = document.createElement(data.tag); |
56 | | - if (data.id) { |
57 | | - result.id = data.id; |
58 | | - } |
59 | | - |
60 | | - if (data.class) { |
61 | | - result.className = data.class; |
62 | | - } |
63 | | - |
64 | | - if (data.attributes) { |
65 | | - for(var prop in data.attributes) { |
66 | | - result.setAttribute(prop, data.attributes[prop]); |
67 | | - } |
68 | | - } |
69 | | - |
70 | | - if (data.data) { |
71 | | - for(var prop in data.data) { |
72 | | - result.dataset[prop] = data.data[prop]; |
73 | | - } |
74 | | - } |
75 | | - |
76 | | - return result; |
77 | | - }, |
78 | | - |
79 | | - div : function(data) { |
80 | | - if (!data) { |
81 | | - data = new Object(); |
82 | | - } |
83 | | - |
84 | | - data.tag = 'div'; |
85 | | - return this.create(data); |
86 | | - }, |
87 | | - |
88 | | - label : function(data) { |
89 | | - if (!data) { |
90 | | - data = new Object(); |
91 | | - } |
92 | | - |
93 | | - data.tag = 'label'; |
94 | | - return this.create(data); |
95 | | - }, |
96 | | - |
97 | | - textField : function(data) { |
98 | | - if (!data) { |
99 | | - data = new Object(); |
100 | | - } |
101 | | - |
102 | | - data.tag = 'input'; |
103 | | - if (!data.attributes) |
104 | | - data.attributes = new Object(); |
105 | | - |
106 | | - data.attributes.type = 'text'; |
107 | | - |
108 | | - return this.create(data); |
109 | | - }, |
110 | | - |
111 | | - checkbox : function(data) { |
112 | | - if (!data) { |
113 | | - data = new Object(); |
114 | | - } |
115 | | - |
116 | | - data.tag = 'input'; |
117 | | - if (!data.attributes) |
118 | | - data.attributes = new Object(); |
119 | | - |
120 | | - data.attributes.type = 'checkbox'; |
121 | | - |
122 | | - return this.create(data); |
123 | | - }, |
124 | | - |
125 | | - each : function(array, handler) { |
126 | | - for(var i = 0; i< array.length; i++) { |
127 | | - handler(array[i]); |
128 | | - } |
129 | | - }, |
130 | | - |
131 | | - setActive : function(element) { |
132 | | - element.classList.add('active'); |
133 | | - }, |
134 | | - |
135 | | - setUnactive : function(element) { |
136 | | - element.classList.remove('active'); |
137 | | - }, |
138 | | - |
139 | | - select :function (element) { |
140 | | - element.selected = true; |
141 | | - element.setAttribute('selected', 'selected'); |
142 | | - }, |
143 | | - |
144 | | - deselect : function (element) { |
145 | | - element.selected = false; |
146 | | - element.removeAttribute('selected'); |
147 | | - }, |
148 | | - |
149 | | - check : function(element) { |
150 | | - element.checked = true; |
151 | | - }, |
152 | | - |
153 | | - uncheck : function(element) { |
154 | | - element.checked = false; |
155 | | - }, |
156 | | - |
157 | | - click : function(element) { |
158 | | - if (element.fireEvent) { |
159 | | - el.fireEvent('onclick'); |
160 | | - } else { |
161 | | - var evObj = document.createEvent('Events'); |
162 | | - evObj.initEvent('click', true, false); |
163 | | - element.dispatchEvent(evObj); |
164 | | - } |
165 | | - }, |
166 | | - setDisabled: function(element, value) { |
167 | | - element.disabled = value; |
168 | | - }, |
169 | | - }; |
170 | | -} |
| 1 | +if (!m_helper) |
| 2 | +{ |
| 3 | + var m_helper = { |
| 4 | + removeNode : function(id) { |
| 5 | + var el = document.getElementById(id); |
| 6 | + if (el) { |
| 7 | + el.parentNode.removeChild(el); |
| 8 | + } |
| 9 | + }, |
| 10 | + |
| 11 | + insertAfter : function(item, target) { |
| 12 | + var parent = target.parentNode; |
| 13 | + if (target.nextElementSibling) { |
| 14 | + parent.insertBefore(item, target.nextElementSibling); |
| 15 | + } else { |
| 16 | + parent.appendChild(item); |
| 17 | + } |
| 18 | + }, |
| 19 | + |
| 20 | + hide : function(element) { |
| 21 | + element.style.display = 'none'; |
| 22 | + }, |
| 23 | + |
| 24 | + hideAll : function(array) { |
| 25 | + for(var i = 0; i< array.length; i++) { |
| 26 | + this.hide(array[i]); |
| 27 | + } |
| 28 | + }, |
| 29 | + |
| 30 | + show : function(element) { |
| 31 | + element.style.display = 'block'; |
| 32 | + }, |
| 33 | + |
| 34 | + showAll : function(array) { |
| 35 | + for(var i = 0; i< array.length; i++) { |
| 36 | + this.show(array[i]); |
| 37 | + } |
| 38 | + }, |
| 39 | + |
| 40 | + parent : function(element, id) { |
| 41 | + var parent = element.parentElement; |
| 42 | + while (parent && parent.tagName != 'BODY') { |
| 43 | + if (parent.id == id) { |
| 44 | + return parent; |
| 45 | + } |
| 46 | + |
| 47 | + parent = parent.parentElement; |
| 48 | + } |
| 49 | + |
| 50 | + return null; |
| 51 | + }, |
| 52 | + |
| 53 | + //data : { tag, id, class, attributes : { key : value }, data : { key : value } } |
| 54 | + create : function(data) { |
| 55 | + var result = document.createElement(data.tag); |
| 56 | + if (data.id) { |
| 57 | + result.id = data.id; |
| 58 | + } |
| 59 | + |
| 60 | + if (data.class) { |
| 61 | + result.className = data.class; |
| 62 | + } |
| 63 | + |
| 64 | + if (data.attributes) { |
| 65 | + for(var prop in data.attributes) { |
| 66 | + result.setAttribute(prop, data.attributes[prop]); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + if (data.data) { |
| 71 | + for(var prop in data.data) { |
| 72 | + result.dataset[prop] = data.data[prop]; |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + return result; |
| 77 | + }, |
| 78 | + |
| 79 | + div : function(data) { |
| 80 | + if (!data) { |
| 81 | + data = new Object(); |
| 82 | + } |
| 83 | + |
| 84 | + data.tag = 'div'; |
| 85 | + return this.create(data); |
| 86 | + }, |
| 87 | + |
| 88 | + label : function(data) { |
| 89 | + if (!data) { |
| 90 | + data = new Object(); |
| 91 | + } |
| 92 | + |
| 93 | + data.tag = 'label'; |
| 94 | + return this.create(data); |
| 95 | + }, |
| 96 | + |
| 97 | + textField : function(data) { |
| 98 | + if (!data) { |
| 99 | + data = new Object(); |
| 100 | + } |
| 101 | + |
| 102 | + data.tag = 'input'; |
| 103 | + if (!data.attributes) |
| 104 | + data.attributes = new Object(); |
| 105 | + |
| 106 | + data.attributes.type = 'text'; |
| 107 | + |
| 108 | + return this.create(data); |
| 109 | + }, |
| 110 | + |
| 111 | + checkbox : function(data) { |
| 112 | + if (!data) { |
| 113 | + data = new Object(); |
| 114 | + } |
| 115 | + |
| 116 | + data.tag = 'input'; |
| 117 | + if (!data.attributes) |
| 118 | + data.attributes = new Object(); |
| 119 | + |
| 120 | + data.attributes.type = 'checkbox'; |
| 121 | + |
| 122 | + return this.create(data); |
| 123 | + }, |
| 124 | + |
| 125 | + each : function(array, handler) { |
| 126 | + for(var i = 0; i< array.length; i++) { |
| 127 | + handler(array[i]); |
| 128 | + } |
| 129 | + }, |
| 130 | + |
| 131 | + setActive : function(element) { |
| 132 | + element.classList.add('active'); |
| 133 | + }, |
| 134 | + |
| 135 | + setUnactive : function(element) { |
| 136 | + element.classList.remove('active'); |
| 137 | + }, |
| 138 | + |
| 139 | + select :function (element) { |
| 140 | + element.selected = true; |
| 141 | + element.setAttribute('selected', 'selected'); |
| 142 | + }, |
| 143 | + |
| 144 | + deselect : function (element) { |
| 145 | + element.selected = false; |
| 146 | + element.removeAttribute('selected'); |
| 147 | + }, |
| 148 | + |
| 149 | + check : function(element) { |
| 150 | + element.checked = true; |
| 151 | + }, |
| 152 | + |
| 153 | + uncheck : function(element) { |
| 154 | + element.checked = false; |
| 155 | + }, |
| 156 | + |
| 157 | + click : function(element) { |
| 158 | + if (element.fireEvent) { |
| 159 | + el.fireEvent('onclick'); |
| 160 | + } else { |
| 161 | + var evObj = document.createEvent('Events'); |
| 162 | + evObj.initEvent('click', true, false); |
| 163 | + element.dispatchEvent(evObj); |
| 164 | + } |
| 165 | + }, |
| 166 | + setDisabled: function(element, value) { |
| 167 | + element.disabled = value; |
| 168 | + }, |
| 169 | + }; |
| 170 | +} |
0 commit comments