@joyzl/eno 1.1.6 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1,6 +1,5 @@
1
- // HTML5 Node Element
2
- // Easy Node Object
3
1
  // 提供HTML标签元素处理与数据对象之间的互操作支持。
2
+ // 用于简化 HTMLElement 与 JS JSON/Object 之间的互操作。
4
3
 
5
4
  export default {
6
5
  create,
@@ -14,7 +13,9 @@ export default {
14
13
  hide,
15
14
  toggle,
16
15
 
16
+ get,
17
17
  gets,
18
+ set,
18
19
  sets,
19
20
 
20
21
  bind,
@@ -26,62 +27,81 @@ export default {
26
27
  }
27
28
 
28
29
  // 这个临时标签用于解析HTML字符串
29
- const TEMP = document.createElement("div");
30
+ const TEMPLATE = document.createElement("template");
30
31
 
31
32
  /**
32
33
  * HTML字符串创建标签元素实例
33
- * @param {String} html HTML字符串
34
- * @return {Element} 创建的单个/多个标签元素
34
+ * @example eno.create(html);
35
+ * @param {String|HTMLElement} html 要创建为标签元素实例的HTML字符串
36
+ * @return {HTMLElement|HTMLElement[]|null} 创建的单个或多个标签元素
35
37
  */
36
38
  function create(html) {
37
- // 创建元素
38
- TEMP.innerHTML = html;
39
- let element;
40
- if (TEMP.childElementCount == 1) {
41
- element = TEMP.children[0];
42
- element.remove();
43
- } else
44
- if (TEMP.childElementCount > 1) {
45
- element = new Array();
46
- do {
47
- element.push(TEMP.children[0]);
48
- TEMP.children[0].remove();
49
- } while (TEMP.childElementCount > 0);
50
- }
51
- return element;
52
-
53
39
  // DocumentFragment
40
+ // 插入文档即便多个标签也仅触发一次重渲染
41
+ // 插入后实例为空集合
42
+ // Element.innerHTML
43
+
44
+ if (html) {
45
+ if (html.trim) {
46
+ // 创建新元素
47
+ TEMPLATE.innerHTML = html;
48
+ if (TEMPLATE.content.childElementCount == 1) {
49
+ return TEMPLATE.content.firstElementChild;
50
+ } else
51
+ if (TEMPLATE.content.childElementCount > 1) {
52
+ return Array.from(TEMPLATE.content.children);
53
+ }
54
+ } else
55
+ if (html.tagName) {
56
+ // 已为元素实例
57
+ // 添加到临时集合以便渲染
58
+ TEMPLATE.innerHTML = "";
59
+ TEMPLATE.appendChild(html);
60
+ return html;
61
+ } else
62
+ if (html instanceof DocumentFragment) {
63
+ // 已为元素实例
64
+ // 添加到临时集合以便渲染
65
+ TEMPLATE.innerHTML = "";
66
+ TEMPLATE.appendChild(html);
67
+ return Array.from(TEMPLATE.content.children);
68
+ }
69
+ }
70
+ return null;
54
71
  }
55
72
 
56
73
  /**
57
74
  * 创建并添加标签元素
58
- * @param {Element} element 标签元素
59
- * @param {String} html HTML字符串
60
- * @return {Element} 创建的单个/多个标签元素
75
+ * @param {HTMLElement} element 父标签元素
76
+ * @param {String} selector 选择器字符串
77
+ * @param {HTMLElement|String} html 要添加的标签元素实例或HTML字符串
78
+ * @return {HTMLElement|HTMLElement[]|null} 创建的单个/多个标签元素/null
79
+ * @example eno.append(html); //添加到文档尾部
80
+ * @example eno.append(element,html); // 添加到指定标签尾部
81
+ * @example eno.append(element,selector,html); // 添加到指定标签中匹配选择器的标签尾部
61
82
  */
62
- function append(element, html) {
83
+ function append(element, selector, html) {
63
84
  if (arguments.length == 1) {
64
85
  // append(html);
65
- html = element;
86
+ html = create(element);
66
87
  element = document.body;
67
88
  } else
68
89
  if (arguments.length == 2) {
90
+ // append(element,selector); 无效
69
91
  // append(element,html);
70
92
  element = select(element);
93
+ html = create(selector);
94
+ } else
95
+ if (arguments.length == 3) {
96
+ // append(element,selector,html)
97
+ element = select(element, selector);
98
+ html = create(html);
71
99
  } else {
72
100
  return null;
73
101
  }
74
- if (element) {
75
- if (html.trim) {
76
- html = create(html);
77
- }
78
- if (Array.isArray(html)) {
79
- for (let i = 0; i < html.length; i++) {
80
- element.appendChild(html[i]);
81
- }
82
- } else {
83
- element.appendChild(html);
84
- }
102
+
103
+ if (element && html) {
104
+ element.appendChild(TEMPLATE.content);
85
105
  return html;
86
106
  }
87
107
  return null;
@@ -89,673 +109,741 @@ function append(element, html) {
89
109
 
90
110
  /**
91
111
  * 创建并替换为标签元素
92
- * @param {Element} element 标签元素
93
- * @param {String} html HTML字符串
94
- * @return {Element} 创建的单个/多个标签元素
112
+ * @param {HTMLElement} element 目标标签元素
113
+ * @param {String} selector 选择器字符串
114
+ * @param {HTMLElement|String} html 用于替换的标签元素或HTML字符串
115
+ * @return {HTMLElement|HTMLElement[]|null} 创建的单个/多个标签元素/null
116
+ * @example eno.replace(element,html);
117
+ * @example eno.replace(element,selector,html);
95
118
  */
96
- function replace(element, html) {
119
+ function replace(element, selector, html) {
97
120
  if (arguments.length == 2) {
121
+ // replace(element,html);
98
122
  element = select(element);
123
+ html = create(selector);
124
+ } else
125
+ if (arguments.length == 3) {
126
+ // replace(element,selector,html);
127
+ element = select(element, selector);
128
+ html = create(html);
99
129
  } else {
100
130
  return null;
101
131
  }
102
- if (element) {
103
- if (html.trim) {
104
- html = create(html);
105
- }
106
- if (element.parentElement) {
107
- if (Array.isArray(html)) {
108
- let item;
109
- for (let i = 0; i < html.length; i++) {
110
- item = html[i];
111
- if (element.className) {
112
- item.className += " " + element.className;
113
- }
114
- if (element.style.cssText) {
115
- item.style.cssText += element.style.cssText;
116
- }
117
- }
118
- element.replaceWith(html);
119
- } else {
120
- if (element.className) {
121
- html.className += " " + element.className;
122
- }
132
+
133
+ if (element && html) {
134
+ // 转移属性
135
+ if (Array.isArray(html)) {
136
+ for (let i = 0; i < html.length; i++) {
137
+ // TODO 需要测试验证
138
+ html[i].classList.add(element.classList);
123
139
  if (element.style.cssText) {
124
- html.style.cssText += element.style.cssText;
140
+ html[i].style.cssText += element.style.cssText;
125
141
  }
126
- element.parentElement.replaceChild(html, element);
142
+ }
143
+ } else {
144
+ // TODO 需要测试验证
145
+ html.classList.add(element.classList);
146
+ if (element.style.cssText) {
147
+ html.style.cssText += element.style.cssText;
127
148
  }
128
149
  }
150
+ element.replaceWith(TEMPLATE.content);
129
151
  return html;
130
152
  }
131
153
  return null;
132
154
  }
133
155
 
134
156
  /**
135
- * 在指定范围内/整个文档查找
136
- * @param {Element} element 标签元素
137
- * @param {String} selector 筛选字符
138
- * @return {Element} 匹配的单个标签元素
157
+ * 在指定范围内/整个文档查找标签元素
158
+ * @example eno.select(selector);
159
+ * @example eno.select(element,selector);
160
+ * @param {HTMLElement} element 要在其中查找的父标签元素
161
+ * @param {String} selector 选择器字符串
162
+ * @return {HTMLElement|null} 匹配的单个标签元素,如果匹配多个仅返回第一个
139
163
  */
140
164
  function select(element, selector) {
141
165
  if (arguments.length == 1) {
142
166
  // 仅指定1个参数
143
- // select(element/selector);
167
+ // select(element);
168
+ if (element.tagName) {
169
+ return element;
170
+ } else
144
171
  if (element.trim) {
145
- element = document.querySelectorAll(element);
146
- if (element.length == 0) {
147
- return null;
148
- }
149
- if (element.length == 1) {
150
- return element[0];
151
- }
152
- return Array.from(element);
172
+ return document.querySelector(element);
153
173
  } else
154
- if (element.nodeType) {
155
- return element;
174
+ if (element.length) {
175
+ // NodeList,HTMLCollection
176
+ return element[0];
156
177
  }
157
178
  } else
158
179
  if (arguments.length == 2) {
159
180
  // 指定了2个参数
160
181
  // select(element, selector);
161
- if (element.trim) {
162
- element = document.querySelectorAll(element);
163
- if (element.length == 0) {
164
- return null;
165
- }
166
- } else
167
- if (element.nodeType) {
168
- element = element.querySelectorAll(selector);
169
- if (element.length == 0) {
170
- return null;
171
- }
172
- if (element.length == 1) {
173
- return element[0];
174
- }
175
- return Array.from(element);
182
+ if (element.tagName) {
183
+ return element.querySelector(selector);
176
184
  } else
177
- if (Array.isArray(element)) {
178
- if (element.length == 0) {
179
- return null;
180
- }
181
- }
182
- // element[]
183
- let nodes, items = new Array();
184
- for (let i = 0; i < element.length; i++) {
185
- nodes = element[i].querySelectorAll(selector);
186
- for (let n = 0; n < nodes.length; n++) {
187
- items.push(nodes[n]);
185
+ if (element.trim) {
186
+ element = document.querySelector(element);
187
+ if (element) {
188
+ return element.querySelector(selector);
188
189
  }
189
190
  }
190
- if (items.length == 0) {
191
- return null;
192
- }
193
- if (items.length == 1) {
194
- return items[0];
195
- }
196
- return items;
191
+ // 不支持element参数为数组或集合
192
+ // 应用场景极少且让程序难以理解
197
193
  }
194
+ return null;
198
195
  }
199
196
 
200
197
  /**
201
- * 在指定范围内/整个文档查找
202
- * @param {Element} element 标签元素
203
- * @param {String} selector 筛选字符
204
- * @return {[Element]} 匹配的多个标签元素
198
+ * 在指定范围内/整个文档查找标签元素
199
+ * @example eno.selects(selector);
200
+ * @example eno.selects(element,selector);
201
+ * @param {HTMLElement} element 要在其中查找的父标签元素
202
+ * @param {String} selector 选择器字符串
203
+ * @return {HTMLElement[]|null} 匹配的多个标签元素,仅匹配一个也返回数组
205
204
  */
206
205
  function selects(element, selector) {
207
206
  if (arguments.length == 1) {
208
207
  // 仅指定1个参数
209
- // selects(element/selector);
208
+ // selects(selector);
209
+ if (element.tagName) {
210
+ // 仅提供元素参数
211
+ return [element];
212
+ } else
210
213
  if (element.trim) {
211
214
  // 仅提供字符串参数
212
215
  element = document.querySelectorAll(element);
213
- if (element.length == 0) {
214
- return null;
216
+ if (element.length > 0) {
217
+ return Array.from(element);
215
218
  }
216
- return Array.from(element);
217
219
  } else
218
- if (element.nodeType) {
219
- // 仅提供元素参数
220
- return [element];
220
+ if (element.length) {
221
+ // NodeList,HTMLCollection
222
+ return Array.from(element);
221
223
  }
222
224
  } else
223
225
  if (arguments.length == 2) {
224
226
  // 指定了2个参数
225
227
  // select(element, selector);
226
- if (element.trim) {
227
- element = document.querySelectorAll(element);
228
- if (element.length == 0) {
229
- return null;
230
- }
231
- } else
232
- if (element.nodeType) {
228
+ if (element.tagName) {
233
229
  element = element.querySelectorAll(selector);
234
- if (element.length == 0) {
235
- return null;
230
+ if (element.length > 0) {
231
+ return Array.from(element);
236
232
  }
237
- return Array.from(element);
238
233
  } else
239
- if (Array.isArray(element)) {
240
- if (element.length == 0) {
241
- return null;
242
- }
243
- // element[]
244
- let nodes, items = new Array();
245
- for (let i = 0; i < element.length; i++) {
246
- nodes = element[i].querySelectorAll(selector);
247
- for (let n = 0; n < nodes.length; n++) {
248
- items.push(nodes[n]);
234
+ if (element.trim) {
235
+ element = document.querySelector(element);
236
+ if (element) {
237
+ element = element.querySelectorAll(selector);
238
+ if (element.length > 0) {
239
+ return Array.from(element);
249
240
  }
250
241
  }
251
- if (items.length == 0) {
252
- return null;
253
- }
254
- return items;
255
242
  }
243
+ // 不支持element参数为数组或集合
244
+ // 应用场景极少且让程序难以理解
256
245
  }
246
+ return null;
257
247
  }
258
248
 
259
249
  /**
260
- * 从文档移除
261
- * @param {Element} element 标签元素
262
- * @param {String} selector 筛选字符
263
- * @return {Element} 移除的单个/多个标签元素
250
+ * 从文档移除标签元素
251
+ * @param {HTMLElement} element 要在其中查找的父标签元素
252
+ * @param {String} selector 选择器字符串
264
253
  */
265
254
  function remove(element, selector) {
266
255
  if (arguments.length == 1) {
267
- element = select(element);
256
+ element = selects(element);
268
257
  } else
269
258
  if (arguments.length == 2) {
270
- element = select(element, selector);
259
+ element = selects(element, selector);
271
260
  } else {
272
261
  return;
273
262
  }
274
- if (element) {
275
- if (Array.isArray(element)) {
276
- for (let i = 0; i < element.length; i++) {
277
- element[i].remove();
278
- }
279
- } else {
280
- element.remove();
263
+
264
+ if (element && element.length) {
265
+ for (let i = 0; i < element.length; i++) {
266
+ element[i].remove();
281
267
  }
282
268
  }
283
- return element;
284
269
  }
285
270
 
286
271
  /**
287
- * 隐藏单个/多个元素
288
- * @param {Element} element 标签元素
289
- * @param {String} selector 筛选字符
290
- * @return {Element} 隐藏的单个/多个标签元素
272
+ * 隐藏标签元素
273
+ * @param {HTMLElement} element 要在其中查找的父标签元素
274
+ * @param {String} selector 选择器字符串
291
275
  */
292
276
  function hide(element, selector) {
293
277
  if (arguments.length == 1) {
294
- element = select(element);
278
+ element = selects(element);
295
279
  } else
296
280
  if (arguments.length == 2) {
297
- element = select(element, selector);
281
+ element = selects(element, selector);
298
282
  } else {
299
283
  return;
300
284
  }
301
- if (element) {
302
- if (Array.isArray(element)) {
303
- let e;
304
- for (let i = 0; i < element.length; i++) {
305
- e = element[i];
306
- if (e.hidden) {} else {
307
- e.hidden = true;
308
- e.__DISPLAY = e.style.display
309
- e.style.display = "none";
310
- }
311
- }
312
- } else {
313
- if (element.hidden) {} else {
314
- element.hidden = true;
315
- element.__DISPLAY = element.style.display;
316
- // display:flex 导致 hidden 属性失效而不会隐藏
317
- element.style.display = "none";
318
- }
285
+
286
+ if (element && element.length) {
287
+ for (let i = 0; i < element.length; i++) {
288
+ hideElement(element[i]);
319
289
  }
320
290
  }
321
- return element;
322
291
  }
323
292
 
324
293
  /**
325
- * 显示单个/多个元素
326
- * @param {Element} element 标签元素
327
- * @param {String} selector 筛选字符
328
- * @return {Element} 显示的单个/多个标签元素
294
+ * 显示标签元素
295
+ * @param {HTMLElement} element 要在其中查找的父标签元素
296
+ * @param {String} selector 选择器字符串
329
297
  */
330
298
  function show(element, selector) {
331
299
  if (arguments.length == 1) {
332
- element = select(element);
300
+ element = selects(element);
333
301
  } else
334
302
  if (arguments.length == 2) {
335
- element = select(element, selector);
303
+ element = selects(element, selector);
336
304
  } else {
337
305
  return;
338
306
  }
339
- if (element) {
340
- if (Array.isArray(element)) {
341
- let e;
342
- for (let i = 0; i < element.length; i++) {
343
- e = element[i];
344
- if (e.hidden) {
345
- e.hidden = false;
346
- e.style.display = e.__DISPLAY;
347
- }
348
- }
349
- } else
350
- if (element.hidden) {
351
- element.hidden = false;
352
- element.style.display = element.__DISPLAY;
307
+
308
+ if (element && element.length) {
309
+ for (let i = 0; i < element.length; i++) {
310
+ showElement(element[i]);
311
+ }
312
+ }
313
+ }
314
+
315
+ function hideElement(element) {
316
+ if (element.hidden) {
317
+ if (element.__ENO_DISPLAY !== undefined) {
318
+ return;
319
+ }
320
+ } else {
321
+ element.hidden = true;
322
+ }
323
+ // display:flex 导致 hidden 属性失效而不会隐藏
324
+ element.__ENO_DISPLAY = element.style.display;
325
+ element.style.display = "none";
326
+ }
327
+
328
+ function showElement(element) {
329
+ if (element.hidden) {
330
+ element.hidden = false;
331
+ if (element.__ENO_DISPLAY !== undefined) {
332
+ element.style.display = element.__ENO_DISPLAY;
353
333
  }
354
334
  }
355
- return element;
356
335
  }
357
336
 
358
337
  /**
359
338
  * 切换指定元素显示,同级其余元素隐藏;
360
- * 如果指定样式类名,则当前原始添加样式类,其余元素移除样式类
361
- * @param {Element} element 标签元素
362
- * @param {String} selector 筛选字符
363
- * @param {String} applyClass 添加类名称,必须同时提供otherClass参数
364
- * @param {String} otherClass 移除类名称,必须同时提供applyClass参数
365
- * @return {Element} 显示的单个/多个标签元素
339
+ * 如果指定样式类名,则当前元素添加样式类,其余元素移除样式类,样式类名区分大小写
340
+ * @param {HTMLElement} element 要在其中查找的父标签元素
341
+ * @param {String} selector 选择器字符串
342
+ * @param {String} applyClass 添加类名称,必须同时提供otherClass参数,可指定""/null表示无具体类名
343
+ * @param {String} otherClass 移除类名称,必须同时提供applyClass参数,可指定""/null表示无具体类名
344
+ * @return {HTMLElement|HTMLElement[]|null} 显示的单个/多个标签元素
366
345
  */
367
346
  function toggle(element, selector, applyClass, otherClass) {
368
347
  if (arguments.length == 1) {
369
348
  // toggle(element)
370
- element = select(element);
349
+ element = selects(element);
350
+ if (element) {
351
+ toggleElements(element);
352
+ return element;
353
+ }
371
354
  } else
372
355
  if (arguments.length == 2) {
373
356
  // toggle(element,selector)
374
- element = select(element, selector);
357
+ // toggle(element,applyClass) 无效
358
+ element = selects(element, selector);
359
+ if (element) {
360
+ toggleElements(element);
361
+ return element;
362
+ }
375
363
  } else
376
364
  if (arguments.length == 3) {
365
+ // toggle(element,selector,applyClass) 无效
377
366
  // toggle(element,applyClass,otherClass)
378
- element = select(element);
379
- otherClass = applyClass;
380
- applyClass = selector;
367
+ element = selects(element);
368
+ if (element) {
369
+ toggleClasss(element, selector, applyClass);
370
+ return element;
371
+ }
381
372
  } else
382
373
  if (arguments.length == 4) {
383
374
  // toggle(element,selector,applyClass,otherClass)
384
- element = select(element, selector);
385
- } else {
386
- return;
375
+ element = selects(element, selector);
376
+ if (element) {
377
+ toggleClasses(element, applyClass, otherClass);
378
+ return element;
379
+ }
387
380
  }
388
- if (element) {
389
- const parent = element.parentElement;
390
- if (applyClass) {
391
- for (let i = 0; i < parent.children.length; i++) {
392
- if (element == parent.children[i]) {
393
- parent.children[i].classList.remove(otherClass);
394
- parent.children[i].classList.add(applyClass);
395
- } else {
396
- parent.children[i].classList.remove(applyClass);
397
- parent.children[i].classList.add(otherClass);
381
+ return null;
382
+ }
383
+
384
+ function toggleElement(element) {
385
+ const parent = element.parentElement;
386
+ for (let i = 0; i < parent.children.length; i++) {
387
+ if (element !== parent.children[i]) {
388
+ hideElement(parent.children[i]);
389
+ }
390
+ }
391
+ showElement(element);
392
+ }
393
+
394
+ function toggleElements(elements) {
395
+ // 这些元素可能不在同级
396
+ let element, parent, i;
397
+ for (let e = 0; e < elements.length; e++) {
398
+ element = elements[e];
399
+ if (element.parentElement !== parent) {
400
+ parent = element.parentElement;
401
+ for (i = 0; i < parent.children.length; i++) {
402
+ if (element !== parent.children[i]) {
403
+ hideElement(parent.children[i]);
398
404
  }
399
405
  }
400
- } else {
401
- for (let i = 0; i < parent.children.length; i++) {
402
- if (element == parent.children[i]) {
403
- show(parent.children[i]);
404
- } else {
405
- hide(parent.children[i]);
406
+ }
407
+ showElement(element);
408
+ }
409
+ }
410
+
411
+ function toggleClass(element, apply, other) {
412
+ const parent = element.parentElement;
413
+ for (let i = 0; i < parent.children.length; i++) {
414
+ if (element !== parent.children[i]) {
415
+ parent.children[i].classList.remove(apply);
416
+ parent.children[i].classList.add(other);
417
+ }
418
+ }
419
+ element.classList.remove(other);
420
+ element.classList.add(apply);
421
+ }
422
+
423
+ function toggleClasses(elements, apply, other) {
424
+ // 这些元素可能不在同级
425
+ let element, parent, i;
426
+ for (let e = 0; e < elements.length; e++) {
427
+ element = elements[e];
428
+ if (element.parentElement !== parent) {
429
+ parent = element.parentElement;
430
+ for (i = 0; i < parent.children.length; i++) {
431
+ if (element !== parent.children[i]) {
432
+ parent.children[i].classList.remove(apply);
433
+ parent.children[i].classList.add(other);
406
434
  }
407
435
  }
408
436
  }
437
+ element.classList.remove(other);
438
+ element.classList.add(apply);
409
439
  }
410
- return element;
411
440
  }
412
441
 
413
442
  // 默认转换函数
414
- function defaultConverter(element, parameter, name) {}
443
+ function defaultConverter(element, entity, name) {}
415
444
 
416
445
  /**
417
- * 从指定元素获取值以JSON对象返回{name:value}
418
- * @param {Element} element 标签元素
419
- * @param {String} selector 筛选字符
420
- * @param {Function} converter 转换
421
- * @return {Object} {name1:value1,name2:value2,...}
446
+ * 从指定元素获取值以实体对象返回
447
+ * @param {HTMLElement} element 要在其中查找的父标签元素
448
+ * @param {String} selector 选择器字符串
449
+ * @param {Function} converter 转换方法
450
+ * @return {Object} 包含数据的实体对象实例
451
+ */
452
+ function get(element, selector, converter = defaultConverter) {
453
+ if (arguments.length == 1) {
454
+ // get(element)
455
+ // get(selector)
456
+ element = select(element);
457
+ } else
458
+ if (arguments.length == 2) {
459
+ // get(element,selector)
460
+ // get(element,converter)
461
+ if (selector instanceof Function) {
462
+ element = select(element);
463
+ converter = selector;
464
+ } else {
465
+ element = select(element, selector);
466
+ }
467
+ } else
468
+ if (arguments.length == 3) {
469
+ // get(element,selector,converter)
470
+ element = select(element, selector);
471
+ } else {
472
+ return null;
473
+ }
474
+
475
+ if (element) {
476
+ let entity = {};
477
+ getEntity(element, entity, converter);
478
+ return entity;
479
+ }
480
+ return null;
481
+ }
482
+
483
+ /**
484
+ * 从指定元素获取值以JSON对象返回
485
+ * @param {HTMLElement} element 要在其中查找的父标签元素
486
+ * @param {String} selector 选择器字符串
487
+ * @param {Function} converter 转换方法
488
+ * @return {Object[]} 包含数据的实体对象实例
422
489
  */
423
490
  function gets(element, selector, converter = defaultConverter) {
424
491
  if (arguments.length == 1) {
425
492
  // gets(element)
426
493
  // gets(selector)
427
- element = select(element);
494
+ element = selects(element);
428
495
  } else
429
496
  if (arguments.length == 2) {
430
497
  // gets(element,selector)
431
498
  // gets(element,converter)
432
- if (selector.trim) {
433
- element = select(element, selector);
434
- } else {
499
+ if (selector instanceof Function) {
435
500
  element = select(element);
436
501
  converter = selector;
502
+ } else {
503
+ element = selects(element, selector);
437
504
  }
438
505
  } else
439
506
  if (arguments.length == 3) {
440
507
  // gets(element,selector,converter)
441
- element = select(element, selector);
508
+ element = selects(element, selector);
442
509
  } else {
443
- return;
510
+ return null;
444
511
  }
512
+
445
513
  if (element) {
446
- if (Array.isArray(element)) {
447
- let parameter = {},
448
- parameters = new Array();
449
- for (let i = 0; i < element.length; i++) {
450
- get(element[i], parameter, converter);
451
- if (Object.keys(parameter).length) {
452
- parameters.push(parameter);
453
- parameter = {};
454
- }
455
- }
456
- return parameters;
457
- } else {
458
- let parameter = {};
459
- get(element, parameter, converter);
460
- return parameter;
514
+ let entity, entities = new Array();
515
+ for (let i = 0; i < element.length; i++) {
516
+ entity = {};
517
+ getEntity(element[i], entity, converter);
518
+ entities.push(entity);
461
519
  }
520
+ return entities;
462
521
  }
522
+ return null;
463
523
  }
464
524
 
465
525
  /**
466
- * 从指定JSON对象设置元素值,以name属性作为标识
467
- * @param {Element} element 标签元素
468
- * @param {String} selector 筛选字符
469
- * @param {Object} parameter 数据对象
470
- * @param {Function} converter 数据转换
471
- * @return {Element} 设置的单个/多个标签元素
526
+ * 实体对象设置到标签元素显示,以name属性作为标识
527
+ * @param {HTMLElement} element 要在其中查找的父标签元素
528
+ * @param {String} selector 选择器字符串
529
+ * @param {Object} entity 数据实体对象
530
+ * @param {Function} converter 数据转换方法
531
+ * @return {HTMLElement} 设置或创建的标签元素
472
532
  */
473
- function sets(element, selector, parameter, converter = defaultConverter) {
533
+ function set(element, selector, entity, converter = defaultConverter) {
534
+ // 仅对单个标签元素目标
535
+ // 多个标签元素目标难以理解
536
+
474
537
  if (arguments.length == 2) {
475
- // sets(element,parameter)
476
- // sets(selector,parameter)
538
+ // set(element,entity)
539
+ // set(selector,entity)
477
540
  element = select(element);
478
- parameter = selector;
541
+ entity = selector;
479
542
  } else
480
543
  if (arguments.length == 3) {
481
- // sets(element,selector,parameter)
482
- // sets(element,parameter,converter)
483
- if (selector.trim) {
484
- element = select(element, selector);
544
+ // set(element,selector,entity)
545
+ // set(element,entity,converter)
546
+ if (entity instanceof Function) {
547
+ element = select(element);
548
+ converter = entity;
549
+ entity = selector;
485
550
  } else {
551
+ element = select(element, selector);
552
+ }
553
+ } else
554
+ if (arguments.length == 4) {
555
+ // set(element,selector,entity,converter)
556
+ element = select(element, selector);
557
+ } else {
558
+ return null;
559
+ }
560
+
561
+ if (element) {
562
+ // Object -> Element
563
+ setEntity(element, entity, converter);
564
+ element.__ENO_ENTITY = entity;
565
+ return element;
566
+ }
567
+ }
568
+
569
+ /**
570
+ * 实体对象设置到标签元素显示,以name属性作为标识
571
+ * @param {HTMLElement} element 要在其中查找的父标签元素
572
+ * @param {String} selector 选择器字符串
573
+ * @param {Object} entity 数据实体对象
574
+ * @param {Function} converter 数据转换方法
575
+ * @return {HTMLElement} 设置或创建的标签元素
576
+ */
577
+ function sets(element, selector, entity, converter = defaultConverter) {
578
+ // 仅对单个标签元素目标
579
+ // 多个标签元素目标难以理解
580
+ // entity为数组时返回数组
581
+
582
+ if (arguments.length == 2) {
583
+ // sets(element,entity)
584
+ // sets(selector,entity)
585
+ element = select(element);
586
+ entity = selector;
587
+ } else
588
+ if (arguments.length == 3) {
589
+ // sets(element,selector,entity)
590
+ // sets(element,entity,converter)
591
+ if (entity instanceof Function) {
486
592
  element = select(element);
487
- converter = parameter;
488
- parameter = selector;
593
+ converter = entity;
594
+ entity = selector;
595
+ } else {
596
+ element = select(element, selector);
489
597
  }
490
598
  } else
491
599
  if (arguments.length == 4) {
492
- // sets(element,selector,parameter,converter)
600
+ // sets(element,selector,entity,converter)
493
601
  element = select(element, selector);
494
602
  } else {
495
- return;
603
+ return null;
496
604
  }
605
+
497
606
  if (element) {
498
- if (parameter) {
499
- if (Array.isArray(parameter)) {
500
- // Object[] -> Element.children
501
- let i = 0;
502
- // 利用ENO_SET记录并判定是否首次
503
- if (element.__ENO_SETS) {} else {
504
- element.__ENO_SETS = {};
505
- // before...<template>...after
506
- // 只有<template>模板具有content属性
507
- // 记录模板前后已有标签元素数量
508
- // before数量包括模板本身
509
- for (; i < element.childElementCount; i++) {
510
- if (element.children[i].content) {
511
- element.__ENO_SETS.template = element.children[i];
512
- element.__ENO_SETS.before = ++i;
513
- element.__ENO_SETS.after = element.childElementCount - i;
514
- break;
515
- }
607
+ // Object[] -> Element.children
608
+ let i = 0;
609
+ // 利用ENO_SET缓存模板并判定是否首次
610
+ if (element.__ENO_SETS === undefined) {
611
+ if (element.childElementCount) {
612
+ element.__ENO_SETS = {};
613
+ // 查找模块和位置
614
+ // before...<template>...after
615
+ // 只有<template>模板具有content属性
616
+ // 记录模板前后已有标签元素数量
617
+ // before数量包括模板本身
618
+ for (i = 0; i < element.childElementCount; i++) {
619
+ if (element.children[i].content) {
620
+ element.__ENO_SETS.fragment = element.children[i].content;
621
+ element.__ENO_SETS.before = ++i;
622
+ element.__ENO_SETS.after = element.childElementCount - i;
623
+ break;
516
624
  }
517
625
  }
518
-
519
- if (element.__ENO_SETS.template) {
520
- // 已定义模板
521
- if (parameter.length) {
522
- let node, n;
523
- // 构造填充元素
524
- for (i = 0; i < parameter.length; i++) {
525
- if (element.__ENO_SETS.before + i < element.childElementCount - element.__ENO_SETS.after) {
526
- // 重用已有元素
527
- for (n = 0; n < element.__ENO_SETS.template.content.childElementCount; n++) {
528
- node = element.children[element.__ENO_SETS.before + i + n];
529
- set(node, parameter[i], converter);
530
- node.userData = parameter[i];
531
- }
532
- } else {
533
- // 克隆新的元素(DocumentFragment)
534
- // node = element.template.content.cloneNode(true);
535
- node = document.importNode(element.__ENO_SETS.template.content, true);
536
- for (n = 0; n < node.childElementCount; n++) {
537
- set(node.children.item(n), parameter[i], converter);
538
- node.children.item(n).userData = parameter[i];
539
- }
540
- element.insertBefore(node, element.children[element.__ENO_SETS.before + i * node.childElementCount]);
541
- }
542
- }
543
- // 移除多余元素
544
- n = i * element.__ENO_SETS.template.content.childElementCount;
545
- i = element.__ENO_SETS.before + element.__ENO_SETS.after;
546
- while (element.childElementCount > i + n) {
547
- element.children[element.__ENO_SETS.before + n].remove();
548
- }
549
- return element;
550
- } else {
551
- // 移除多余元素
552
- i = element.__ENO_SETS.before + element.__ENO_SETS.after;
553
- while (element.childElementCount > i) {
554
- element.children[element.childElementCount - element.__ENO_SETS.after - 1].remove();
555
- }
556
- return element;
557
- }
558
- } else {
559
- // 未使用模板
560
- if (parameter.length) {
561
- let node;
562
- // 构造填充元素
563
- for (i = 0; i < parameter.length; i++) {
564
- if (i < element.childElementCount) {
565
- // 重用已有元素
566
- node = element.children[i];
567
- } else if (node) {
568
- // 克隆新的元素
569
- node = element.appendChild(node.cloneNode(true));
570
- } else {
571
- // 干不了
572
- // 此情形出现于没有任何子标签元素
573
- continue;
574
- }
575
- set(node, parameter[i], converter);
576
- node.userData = parameter[i];
577
- node.hidden = false;
578
- }
579
- // 移除多余元素
580
- while (element.childElementCount > i) {
581
- element.children[i].remove();
582
- }
583
- return element;
584
- } else {
585
- // 移除多余元素,保留模板
586
- element.children[0].userData = null;
587
- element.children[0].hidden = true;
588
- while (element.childElementCount > 1) {
589
- element.children[1].remove();
590
- }
591
- return element;
626
+ // 未定义模板<template>
627
+ // 子元素视为模板
628
+ if (element.__ENO_SETS.fragment === undefined) {
629
+ element.__ENO_SETS.fragment = new DocumentFragment();
630
+ while (element.childElementCount > 0) {
631
+ element.__ENO_SETS.fragment.appendChild(element.children[0]);
592
632
  }
633
+ element.__ENO_SETS.before = 0;
634
+ element.__ENO_SETS.after = 0;
593
635
  }
594
636
  } else {
595
- // Object -> Element
596
- if (Array.isArray(element)) {
597
- for (let i = 0; i < element.length; i++) {
598
- set(element[i], parameter, converter);
599
- element[i].userData = parameter;
637
+ // 没有可用模板
638
+ return null;
639
+ }
640
+ }
641
+ if (entity) {
642
+ if (!Array.isArray(entity)) {
643
+ entity = [entity];
644
+ }
645
+
646
+ let node, n;
647
+ // 构造填充元素
648
+ for (i = 0; i < entity.length; i++) {
649
+ if (element.__ENO_SETS.before + i < element.childElementCount - element.__ENO_SETS.after) {
650
+ // 重用已有元素
651
+ for (n = 0; n < element.__ENO_SETS.fragment.childElementCount; n++) {
652
+ node = element.children[element.__ENO_SETS.before + i + n];
653
+ setEntity(node, entity[i], converter);
654
+ node.__ENO_ENTITY = entity[i];
600
655
  }
601
656
  } else {
602
- set(element, parameter, converter);
603
- element.userData = parameter;
657
+ // 克隆新的元素(DocumentFragment)
658
+ node = element.fragment.cloneNode(true);
659
+ for (n = 0; n < node.childElementCount; n++) {
660
+ setEntity(node.children[n], entity[i], converter);
661
+ node.children[n].__ENO_ENTITY = entity[i];
662
+ }
663
+ element.insertBefore(node, element.children[element.__ENO_SETS.before + i * node.childElementCount]);
604
664
  }
605
- return element;
665
+ }
666
+ // 移除多余元素
667
+ n = i * element.__ENO_SETS.template.content.childElementCount;
668
+ i = element.__ENO_SETS.before + element.__ENO_SETS.after;
669
+ while (element.childElementCount > i + n) {
670
+ element.children[element.__ENO_SETS.before + n].remove();
606
671
  }
607
672
  } else {
608
673
  // null / undefine -> Element
609
- if (element.__ENO_SETS) {
610
- if (element.__ENO_SETS.template) {
611
- const i = element.__ENO_SETS.before + element.__ENO_SETS.after;
612
- while (element.childElementCount > i) {
613
- element.children[element.childElementCount - element.__ENO_SETS.after - 1].remove();
614
- }
615
- } else {
616
- element.children[0].userData = null;
617
- element.children[0].hidden = true;
618
- while (element.childElementCount > 1) {
619
- element.children[1].remove();
620
- }
621
- }
622
- } else {
623
- if (Array.isArray(element)) {
624
- for (let i = 0; i < element.length; i++) {
625
- set(element[i], null, converter);
626
- element[i].userData = null;
627
- }
628
- } else {
629
- set(element, null, converter);
630
- element.userData = null;
631
- }
674
+ i = element.__ENO_SETS.before + element.__ENO_SETS.after;
675
+ while (element.childElementCount > i) {
676
+ element.children[element.childElementCount - element.__ENO_SETS.after - 1].remove();
632
677
  }
633
- return element;
634
678
  }
679
+ return element;
635
680
  }
636
681
  }
637
682
 
638
683
  /**
639
- * 获取元素值
684
+ * 获取实体从标签元素
640
685
  * <input name="AAA" value="123"/>
641
686
  * <span name="AAA">123</span>
642
687
  * <img name="AAA" src="123"/>
643
688
  * <i case="AAA"></i>
644
689
  */
645
- function get(element, parameter, converter) {
690
+ function getEntity(element, entity, converter) {
646
691
  let name = element.getAttribute("case");
647
692
  if (name && name.length) {
648
- converter(element, parameter, name);
693
+ converter(element, entity, name);
649
694
  }
650
695
  name = element.getAttribute("name");
651
696
  if (name && name.length) {
652
697
  if (element.type) {
653
- valu(parameter, name, element.value);
698
+ // 所有控件具有type属性
699
+ if (!element.disabled) {
700
+ if (element.checked === undefined || element.checked) {
701
+ setValue(entity, name, element.value);
702
+ }
703
+ }
654
704
  } else
655
705
  if (element.src) {
656
- valu(parameter, name, element.src);
706
+ // img
707
+ setValue(entity, name, element.src);
657
708
  } else {
658
- valu(parameter, name, element.innerText);
709
+ setValue(entity, name, element.innerText);
659
710
  }
660
711
  }
661
712
  if (element.childElementCount) {
662
713
  for (let i = 0; i < element.children.length; i++) {
663
- get(element.children[i], parameter, converter);
714
+ getEntity(element.children[i], entity, converter);
664
715
  }
665
716
  }
666
717
  }
667
718
 
668
719
  /**
669
- * 设置元素值
720
+ * 设置实体到标签元素
670
721
  * <input name="AAA" value="123"/>
671
722
  * <span name="AAA">123</span>
672
723
  * <img name="AAA" src="123"/>
673
724
  * <i case="AAA"></i>
674
725
  */
675
- function set(element, parameter, converter) {
726
+ function setEntity(element, entity, converter) {
676
727
  let name = element.getAttribute("case");
677
728
  if (name && name.length) {
678
- converter(element, parameter, name);
729
+ converter(element, entity, name);
679
730
  }
680
731
  name = element.getAttribute("name");
681
732
  if (name && name.length) {
682
733
  if (element.type) {
683
- element.value = text(vale(parameter, name));
734
+ // 所有控件具有type属性
735
+ if (element.checked === undefined) {
736
+ // Radio / Check
737
+ element.checked = element.value == getValue(entity, name);
738
+ } else {
739
+ // OTHER
740
+ element.value = text(getValue(entity, name));
741
+ }
684
742
  } else
685
- if (element.src) {
686
- element.src = text(vale(parameter, name));
743
+ if (element.src !== undefined) {
744
+ // <img />
745
+ if (element.__ENO_SRC === undefined) {
746
+ // 记录默认图像
747
+ element.__ENO_SRC = element.src;
748
+ }
749
+ element.src = text(getValue(entity, name));
750
+ if (element.src.length == 0) {
751
+ element.src = element.__ENO_SRC;
752
+ }
687
753
  } else {
688
- element.innerText = text(vale(parameter, name));
754
+ if (element.__ENO_TEXT === undefined) {
755
+ // 原始内容作为默认值
756
+ element.__ENO_TEXT = element.innerText;
757
+ // 是否已有title
758
+ // 如果用于已设置title则不在自动设置
759
+ element.__ENO_TITLE = element.title ? false : true;
760
+ }
761
+ element.innerText = text(getValue(entity, name));
762
+ if (element.innerText.length == 0) {
763
+ element.innerText = element.__ENO_TEXT;
764
+ }
765
+ if (element.__ENO_TITLE) {
766
+ // 设置title实现文本提示
767
+ element.title = element.innerText;
768
+ }
689
769
  }
690
770
  }
691
771
  if (element.childElementCount) {
692
772
  for (let i = 0; i < element.children.length; i++) {
693
- set(element.children[i], parameter, converter);
773
+ setEntity(element.children[i], entity, converter);
694
774
  }
695
775
  }
696
776
  }
697
777
 
698
778
  /**
699
- * 根据名称获取对象值
700
- * @param {Object} o 对象
701
- * @param {Object} name 名称 "Device.Type.Text"
702
- * @returns {Object} value 值
779
+ * 根据名称获取实体对象值
780
+ * @param {Object} entity 要获取值的实体对象
781
+ * @param {Object} name 字段名称 "Device.Type.Text" 区分大小写
782
+ * @returns {Object} 获取的值
703
783
  */
704
- function vale(o, name) {
784
+ function getValue(entity, name) {
705
785
  name = name.split(".");
706
786
  for (let i = 0; i < name.length; i++) {
707
- if (o) {
708
- if (Array.isArray(o)) {
787
+ if (entity) {
788
+ if (Array.isArray(entity)) {
709
789
  const items = new Array();
710
- for (let a = 0; a < o.length; a++) {
711
- if (o[a]) {
712
- items.push(o[a][name[i]]);
790
+ for (let a = 0; a < entity.length; a++) {
791
+ if (entity[a]) {
792
+ items.push(entity[a][name[i]]);
713
793
  }
714
794
  }
715
- o = items;
795
+ entity = items;
716
796
  } else {
717
- o = o[name[i]];
797
+ entity = entity[name[i]];
718
798
  }
719
799
  } else {
720
800
  break;
721
801
  }
722
802
  }
723
- return o;
803
+ return entity;
724
804
  }
725
805
 
726
806
  /**
727
- * 根据名称设置对象值
728
- * @param {Object} o
729
- * @param {Object} name "Device.Type.Text"
730
- * @param {Object} value
807
+ * 根据名称设置实体对象值
808
+ * @param {Object} entity 要设置值的实体对象
809
+ * @param {Object} name 字段名称 "Device.Type.Text" 区分大小写
810
+ * @param {Object} value 要设置的值
731
811
  */
732
- function valu(o, name, value) {
812
+ function setValue(entity, name, value) {
733
813
  name = name.split(".");
734
814
  let i = 0;
735
815
  for (; i < name.length - 1; i++) {
736
- if (o) {
737
- if (o[name[i]]) {
738
- o = o[name[i]];
739
- } else {
740
- o = o[name[i]] = {};
741
- }
816
+ if (entity[name[i]]) {
817
+ entity = entity[name[i]];
818
+ } else {
819
+ entity = entity[name[i]] = {};
820
+ }
821
+ }
822
+ // 点语法最后的名称
823
+ name = name[i];
824
+ // 相同name多次出现应数组化
825
+ if (entity[name] === undefined) {
826
+ entity[name] = value;
827
+ } else {
828
+ if (Array.isArray(entity[name])) {
829
+ entity[name].push(value);
830
+ } else {
831
+ entity[name] = [entity[name], value];
742
832
  }
743
833
  }
744
- o[name[i]] = value;
745
- return o;
746
834
  }
747
835
 
748
836
  /**
749
837
  * 转换为字符串值
750
- * @param {Object} o
838
+ * @param {any} value
751
839
  */
752
- function text(o) {
753
- if (Array.isArray(o)) {
840
+ function text(value) {
841
+ if (Array.isArray(value)) {
754
842
  // 数组值合并(逗号分割)
755
- return o.join(',');
843
+ return value.join(',');
756
844
  }
757
- if (o != undefined) {
758
- return o.toString();
845
+ if (value !== undefined && value !== null) {
846
+ return value.toString();
759
847
  }
760
848
  return "";
761
849
  }
@@ -773,56 +861,57 @@ function text(o) {
773
861
  function bind(element, selector, eventName, listener) {
774
862
  if (arguments.length == 3) {
775
863
  // bind(element,eventName,listener);
776
- element = select(element);
864
+ element = selects(element);
777
865
  listener = eventName;
778
866
  eventName = selector;
779
867
  } else
780
868
  if (arguments.length == 4) {
781
869
  // bind(element,selector,eventName,listener);
782
- element = select(element, selector);
870
+ element = selects(element, selector);
783
871
  } else {
784
- return;
872
+ return null;
785
873
  }
786
- if (element) {
787
- if (Array.isArray(element)) {
788
- for (let i = 0; i < element.length; i++) {
789
- element[i].addEventListener(eventName, listener);
790
- }
791
- } else {
792
- element.addEventListener(eventName, listener);
874
+
875
+ if (element && element.length) {
876
+ for (let i = 0; i < element.length; i++) {
877
+ element[i].addEventListener(eventName, listener);
793
878
  }
879
+ return element;
794
880
  }
795
- return element;
881
+ return null;
796
882
  }
797
883
 
798
884
  /**
799
- * 根据事件或元素获取由sets关联的实体对象
885
+ * 根据事件或标签元素获取由eno.sets()对应的实体对象
886
+ * @param {Event|HTMLElement} e 事件或标签元素
887
+ * @param {String} selector 选择器字符串
888
+ * @return {Object} 标签元素对应的实体对象
800
889
  * @example entity(event);
801
890
  * @example entity(element);
802
891
  * @example entity(element,selector);
803
- * @return {Object} 标签元素关联的数据对象
804
892
  */
805
893
  function entity(e, selector) {
806
894
  if (arguments.length == 1) {
807
895
  // entity(event);
808
- if (e.nodeType) {
809
- e = e;
810
- } else
811
- if (e && e.target) {
896
+ if (e.target) {
812
897
  e = e.target;
813
898
  } else
814
- if (e && e.srcElement) {
899
+ if (e.srcElement) {
815
900
  e = e.srcElement;
901
+ } else {
902
+ e = select(e);
816
903
  }
817
904
  } else
818
905
  if (arguments.length == 2) {
819
906
  // entity(element,selector);
820
907
  e = select(e, selector);
908
+ } else {
909
+ return null;
821
910
  }
822
911
 
823
912
  while (e) {
824
- if (e.userData) {
825
- return e.userData;
913
+ if (e.__ENO_ENTITY) {
914
+ return e.__ENO_ENTITY;
826
915
  } else {
827
916
  e = e.parentElement;
828
917
  }
@@ -831,32 +920,40 @@ function entity(e, selector) {
831
920
  }
832
921
 
833
922
  /**
834
- * 根据事件获取绑定实体的元素
835
- * @param {Event} e
836
- * @return {Element} 标签元素关联的数据对象
923
+ * 根据事件或标签元素获取由eno.sets()对应标签元素
924
+ * @param {Event|HTMLElement} e 事件或标签元素
925
+ * @return {HTMLElement} 实体对象对应的标签元素
837
926
  */
838
927
  function element(e) {
839
- if (e && e.target) {
840
- e = e.target;
841
- } else
842
- if (e && e.srcElement) {
843
- e = e.srcElement;
844
- }
845
-
846
- while (e) {
847
- if (e.userData) {
848
- return e;
928
+ if (e) {
929
+ if (e.target) {
930
+ e = e.target;
931
+ } else
932
+ if (e.srcElement) {
933
+ e = e.srcElement;
849
934
  } else {
850
- e = e.parentElement;
935
+ e = select(e);
936
+ }
937
+
938
+ while (e) {
939
+ if (e.userData) {
940
+ return e;
941
+ } else {
942
+ e = e.parentElement;
943
+ }
851
944
  }
852
945
  }
853
946
  return null;
854
947
  }
855
948
 
856
949
  /**
857
- * 读取 URL 中的 Query String 参数值
950
+ * 获取 URL 中的 Query String 指定名称的参数值或包含所有参数的实体对象
951
+ * @param {String} url URL
858
952
  * @param {String} name 参数名
859
953
  * @return {String} 参数值
954
+ * @example eno.query(url);
955
+ * @example eno.query(name);
956
+ * @example eno.query(url,name);
860
957
  */
861
958
  function query(url, name) {
862
959
  if (arguments.length == 0) {
@@ -888,10 +985,13 @@ function query(url, name) {
888
985
  } else {
889
986
  return null;
890
987
  }
988
+ } else {
989
+ return null;
891
990
  }
892
991
 
893
992
  if (url) {
894
993
  if (name) {
994
+ // 查找指定参数值
895
995
  let start = url.indexOf(name);
896
996
  if (start >= 0) {
897
997
  start += name.length;
@@ -905,6 +1005,7 @@ function query(url, name) {
905
1005
  }
906
1006
  }
907
1007
  } else {
1008
+ // 获取所有参数值
908
1009
  // ?name1=value1&name2=value2
909
1010
  let start = 1;
910
1011
  let index = 1;
@@ -931,28 +1032,4 @@ function query(url, name) {
931
1032
  }
932
1033
  }
933
1034
  return null;
934
- }
935
-
936
- /**
937
- * 根据事件或元素获取属性指定的动作
938
- * @param {Event} e
939
- * @param {String} a
940
- * @deprecated 1.1.3
941
- */
942
- function action(e, a) {
943
- if (e.target) {
944
- e = e.target;
945
- } else
946
- if (e.srcElement) {
947
- e = e.srcElement;
948
- }
949
-
950
- while (e) {
951
- if (e.hasAttribute(a)) {
952
- return true;
953
- } else {
954
- e = e.parentElement;
955
- }
956
- }
957
- return false;
958
1035
  }