1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,208 @@ |
1 |
+/** |
|
2 |
+* Tom Select v2.2.2 |
|
3 |
+* Licensed under the Apache License, Version 2.0 (the "License"); |
|
4 |
+*/ |
|
5 |
+ |
|
6 |
+(function (global, factory) { |
|
7 |
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
|
8 |
+ typeof define === 'function' && define.amd ? define(factory) : |
|
9 |
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.remove_button = factory()); |
|
10 |
+})(this, (function () { 'use strict'; |
|
11 |
+ |
|
12 |
+ /*! @orchidjs/unicode-variants | https://github.com/orchidjs/unicode-variants | Apache License (v2) */ |
|
13 |
+ const accent_pat = '[\u0300-\u036F\u{b7}\u{2be}\u{2bc}]'; |
|
14 |
+ /** @type {TUnicodeMap} */ |
|
15 |
+ |
|
16 |
+ const latin_convert = {}; |
|
17 |
+ /** @type {TUnicodeMap} */ |
|
18 |
+ |
|
19 |
+ const latin_condensed = { |
|
20 |
+ '/': '⁄∕', |
|
21 |
+ '0': '߀', |
|
22 |
+ "a": "ⱥɐɑ", |
|
23 |
+ "aa": "ꜳ", |
|
24 |
+ "ae": "æǽǣ", |
|
25 |
+ "ao": "ꜵ", |
|
26 |
+ "au": "ꜷ", |
|
27 |
+ "av": "ꜹꜻ", |
|
28 |
+ "ay": "ꜽ", |
|
29 |
+ "b": "ƀɓƃ", |
|
30 |
+ "c": "ꜿƈȼↄ", |
|
31 |
+ "d": "đɗɖᴅƌꮷԁɦ", |
|
32 |
+ "e": "ɛǝᴇɇ", |
|
33 |
+ "f": "ꝼƒ", |
|
34 |
+ "g": "ǥɠꞡᵹꝿɢ", |
|
35 |
+ "h": "ħⱨⱶɥ", |
|
36 |
+ "i": "ɨı", |
|
37 |
+ "j": "ɉȷ", |
|
38 |
+ "k": "ƙⱪꝁꝃꝅꞣ", |
|
39 |
+ "l": "łƚɫⱡꝉꝇꞁɭ", |
|
40 |
+ "m": "ɱɯϻ", |
|
41 |
+ "n": "ꞥƞɲꞑᴎлԉ", |
|
42 |
+ "o": "øǿɔɵꝋꝍᴑ", |
|
43 |
+ "oe": "œ", |
|
44 |
+ "oi": "ƣ", |
|
45 |
+ "oo": "ꝏ", |
|
46 |
+ "ou": "ȣ", |
|
47 |
+ "p": "ƥᵽꝑꝓꝕρ", |
|
48 |
+ "q": "ꝗꝙɋ", |
|
49 |
+ "r": "ɍɽꝛꞧꞃ", |
|
50 |
+ "s": "ßȿꞩꞅʂ", |
|
51 |
+ "t": "ŧƭʈⱦꞇ", |
|
52 |
+ "th": "þ", |
|
53 |
+ "tz": "ꜩ", |
|
54 |
+ "u": "ʉ", |
|
55 |
+ "v": "ʋꝟʌ", |
|
56 |
+ "vy": "ꝡ", |
|
57 |
+ "w": "ⱳ", |
|
58 |
+ "y": "ƴɏỿ", |
|
59 |
+ "z": "ƶȥɀⱬꝣ", |
|
60 |
+ "hv": "ƕ" |
|
61 |
+ }; |
|
62 |
+ |
|
63 |
+ for (let latin in latin_condensed) { |
|
64 |
+ let unicode = latin_condensed[latin] || ''; |
|
65 |
+ |
|
66 |
+ for (let i = 0; i < unicode.length; i++) { |
|
67 |
+ let char = unicode.substring(i, i + 1); |
|
68 |
+ latin_convert[char] = latin; |
|
69 |
+ } |
|
70 |
+ } |
|
71 |
+ |
|
72 |
+ new RegExp(Object.keys(latin_convert).join('|') + '|' + accent_pat, 'gu'); |
|
73 |
+ |
|
74 |
+ /** |
|
75 |
+ * Return a dom element from either a dom query string, jQuery object, a dom element or html string |
|
76 |
+ * https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518 |
|
77 |
+ * |
|
78 |
+ * param query should be {} |
|
79 |
+ */ |
|
80 |
+ |
|
81 |
+ const getDom = query => { |
|
82 |
+ if (query.jquery) { |
|
83 |
+ return query[0]; |
|
84 |
+ } |
|
85 |
+ |
|
86 |
+ if (query instanceof HTMLElement) { |
|
87 |
+ return query; |
|
88 |
+ } |
|
89 |
+ |
|
90 |
+ if (isHtmlString(query)) { |
|
91 |
+ var tpl = document.createElement('template'); |
|
92 |
+ tpl.innerHTML = query.trim(); // Never return a text node of whitespace as the result |
|
93 |
+ |
|
94 |
+ return tpl.content.firstChild; |
|
95 |
+ } |
|
96 |
+ |
|
97 |
+ return document.querySelector(query); |
|
98 |
+ }; |
|
99 |
+ const isHtmlString = arg => { |
|
100 |
+ if (typeof arg === 'string' && arg.indexOf('<') > -1) { |
|
101 |
+ return true; |
|
102 |
+ } |
|
103 |
+ |
|
104 |
+ return false; |
|
105 |
+ }; |
|
106 |
+ |
|
107 |
+ /** |
|
108 |
+ * Converts a scalar to its best string representation |
|
109 |
+ * for hash keys and HTML attribute values. |
|
110 |
+ * |
|
111 |
+ * Transformations: |
|
112 |
+ * 'str' -> 'str' |
|
113 |
+ * null -> '' |
|
114 |
+ * undefined -> '' |
|
115 |
+ * true -> '1' |
|
116 |
+ * false -> '0' |
|
117 |
+ * 0 -> '0' |
|
118 |
+ * 1 -> '1' |
|
119 |
+ * |
|
120 |
+ */ |
|
121 |
+ /** |
|
122 |
+ * Escapes a string for use within HTML. |
|
123 |
+ * |
|
124 |
+ */ |
|
125 |
+ |
|
126 |
+ const escape_html = str => { |
|
127 |
+ return (str + '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); |
|
128 |
+ }; |
|
129 |
+ /** |
|
130 |
+ * Prevent default |
|
131 |
+ * |
|
132 |
+ */ |
|
133 |
+ |
|
134 |
+ const preventDefault = (evt, stop = false) => { |
|
135 |
+ if (evt) { |
|
136 |
+ evt.preventDefault(); |
|
137 |
+ |
|
138 |
+ if (stop) { |
|
139 |
+ evt.stopPropagation(); |
|
140 |
+ } |
|
141 |
+ } |
|
142 |
+ }; |
|
143 |
+ /** |
|
144 |
+ * Add event helper |
|
145 |
+ * |
|
146 |
+ */ |
|
147 |
+ |
|
148 |
+ const addEvent = (target, type, callback, options) => { |
|
149 |
+ target.addEventListener(type, callback, options); |
|
150 |
+ }; |
|
151 |
+ |
|
152 |
+ /** |
|
153 |
+ * Plugin: "remove_button" (Tom Select) |
|
154 |
+ * Copyright (c) contributors |
|
155 |
+ * |
|
156 |
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
|
157 |
+ * file except in compliance with the License. You may obtain a copy of the License at: |
|
158 |
+ * http://www.apache.org/licenses/LICENSE-2.0 |
|
159 |
+ * |
|
160 |
+ * Unless required by applicable law or agreed to in writing, software distributed under |
|
161 |
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
|
162 |
+ * ANY KIND, either express or implied. See the License for the specific language |
|
163 |
+ * governing permissions and limitations under the License. |
|
164 |
+ * |
|
165 |
+ */ |
|
166 |
+ function plugin (userOptions) { |
|
167 |
+ const options = Object.assign({ |
|
168 |
+ label: '×', |
|
169 |
+ title: 'Remove', |
|
170 |
+ className: 'remove', |
|
171 |
+ append: true |
|
172 |
+ }, userOptions); //options.className = 'remove-single'; |
|
173 |
+ |
|
174 |
+ var self = this; // override the render method to add remove button to each item |
|
175 |
+ |
|
176 |
+ if (!options.append) { |
|
177 |
+ return; |
|
178 |
+ } |
|
179 |
+ |
|
180 |
+ var html = '<a href="javascript:void(0)" class="' + options.className + '" tabindex="-1" title="' + escape_html(options.title) + '">' + options.label + '</a>'; |
|
181 |
+ self.hook('after', 'setupTemplates', () => { |
|
182 |
+ var orig_render_item = self.settings.render.item; |
|
183 |
+ |
|
184 |
+ self.settings.render.item = (data, escape) => { |
|
185 |
+ var item = getDom(orig_render_item.call(self, data, escape)); |
|
186 |
+ var close_button = getDom(html); |
|
187 |
+ item.appendChild(close_button); |
|
188 |
+ addEvent(close_button, 'mousedown', evt => { |
|
189 |
+ preventDefault(evt, true); |
|
190 |
+ }); |
|
191 |
+ addEvent(close_button, 'click', evt => { |
|
192 |
+ // propagating will trigger the dropdown to show for single mode |
|
193 |
+ preventDefault(evt, true); |
|
194 |
+ if (self.isLocked) return; |
|
195 |
+ if (!self.shouldDelete([item], evt)) return; |
|
196 |
+ self.removeItem(item); |
|
197 |
+ self.refreshOptions(false); |
|
198 |
+ self.inputState(); |
|
199 |
+ }); |
|
200 |
+ return item; |
|
201 |
+ }; |
|
202 |
+ }); |
|
203 |
+ } |
|
204 |
+ |
|
205 |
+ return plugin; |
|
206 |
+ |
|
207 |
+})); |
|
208 |
+//# sourceMappingURL=remove_button.js.map |