@joyzl/eno 1.0.0 → 1.0.1
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 +120 -25
- package/package.json +1 -1
- package/publish.cmd +1 -0
package/index.js
CHANGED
@@ -11,14 +11,20 @@ export default {
|
|
11
11
|
query,
|
12
12
|
on,
|
13
13
|
|
14
|
-
toggle,
|
15
14
|
show,
|
16
15
|
hide,
|
16
|
+
stack,
|
17
|
+
toggle,
|
17
18
|
|
18
19
|
gets,
|
19
20
|
sets,
|
20
21
|
entity,
|
21
|
-
action
|
22
|
+
action,
|
23
|
+
element,
|
24
|
+
|
25
|
+
date,
|
26
|
+
time,
|
27
|
+
datetime
|
22
28
|
}
|
23
29
|
|
24
30
|
/**
|
@@ -62,14 +68,24 @@ function hide(element) {
|
|
62
68
|
/**
|
63
69
|
* 切换指定元素显示,其余元素隐藏
|
64
70
|
* @param {Object} parent 父级
|
65
|
-
* @param {Object} element
|
71
|
+
* @param {Object} element 当前元素
|
72
|
+
* @param {String} className 类名称
|
66
73
|
*/
|
67
|
-
function toggle(parent, element) {
|
74
|
+
function toggle(parent, element, className) {
|
68
75
|
if (arguments.length == 1) {
|
69
76
|
// toggle(element);
|
70
|
-
|
71
|
-
|
72
|
-
|
77
|
+
element = parent;
|
78
|
+
if (element.trim) {
|
79
|
+
element = select(element);
|
80
|
+
}
|
81
|
+
if (element.hidden) {
|
82
|
+
element.hidden = false;
|
83
|
+
} else {
|
84
|
+
element.hidden = true;
|
85
|
+
}
|
86
|
+
} else
|
87
|
+
if (arguments.length == 2) {
|
88
|
+
// toggle(parent,element);
|
73
89
|
if (parent.trim) {
|
74
90
|
parent = select(parent);
|
75
91
|
}
|
@@ -86,9 +102,20 @@ function toggle(parent, element) {
|
|
86
102
|
parent.children[i].hidden = true;
|
87
103
|
}
|
88
104
|
}
|
105
|
+
} else
|
106
|
+
if (arguments.length == 3) {
|
107
|
+
// toggle(parent,element,className);
|
108
|
+
|
89
109
|
}
|
90
110
|
}
|
91
111
|
|
112
|
+
function stack(parent, element, className) {
|
113
|
+
// 单选 增加class/移除其它
|
114
|
+
// 多选 增加class
|
115
|
+
// 增加 class
|
116
|
+
// 移除 class
|
117
|
+
}
|
118
|
+
|
92
119
|
/**
|
93
120
|
* 在指定元素内/整个文档查找标签
|
94
121
|
* @param {Element} element 元素内
|
@@ -418,12 +445,14 @@ function sets(element, parameter, converter = defaultConverter) {
|
|
418
445
|
// }
|
419
446
|
|
420
447
|
let i = 0;
|
448
|
+
// 利用ENO_SET记录并判定是否首次
|
421
449
|
if (element.ENO_SETS) {
|
422
450
|
element.ENO_SETS = element.ENO_SETS + 1;
|
423
451
|
} else {
|
424
452
|
element.ENO_SETS = 1;
|
425
453
|
// ...<template>...
|
426
454
|
for (; i < element.children.length; i++) {
|
455
|
+
// 只有<template>模板具有content属性
|
427
456
|
if (element.children[i].content) {
|
428
457
|
element.template = element.children[i];
|
429
458
|
element.a = ++i;
|
@@ -450,14 +479,12 @@ function sets(element, parameter, converter = defaultConverter) {
|
|
450
479
|
} else {
|
451
480
|
// 克隆新的元素(DocumentFragment)
|
452
481
|
node = element.template.content.cloneNode(true);
|
453
|
-
n =
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
node[n].userData = parameter[i];
|
458
|
-
set(node[n], parameter[i], converter);
|
459
|
-
node[n].hidden = false;
|
482
|
+
for (n = 0; n < node.childElementCount; n++) {
|
483
|
+
node.children.item(n).userData = parameter[i];
|
484
|
+
set(node.children.item(n), parameter[i], converter);
|
485
|
+
node.children.item(n).hidden = false;
|
460
486
|
}
|
487
|
+
element.insertBefore(node, element.children[element.a + i * node.childElementCount]);
|
461
488
|
}
|
462
489
|
}
|
463
490
|
// 移除多余元素
|
@@ -501,11 +528,13 @@ function sets(element, parameter, converter = defaultConverter) {
|
|
501
528
|
}
|
502
529
|
return element;
|
503
530
|
} else { // []
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
element.children
|
531
|
+
if (element.children.length) {
|
532
|
+
// 保留模板
|
533
|
+
element.children[0].hidden = true;
|
534
|
+
// 移除多余元素
|
535
|
+
while (element.children.length > 1) {
|
536
|
+
element.children[1].remove();
|
537
|
+
}
|
509
538
|
}
|
510
539
|
return element;
|
511
540
|
}
|
@@ -568,7 +597,7 @@ function get(element, parameter, converter) {
|
|
568
597
|
}
|
569
598
|
if (element.childElementCount) {
|
570
599
|
for (let i = 0; i < element.children.length; i++) {
|
571
|
-
get(element.children[i], parameter);
|
600
|
+
get(element.children[i], parameter, converter);
|
572
601
|
}
|
573
602
|
}
|
574
603
|
}
|
@@ -666,12 +695,22 @@ function text(o) {
|
|
666
695
|
/**
|
667
696
|
* 根据事件或元素获取由sets关联的实体对象
|
668
697
|
*/
|
669
|
-
function entity(e) {
|
670
|
-
if (
|
671
|
-
|
698
|
+
function entity(e, selector) {
|
699
|
+
if (arguments.length == 1) {
|
700
|
+
// entity(event);
|
701
|
+
if (e.nodeType) {
|
702
|
+
e = e;
|
703
|
+
} else
|
704
|
+
if (e && e.target) {
|
705
|
+
e = e.target;
|
706
|
+
} else
|
707
|
+
if (e && e.srcElement) {
|
708
|
+
e = e.srcElement;
|
709
|
+
}
|
672
710
|
} else
|
673
|
-
if (
|
674
|
-
|
711
|
+
if (arguments.length == 2) {
|
712
|
+
// entity(element,selector);
|
713
|
+
e = select(e, selector);
|
675
714
|
}
|
676
715
|
|
677
716
|
while (e) {
|
@@ -704,4 +743,60 @@ function action(e, a) {
|
|
704
743
|
}
|
705
744
|
}
|
706
745
|
return false;
|
746
|
+
}
|
747
|
+
/**
|
748
|
+
* 根据事件获取绑定实体的元素
|
749
|
+
* @param {Event} e
|
750
|
+
*/
|
751
|
+
function element(e) {
|
752
|
+
if (e && e.target) {
|
753
|
+
e = e.target;
|
754
|
+
} else
|
755
|
+
if (e && e.srcElement) {
|
756
|
+
e = e.srcElement;
|
757
|
+
}
|
758
|
+
|
759
|
+
while (e) {
|
760
|
+
if (e.userData) {
|
761
|
+
return e;
|
762
|
+
} else {
|
763
|
+
e = e.parentElement;
|
764
|
+
}
|
765
|
+
}
|
766
|
+
return null;
|
767
|
+
}
|
768
|
+
|
769
|
+
/**
|
770
|
+
* 2024-6-24
|
771
|
+
*/
|
772
|
+
function date() {
|
773
|
+
const now = new Date();
|
774
|
+
const year = now.getFullYear();
|
775
|
+
const month = (now.getMonth() + 1 /*月份从0开始,需要加1*/ ).toString().padStart(2, '0');
|
776
|
+
const day = (now.getDate()).toString().padStart(2, '0');
|
777
|
+
return `${year}-${month}-${day}`;
|
778
|
+
}
|
779
|
+
|
780
|
+
/**
|
781
|
+
* 10:28:12
|
782
|
+
*/
|
783
|
+
function time() {
|
784
|
+
const now = new Date();
|
785
|
+
const hours = now.getHours();
|
786
|
+
const minutes = now.getMinutes();
|
787
|
+
const seconds = now.getSeconds();
|
788
|
+
return `${hours}:${minutes}:${seconds}`;
|
789
|
+
}
|
790
|
+
/**
|
791
|
+
* 2024-6-24 10:28:12
|
792
|
+
*/
|
793
|
+
function datetime() {
|
794
|
+
const now = new Date();
|
795
|
+
const year = now.getFullYear();
|
796
|
+
const month = now.getMonth() + 1 /*月份从0开始,需要加1*/ ;
|
797
|
+
const day = now.getDate();
|
798
|
+
const hours = now.getHours();
|
799
|
+
const minutes = now.getMinutes();
|
800
|
+
const seconds = now.getSeconds();
|
801
|
+
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
707
802
|
}
|
package/package.json
CHANGED
package/publish.cmd
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
npm publish --access public
|