@whitesev/pops 4.2.0 → 4.2.2
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/dist/index.amd.js +169 -145
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +169 -145
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +169 -145
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +169 -145
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +169 -145
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +169 -145
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/Pops.d.ts +10 -10
- package/dist/types/src/types/PopsDOMUtilsEventType.d.ts +3 -3
- package/dist/types/src/utils/PopsDOMUtils.d.ts +11 -11
- package/package.json +1 -1
- package/src/types/PopsDOMUtilsEventType.d.ts +3 -3
- package/src/utils/PopsDOMUtils.ts +159 -138
package/dist/index.iife.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var pops = (function () {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
const version = "4.2.
|
|
4
|
+
const version = "4.2.2";
|
|
5
5
|
|
|
6
6
|
const GlobalConfig = {
|
|
7
7
|
config: {},
|
|
@@ -245,6 +245,24 @@ var pops = (function () {
|
|
|
245
245
|
},
|
|
246
246
|
};
|
|
247
247
|
|
|
248
|
+
/**
|
|
249
|
+
* 通用的CSS类名
|
|
250
|
+
*/
|
|
251
|
+
const PopsCommonCSSClassName = {
|
|
252
|
+
flexCenter: "pops-flex-items-center",
|
|
253
|
+
flexYCenter: "pops-flex-y-center",
|
|
254
|
+
flexXCenter: "pops-flex-x-center",
|
|
255
|
+
hide: "pops-hide",
|
|
256
|
+
hideImportant: "pops-hide-important",
|
|
257
|
+
noBorder: "pops-no-border",
|
|
258
|
+
noBorderImportant: "pops-no-border-important",
|
|
259
|
+
userSelectNone: "pops-user-select-none",
|
|
260
|
+
lineHeightCenter: "pops-line-height-center",
|
|
261
|
+
widthFill: "pops-width-fill",
|
|
262
|
+
textIsDisabled: "pops-text-is-disabled",
|
|
263
|
+
textIsDisabledImportant: "pops-text-is-disabled-important",
|
|
264
|
+
};
|
|
265
|
+
|
|
248
266
|
const OriginPrototype = {
|
|
249
267
|
Object: {
|
|
250
268
|
defineProperty: Object.defineProperty,
|
|
@@ -294,6 +312,30 @@ var pops = (function () {
|
|
|
294
312
|
},
|
|
295
313
|
};
|
|
296
314
|
|
|
315
|
+
const PopsSafeUtils = {
|
|
316
|
+
/**
|
|
317
|
+
* 获取安全的html
|
|
318
|
+
*/
|
|
319
|
+
getSafeHTML(text) {
|
|
320
|
+
if (window.trustedTypes) {
|
|
321
|
+
const policy = window.trustedTypes.createPolicy("safe-innerHTML", {
|
|
322
|
+
createHTML: (html) => html,
|
|
323
|
+
});
|
|
324
|
+
return policy.createHTML(text);
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
return text;
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
/**
|
|
331
|
+
* 设置安全的html
|
|
332
|
+
*/
|
|
333
|
+
setSafeHTML($el, text) {
|
|
334
|
+
// 创建 TrustedHTML 策略(需 CSP 允许)
|
|
335
|
+
$el.innerHTML = this.getSafeHTML(text);
|
|
336
|
+
},
|
|
337
|
+
};
|
|
338
|
+
|
|
297
339
|
const n$1="clientX",e$2="clientY",t$1=16,c$3="start",o$1="move",s$1="cancel",u$3="end",a$2="left",i$3="right",r$4="up",d$1="down",m$2={4:"start",5:"move",1:"end",3:"cancel"};function v$1(n){return m$2[n]}function b(n,e,t){const c={1:{0:{move:4},4:{move:5,end:1,cancel:3},5:{move:5,end:1,cancel:3}},0:{4:{move:2,end:1,cancel:3},5:{start:2,move:2,end:1,cancel:3}}}[Number(n)][e];return void 0!==c&&c[t]||0}function g$1(n){[1,3,2].includes(n.state)&&(n.state=0);}function h$3(n){return [5,1,3].includes(n)}function j(n){if(n.disabled)return n.state=0,true}function O(n,e){return Object.assign(Object.assign(Object.assign({},n),e),{state:0,disabled:false})}function p$3(n){return Math.round(100*n)/100}
|
|
298
340
|
|
|
299
341
|
var x=r=>Math.sqrt(r.x*r.x+r.y*r.y),y=(r,a)=>r.x*a.x+r.y*a.y,e$1=(r,a)=>{var t=x(r)*x(a);if(0===t)return 0;var h=y(r,a)/t;return h>1&&(h=1),Math.acos(h)},n=(r,a)=>r.x*a.y-a.x*r.y,o=r=>r/Math.PI*180,s=(r,a)=>{var t=e$1(r,a);return n(r,a)>0&&(t*=-1),o(t)},u$2=(x,y)=>{if(0!==x||0!==y)return Math.abs(x)>=Math.abs(y)?0<x?i$3:a$2:0<y?d$1:r$4};
|
|
@@ -763,48 +805,6 @@ var pops = (function () {
|
|
|
763
805
|
}
|
|
764
806
|
const popsUtils = new PopsUtils();
|
|
765
807
|
|
|
766
|
-
const PopsSafeUtils = {
|
|
767
|
-
/**
|
|
768
|
-
* 获取安全的html
|
|
769
|
-
*/
|
|
770
|
-
getSafeHTML(text) {
|
|
771
|
-
if (window.trustedTypes) {
|
|
772
|
-
const policy = window.trustedTypes.createPolicy("safe-innerHTML", {
|
|
773
|
-
createHTML: (html) => html,
|
|
774
|
-
});
|
|
775
|
-
return policy.createHTML(text);
|
|
776
|
-
}
|
|
777
|
-
else {
|
|
778
|
-
return text;
|
|
779
|
-
}
|
|
780
|
-
},
|
|
781
|
-
/**
|
|
782
|
-
* 设置安全的html
|
|
783
|
-
*/
|
|
784
|
-
setSafeHTML($el, text) {
|
|
785
|
-
// 创建 TrustedHTML 策略(需 CSP 允许)
|
|
786
|
-
$el.innerHTML = this.getSafeHTML(text);
|
|
787
|
-
},
|
|
788
|
-
};
|
|
789
|
-
|
|
790
|
-
/**
|
|
791
|
-
* 通用的CSS类名
|
|
792
|
-
*/
|
|
793
|
-
const PopsCommonCSSClassName = {
|
|
794
|
-
flexCenter: "pops-flex-items-center",
|
|
795
|
-
flexYCenter: "pops-flex-y-center",
|
|
796
|
-
flexXCenter: "pops-flex-x-center",
|
|
797
|
-
hide: "pops-hide",
|
|
798
|
-
hideImportant: "pops-hide-important",
|
|
799
|
-
noBorder: "pops-no-border",
|
|
800
|
-
noBorderImportant: "pops-no-border-important",
|
|
801
|
-
userSelectNone: "pops-user-select-none",
|
|
802
|
-
lineHeightCenter: "pops-line-height-center",
|
|
803
|
-
widthFill: "pops-width-fill",
|
|
804
|
-
textIsDisabled: "pops-text-is-disabled",
|
|
805
|
-
textIsDisabledImportant: "pops-text-is-disabled-important",
|
|
806
|
-
};
|
|
807
|
-
|
|
808
808
|
/**
|
|
809
809
|
* 存储在元素属性上的事件名
|
|
810
810
|
*/
|
|
@@ -817,7 +817,7 @@ var pops = (function () {
|
|
|
817
817
|
* @param startIndex
|
|
818
818
|
* @param option
|
|
819
819
|
*/
|
|
820
|
-
function
|
|
820
|
+
const getOption = function (args, startIndex, option) {
|
|
821
821
|
const currentParam = args[startIndex];
|
|
822
822
|
if (typeof currentParam === "boolean") {
|
|
823
823
|
option.capture = currentParam;
|
|
@@ -839,7 +839,7 @@ var pops = (function () {
|
|
|
839
839
|
option.isComposedPath = currentParam.isComposedPath;
|
|
840
840
|
}
|
|
841
841
|
return option;
|
|
842
|
-
}
|
|
842
|
+
};
|
|
843
843
|
const that = this;
|
|
844
844
|
// eslint-disable-next-line prefer-rest-params
|
|
845
845
|
const args = arguments;
|
|
@@ -854,8 +854,7 @@ var pops = (function () {
|
|
|
854
854
|
}
|
|
855
855
|
let $elList = [];
|
|
856
856
|
if (element instanceof NodeList || Array.isArray(element)) {
|
|
857
|
-
|
|
858
|
-
$elList = [...element];
|
|
857
|
+
$elList = $elList.concat(Array.from(element));
|
|
859
858
|
}
|
|
860
859
|
else {
|
|
861
860
|
$elList.push(element);
|
|
@@ -863,15 +862,15 @@ var pops = (function () {
|
|
|
863
862
|
// 事件名
|
|
864
863
|
let eventTypeList = [];
|
|
865
864
|
if (Array.isArray(eventType)) {
|
|
866
|
-
eventTypeList = eventTypeList.concat(eventType.filter((
|
|
865
|
+
eventTypeList = eventTypeList.concat(eventType.filter((it) => typeof it === "string" && it.toString() !== ""));
|
|
867
866
|
}
|
|
868
867
|
else if (typeof eventType === "string") {
|
|
869
|
-
eventTypeList = eventTypeList.concat(eventType.split(" ").filter((
|
|
868
|
+
eventTypeList = eventTypeList.concat(eventType.split(" ").filter((it) => it !== ""));
|
|
870
869
|
}
|
|
871
870
|
// 子元素选择器
|
|
872
871
|
let selectorList = [];
|
|
873
872
|
if (Array.isArray(selector)) {
|
|
874
|
-
selectorList = selectorList.concat(selector.filter((
|
|
873
|
+
selectorList = selectorList.concat(selector.filter((it) => typeof it === "string" && it.toString() !== ""));
|
|
875
874
|
}
|
|
876
875
|
else if (typeof selector === "string") {
|
|
877
876
|
selectorList.push(selector);
|
|
@@ -895,83 +894,105 @@ var pops = (function () {
|
|
|
895
894
|
// 这是存在selector的情况
|
|
896
895
|
listenerOption = getOption(args, 4, listenerOption);
|
|
897
896
|
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
let
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
}
|
|
930
|
-
// 在上层与主元素之间寻找可以被selector所匹配到的
|
|
931
|
-
const $closestMatches = that.closest(eventTarget, selectorItem);
|
|
932
|
-
if ($closestMatches && totalParent?.contains($closestMatches)) {
|
|
933
|
-
eventTarget = $closestMatches;
|
|
934
|
-
return true;
|
|
935
|
-
}
|
|
936
|
-
return false;
|
|
937
|
-
});
|
|
938
|
-
if (findValue) {
|
|
939
|
-
// 这里尝试使用defineProperty修改event的target值
|
|
940
|
-
try {
|
|
941
|
-
OriginPrototype.Object.defineProperty(event, "target", {
|
|
942
|
-
get() {
|
|
943
|
-
return eventTarget;
|
|
944
|
-
},
|
|
945
|
-
});
|
|
897
|
+
$elList.forEach(($elItem) => {
|
|
898
|
+
// 遍历事件名设置元素事件
|
|
899
|
+
eventTypeList.forEach((eventName) => {
|
|
900
|
+
/**
|
|
901
|
+
* 如果是option.once,那么删除该监听和元素上的事件和监听
|
|
902
|
+
*/
|
|
903
|
+
const checkOptionOnceToRemoveEventListener = () => {
|
|
904
|
+
if (listenerOption.once) {
|
|
905
|
+
this.off($elItem, eventName, selector, callback, option);
|
|
906
|
+
}
|
|
907
|
+
};
|
|
908
|
+
/**
|
|
909
|
+
* 事件回调
|
|
910
|
+
* @param event
|
|
911
|
+
*/
|
|
912
|
+
const handlerCallBack = function (event) {
|
|
913
|
+
let call_this = void 0;
|
|
914
|
+
let call_event = void 0;
|
|
915
|
+
let call_$selector = void 0;
|
|
916
|
+
let execCallback = false;
|
|
917
|
+
if (selectorList.length) {
|
|
918
|
+
// 存在子元素选择器
|
|
919
|
+
// 这时候的this和target都是子元素选择器的元素
|
|
920
|
+
let $target;
|
|
921
|
+
if (listenerOption.isComposedPath) {
|
|
922
|
+
// 可能为空
|
|
923
|
+
const composedPath = event.composedPath();
|
|
924
|
+
if (!composedPath.length && event.target) {
|
|
925
|
+
composedPath.push(event.target);
|
|
926
|
+
}
|
|
927
|
+
$target = composedPath[0];
|
|
946
928
|
}
|
|
947
|
-
|
|
948
|
-
|
|
929
|
+
else {
|
|
930
|
+
$target = event.target;
|
|
931
|
+
}
|
|
932
|
+
let $parent = $elItem;
|
|
933
|
+
if (popsUtils.isWin($parent)) {
|
|
934
|
+
// window和document共用一个对象
|
|
935
|
+
// 这样就能处理子元素选择器无法匹配的问题
|
|
936
|
+
$parent = PopsCore.document.documentElement;
|
|
937
|
+
}
|
|
938
|
+
const findValue = selectorList.find((selectors) => {
|
|
939
|
+
// 判断目标元素是否匹配选择器
|
|
940
|
+
if (that.matches($target, selectors)) {
|
|
941
|
+
// 当前目标可以被selector所匹配到
|
|
942
|
+
return true;
|
|
943
|
+
}
|
|
944
|
+
// 在上层与主元素之间寻找可以被selector所匹配到的
|
|
945
|
+
const $closestMatches = that.closest($target, selectors);
|
|
946
|
+
if ($closestMatches && $parent?.contains?.($closestMatches)) {
|
|
947
|
+
$target = $closestMatches;
|
|
948
|
+
return true;
|
|
949
|
+
}
|
|
950
|
+
return false;
|
|
951
|
+
});
|
|
952
|
+
if (findValue) {
|
|
953
|
+
// 这里尝试使用defineProperty修改event的target值
|
|
954
|
+
try {
|
|
955
|
+
OriginPrototype.Object.defineProperty(event, "target", {
|
|
956
|
+
get() {
|
|
957
|
+
return $target;
|
|
958
|
+
},
|
|
959
|
+
});
|
|
960
|
+
// oxlint-disable-next-line no-empty
|
|
961
|
+
}
|
|
962
|
+
catch { }
|
|
963
|
+
execCallback = true;
|
|
964
|
+
call_this = $target;
|
|
965
|
+
call_event = event;
|
|
966
|
+
call_$selector = $target;
|
|
949
967
|
}
|
|
950
|
-
|
|
968
|
+
}
|
|
969
|
+
else {
|
|
970
|
+
execCallback = true;
|
|
971
|
+
call_this = $elItem;
|
|
972
|
+
call_event = event;
|
|
973
|
+
}
|
|
974
|
+
if (execCallback) {
|
|
975
|
+
const result = listenerCallBack.call(call_this, call_event, call_$selector);
|
|
951
976
|
checkOptionOnceToRemoveEventListener();
|
|
977
|
+
if (typeof result === "boolean" && !result) {
|
|
978
|
+
return false;
|
|
979
|
+
}
|
|
952
980
|
}
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
listenerCallBack.call(elementItem, event);
|
|
957
|
-
checkOptionOnceToRemoveEventListener();
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
// 遍历事件名设置元素事件
|
|
961
|
-
eventTypeList.forEach((eventName) => {
|
|
962
|
-
elementItem.addEventListener(eventName, domUtilsEventCallBack, listenerOption);
|
|
981
|
+
};
|
|
982
|
+
// add listener
|
|
983
|
+
$elItem.addEventListener(eventName, handlerCallBack, listenerOption);
|
|
963
984
|
// 获取对象上的事件
|
|
964
|
-
const elementEvents = Reflect.get(
|
|
985
|
+
const elementEvents = Reflect.get($elItem, SymbolEvents) || {};
|
|
965
986
|
// 初始化对象上的xx事件
|
|
966
987
|
elementEvents[eventName] = elementEvents[eventName] || [];
|
|
967
988
|
elementEvents[eventName].push({
|
|
968
989
|
selector: selectorList,
|
|
969
990
|
option: listenerOption,
|
|
970
|
-
|
|
971
|
-
|
|
991
|
+
handlerCallBack: handlerCallBack,
|
|
992
|
+
callback: listenerCallBack,
|
|
972
993
|
});
|
|
973
994
|
// 覆盖事件
|
|
974
|
-
Reflect.set(
|
|
995
|
+
Reflect.set($elItem, SymbolEvents, elementEvents);
|
|
975
996
|
});
|
|
976
997
|
});
|
|
977
998
|
return {
|
|
@@ -984,11 +1005,11 @@ var pops = (function () {
|
|
|
984
1005
|
},
|
|
985
1006
|
/**
|
|
986
1007
|
* 主动触发事件
|
|
987
|
-
* @param
|
|
988
|
-
* @param
|
|
1008
|
+
* @param extraDetails 赋予触发的Event的额外属性,如果是Event类型,那么将自动代替默认new的Event对象
|
|
1009
|
+
* @param useDispatchToTriggerEvent 是否使用dispatchEvent来触发事件,默认true,如果为false,则直接调用callback,但是这种会让使用了`$selector`的没有值
|
|
989
1010
|
*/
|
|
990
|
-
emit: (
|
|
991
|
-
that.emit($elList, eventTypeList,
|
|
1011
|
+
emit: (extraDetails, useDispatchToTriggerEvent) => {
|
|
1012
|
+
that.emit($elList, eventTypeList, extraDetails, useDispatchToTriggerEvent);
|
|
992
1013
|
},
|
|
993
1014
|
};
|
|
994
1015
|
}
|
|
@@ -999,7 +1020,7 @@ var pops = (function () {
|
|
|
999
1020
|
* @param startIndex
|
|
1000
1021
|
* @param option
|
|
1001
1022
|
*/
|
|
1002
|
-
function
|
|
1023
|
+
const getOption = function (args1, startIndex, option) {
|
|
1003
1024
|
const currentParam = args1[startIndex];
|
|
1004
1025
|
if (typeof currentParam === "boolean") {
|
|
1005
1026
|
option.capture = currentParam;
|
|
@@ -1008,12 +1029,12 @@ var pops = (function () {
|
|
|
1008
1029
|
option.capture = currentParam.capture;
|
|
1009
1030
|
}
|
|
1010
1031
|
return option;
|
|
1011
|
-
}
|
|
1012
|
-
const
|
|
1032
|
+
};
|
|
1033
|
+
const that = this;
|
|
1013
1034
|
// eslint-disable-next-line prefer-rest-params
|
|
1014
1035
|
const args = arguments;
|
|
1015
1036
|
if (typeof element === "string") {
|
|
1016
|
-
element =
|
|
1037
|
+
element = that.selectorAll(element);
|
|
1017
1038
|
}
|
|
1018
1039
|
if (element == null) {
|
|
1019
1040
|
return;
|
|
@@ -1021,22 +1042,22 @@ var pops = (function () {
|
|
|
1021
1042
|
let $elList = [];
|
|
1022
1043
|
if (element instanceof NodeList || Array.isArray(element)) {
|
|
1023
1044
|
element = element;
|
|
1024
|
-
$elList = $elList.concat(element);
|
|
1045
|
+
$elList = $elList.concat(Array.from(element));
|
|
1025
1046
|
}
|
|
1026
1047
|
else {
|
|
1027
1048
|
$elList.push(element);
|
|
1028
1049
|
}
|
|
1029
1050
|
let eventTypeList = [];
|
|
1030
1051
|
if (Array.isArray(eventType)) {
|
|
1031
|
-
eventTypeList = eventTypeList.concat(eventType.filter((
|
|
1052
|
+
eventTypeList = eventTypeList.concat(eventType.filter((it) => typeof it === "string" && it.toString() !== ""));
|
|
1032
1053
|
}
|
|
1033
1054
|
else if (typeof eventType === "string") {
|
|
1034
|
-
eventTypeList = eventTypeList.concat(eventType.split(" ").filter((
|
|
1055
|
+
eventTypeList = eventTypeList.concat(eventType.split(" ").filter((it) => it !== ""));
|
|
1035
1056
|
}
|
|
1036
1057
|
// 子元素选择器
|
|
1037
1058
|
let selectorList = [];
|
|
1038
1059
|
if (Array.isArray(selector)) {
|
|
1039
|
-
selectorList = selectorList.concat(selector.filter((
|
|
1060
|
+
selectorList = selectorList.concat(selector.filter((it) => typeof it === "string" && it.toString() !== ""));
|
|
1040
1061
|
}
|
|
1041
1062
|
else if (typeof selector === "string") {
|
|
1042
1063
|
selectorList.push(selector);
|
|
@@ -1065,36 +1086,39 @@ var pops = (function () {
|
|
|
1065
1086
|
// 目标函数、事件名、回调函数、事件配置、过滤函数
|
|
1066
1087
|
filter = option;
|
|
1067
1088
|
}
|
|
1068
|
-
$elList.forEach((
|
|
1089
|
+
$elList.forEach(($elItem) => {
|
|
1069
1090
|
// 获取对象上的事件
|
|
1070
|
-
const elementEvents = Reflect.get(
|
|
1091
|
+
const elementEvents = Reflect.get($elItem, SymbolEvents) || {};
|
|
1071
1092
|
eventTypeList.forEach((eventName) => {
|
|
1072
1093
|
const handlers = elementEvents[eventName] || [];
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1094
|
+
// 过滤出需要删除的事件
|
|
1095
|
+
const handlersFiltered = typeof filter === "function" ? handlers.filter(filter) : handlers;
|
|
1096
|
+
for (let index = 0; index < handlersFiltered.length; index++) {
|
|
1097
|
+
const handler = handlersFiltered[index];
|
|
1098
|
+
// 过滤出的事件再根据下面的条件进行判断处理移除
|
|
1099
|
+
// 1. callback内存地址必须相同
|
|
1100
|
+
// 2. selector必须相同
|
|
1101
|
+
// 3. option.capture必须相同
|
|
1076
1102
|
let flag = true;
|
|
1077
|
-
if (flag && listenerCallBack && handler.
|
|
1078
|
-
// callback不同
|
|
1103
|
+
if (flag && listenerCallBack && handler.callback !== listenerCallBack) {
|
|
1079
1104
|
flag = false;
|
|
1080
1105
|
}
|
|
1081
1106
|
if (flag && selectorList.length && Array.isArray(handler.selector)) {
|
|
1082
1107
|
if (JSON.stringify(handler.selector) !== JSON.stringify(selectorList)) {
|
|
1083
|
-
// 子元素选择器不同
|
|
1084
1108
|
flag = false;
|
|
1085
1109
|
}
|
|
1086
1110
|
}
|
|
1087
1111
|
if (flag &&
|
|
1088
1112
|
typeof handler.option.capture === "boolean" &&
|
|
1089
1113
|
listenerOption.capture !== handler.option.capture) {
|
|
1090
|
-
// 事件的配置项不同
|
|
1091
1114
|
flag = false;
|
|
1092
1115
|
}
|
|
1093
1116
|
if (flag) {
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1117
|
+
$elItem.removeEventListener(eventName, handler.handlerCallBack, handler.option);
|
|
1118
|
+
for (let i = handlers.length - 1; i >= 0; i--) {
|
|
1119
|
+
if (handlers[i] === handler) {
|
|
1120
|
+
handlers.splice(i, 1);
|
|
1121
|
+
}
|
|
1098
1122
|
}
|
|
1099
1123
|
}
|
|
1100
1124
|
}
|
|
@@ -1103,7 +1127,7 @@ var pops = (function () {
|
|
|
1103
1127
|
popsUtils.delete(elementEvents, eventType);
|
|
1104
1128
|
}
|
|
1105
1129
|
});
|
|
1106
|
-
Reflect.set(
|
|
1130
|
+
Reflect.set($elItem, SymbolEvents, elementEvents);
|
|
1107
1131
|
});
|
|
1108
1132
|
}
|
|
1109
1133
|
/**
|
|
@@ -1487,11 +1511,11 @@ var pops = (function () {
|
|
|
1487
1511
|
* 阻止事件的默认行为发生,并阻止事件传播
|
|
1488
1512
|
*/
|
|
1489
1513
|
const stopEvent = (event, onlyStopPropagation) => {
|
|
1514
|
+
// 停止事件的传播,阻止它继续向更上层的元素冒泡,事件将不会再传播给其他的元素
|
|
1515
|
+
event?.stopPropagation();
|
|
1516
|
+
// 阻止事件传播,并且还能阻止元素上的其他事件处理程序被触发
|
|
1517
|
+
event?.stopImmediatePropagation();
|
|
1490
1518
|
if (typeof onlyStopPropagation === "boolean" && onlyStopPropagation) {
|
|
1491
|
-
// 停止事件的传播,阻止它继续向更上层的元素冒泡,事件将不会再传播给其他的元素
|
|
1492
|
-
event?.stopPropagation();
|
|
1493
|
-
// 阻止事件传播,并且还能阻止元素上的其他事件处理程序被触发
|
|
1494
|
-
event?.stopImmediatePropagation();
|
|
1495
1519
|
return;
|
|
1496
1520
|
}
|
|
1497
1521
|
// 阻止事件的默认行为发生。例如,当点击一个链接时,浏览器会默认打开链接的URL,或者在输入框内输入文字
|