1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports["default"] = void 0;
|
7 |
|
8 |
|
9 | function octoParseImgTap(e) {
|
10 | var that = this;
|
11 | var nowImgUrl = e.currentTarget.dataset.src;
|
12 | var tagFrom = e.currentTarget.dataset.from;
|
13 |
|
14 | if (typeof tagFrom != 'undefined' && tagFrom.length > 0) {
|
15 | wx.previewImage({
|
16 | current: nowImgUrl,
|
17 |
|
18 |
|
19 | urls: [nowImgUrl]
|
20 | });
|
21 | }
|
22 | }
|
23 |
|
24 |
|
25 | function octoParseTagATap(e) {
|
26 | var href = e.currentTarget.dataset.src;
|
27 | }
|
28 |
|
29 |
|
30 | function defaultEvent(e) {}
|
31 |
|
32 | function mountDefaultAction(wx) {
|
33 | wx.octoParseImgTap = octoParseImgTap;
|
34 | wx.octoParseTagATap = octoParseTagATap;
|
35 | wx.defaultEvent = defaultEvent;
|
36 | }
|
37 |
|
38 |
|
39 | function addEvent2EventMap(eventMap, opt) {
|
40 | if (opt.filter) {
|
41 | if (opt.filter.indexOf('#') === 0) {
|
42 | var id = opt.filter.slice(1);
|
43 |
|
44 | if (!eventMap['id'][id]) {
|
45 | eventMap['id'][id] = {};
|
46 | }
|
47 |
|
48 | eventMap['id'][id] = Object.assign(eventMap['id'][id], opt.events);
|
49 | } else if (opt.filter.indexOf('.') === 0) {
|
50 | var className = opt.filter.slice(1);
|
51 |
|
52 | if (!eventMap['class'][className]) {
|
53 | eventMap['class'][className] = {};
|
54 | }
|
55 |
|
56 | eventMap['class'][className] = Object.assign(eventMap['class'][className], opt.events);
|
57 | }
|
58 | } else if (!opt.filter) {
|
59 | eventMap['base'] = Object.assign(eventMap['base'], opt.events);
|
60 | }
|
61 | }
|
62 |
|
63 | function findClassInRule(ruleClass, classStr) {
|
64 | var res = '';
|
65 | if (!classStr) return res;
|
66 | var classArray = classStr.split(' ');
|
67 | var length = classArray.length;
|
68 |
|
69 | for (var i = length - 1; i >= 0; i--) {
|
70 | var className = classArray[i].slice(1);
|
71 |
|
72 | if (ruleClass[className]) {
|
73 | res = className;
|
74 | break;
|
75 | }
|
76 | }
|
77 |
|
78 | return res;
|
79 | }
|
80 |
|
81 |
|
82 | function defaultEventName(e) {
|
83 | switch (e.type) {
|
84 | case 'tap':
|
85 | if (e.currentTarget.dataset.tag == 'img') {
|
86 | octoParseImgTap(e);
|
87 | } else if (e.currentTarget.dataset.tag == 'a') {
|
88 | octoParseTagATap(e);
|
89 | }
|
90 |
|
91 | break;
|
92 |
|
93 | default:
|
94 | defaultEvent(e);
|
95 | }
|
96 | }
|
97 |
|
98 |
|
99 | function generateAgentFunc(optionArray) {
|
100 | var rule = {};
|
101 |
|
102 | if (Array.isArray(optionArray)) {
|
103 | optionArray.forEach(function (opt) {
|
104 | if (!rule[opt.tag]) {
|
105 | rule[opt.tag] = {
|
106 | base: {},
|
107 | "class": {},
|
108 | id: {}
|
109 | };
|
110 | addEvent2EventMap(rule[opt.tag], opt);
|
111 | } else {
|
112 | addEvent2EventMap(rule[opt.tag], opt);
|
113 | }
|
114 | });
|
115 | }
|
116 |
|
117 | return function (e) {
|
118 | var dataset = e.currentTarget.dataset;
|
119 |
|
120 | if (dataset && rule[dataset.tag]) {
|
121 | if (rule[dataset.tag]['id'][dataset.id]) {
|
122 | rule[dataset.tag]['id'][dataset.id][e.type](e);
|
123 | } else if (findClassInRule(rule[dataset.tag]['class'], dataset["class"])) {
|
124 | var className = findClassInRule(rule[dataset.tag]['class'], dataset["class"]);
|
125 | rule[dataset.tag]['class'][className][e.type](e);
|
126 | } else if (typeof rule[dataset.tag]['base'][e.type] == 'function') {
|
127 | rule[dataset.tag]['base'][e.type](e);
|
128 | } else {
|
129 | defaultEventName(e);
|
130 | }
|
131 | } else {
|
132 | return defaultEventName(e);
|
133 | }
|
134 | };
|
135 | }
|
136 |
|
137 |
|
138 | function mountAction(wx, optionArray) {
|
139 |
|
140 |
|
141 | var agentFunc = generateAgentFunc(optionArray);
|
142 | wx.agentFunc = agentFunc;
|
143 | }
|
144 |
|
145 |
|
146 |
|
147 |
|
148 | var _default = mountAction;
|
149 | exports["default"] = _default; |
\ | No newline at end of file |