hx-tomselect 1.0.12 → 1.0.15
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/hx-tomselect.js +40 -2
- package/index.html +18 -7
- package/package.json +2 -2
package/hx-tomselect.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
/** stable build*/
|
|
3
3
|
const version = '11'
|
|
4
4
|
|
|
5
|
+
/** Resolve htmx from global (script tag) so we work with htmx 4 and correct load order. */
|
|
6
|
+
function getHtmx() { return typeof window !== 'undefined' && window.htmx; }
|
|
7
|
+
|
|
5
8
|
/**
|
|
6
9
|
* @typedef {Object} SupportedAttribute
|
|
7
10
|
* Defines an attribute supported by a configuration modification system.
|
|
@@ -166,7 +169,7 @@
|
|
|
166
169
|
}
|
|
167
170
|
return res.text();
|
|
168
171
|
})
|
|
169
|
-
.then((responseHtml) =>
|
|
172
|
+
.then((responseHtml) => getHtmx().process(elm, responseHtml))
|
|
170
173
|
.catch(error => {
|
|
171
174
|
console.error('Error adding item', error)
|
|
172
175
|
elm.setAttribute('tom-select-warning', `ts-add-post-url - Error processing item: ${JSON.stringify(error)}`);
|
|
@@ -219,6 +222,21 @@
|
|
|
219
222
|
}
|
|
220
223
|
})
|
|
221
224
|
},
|
|
225
|
+
{
|
|
226
|
+
key: 'ts-on-change-navigate',
|
|
227
|
+
configChange: (elm, config) => ({
|
|
228
|
+
multiple: false,
|
|
229
|
+
onChange: function(value) {
|
|
230
|
+
const urlTemplate = elm.getAttribute('ts-on-change-navigate')
|
|
231
|
+
if(urlTemplate && value){
|
|
232
|
+
const url = urlTemplate.replace('{value}', value)
|
|
233
|
+
window.location.href = url
|
|
234
|
+
}else{
|
|
235
|
+
console.warn('tomSelect - ts-on-change-navigate - no url template found')
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
})
|
|
239
|
+
},
|
|
222
240
|
{
|
|
223
241
|
key: 'ts-raw-config',
|
|
224
242
|
configChange: (elm, config) => elm.getAttribute('ts-raw-config')
|
|
@@ -295,7 +313,10 @@
|
|
|
295
313
|
}
|
|
296
314
|
}
|
|
297
315
|
|
|
298
|
-
|
|
316
|
+
function register() {
|
|
317
|
+
var h = getHtmx();
|
|
318
|
+
if (!h || !h.defineExtension) return false;
|
|
319
|
+
h.defineExtension('tomselect', {
|
|
299
320
|
// This is doing all the tom-select attachment at this stage, but relies on this full document scan (would prefer onLoad of speicfic content):
|
|
300
321
|
onEvent: function (name, evt) {
|
|
301
322
|
if (name === "htmx:afterProcessNode") {
|
|
@@ -329,5 +350,22 @@
|
|
|
329
350
|
.forEach(elt => elt.tomselect.destroy())*/
|
|
330
351
|
}
|
|
331
352
|
});
|
|
353
|
+
return true;
|
|
354
|
+
}
|
|
355
|
+
if (!register()) {
|
|
356
|
+
function tryRegister() {
|
|
357
|
+
if (register()) return;
|
|
358
|
+
if (document.readyState === 'loading') {
|
|
359
|
+
document.addEventListener('DOMContentLoaded', tryRegister);
|
|
360
|
+
} else {
|
|
361
|
+
setTimeout(tryRegister, 50);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
if (document.readyState === 'loading') {
|
|
365
|
+
document.addEventListener('DOMContentLoaded', tryRegister);
|
|
366
|
+
} else {
|
|
367
|
+
setTimeout(tryRegister, 50);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
332
370
|
|
|
333
371
|
})();
|
package/index.html
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
<meta charset="UTF-8">
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
7
|
<title>hx-tomselect</title>
|
|
8
|
-
<script
|
|
9
|
-
<script src="
|
|
8
|
+
<script src="https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-alpha7/dist/htmx.min.js"></script>
|
|
9
|
+
<script src="./hx-tomselect.js"></script>
|
|
10
10
|
<link href="https://cdn.jsdelivr.net/npm/tom-select@latest/dist/css/tom-select.css" rel="stylesheet"/>
|
|
11
11
|
<script src="https://cdn.jsdelivr.net/npm/tom-select@latest/dist/js/tom-select.complete.min.js"></script>
|
|
12
12
|
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@latest/dist/tailwind.min.css" rel="stylesheet">
|
|
@@ -60,15 +60,15 @@
|
|
|
60
60
|
<pre
|
|
61
61
|
class="mb-2 code-container"><code class="language-markup wrap"><script src="https://unpkg.com/hx-tomselect/hx-tomselect.js"></script></code></pre>
|
|
62
62
|
|
|
63
|
-
this extention relies on <a class="underline" href="https://
|
|
64
|
-
href="https://tom-select.js.org/">tom-select.js</a> being loaded before it is included:
|
|
63
|
+
this extention relies on <a class="underline" href="https://htmx.org">htmx</a> and <a class="underline"
|
|
64
|
+
href="https://tom-select.js.org/">tom-select.js</a> being loaded before it is included (htmx first, then this extension):
|
|
65
65
|
<pre class="mb-2 code-container"><code class="language-markup"><!DOCTYPE html>
|
|
66
66
|
<html>
|
|
67
67
|
<head>
|
|
68
|
-
<script src="https://
|
|
68
|
+
<script src="https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-alpha7/dist/htmx.min.js"></script>
|
|
69
69
|
<link href="https://unpkg.com/tom-select@latest/dist/css/tom-select.css" rel="stylesheet" />
|
|
70
|
-
<script src="https://unpkg.com/tom-select@latest/dist/js/tom-select.complete.min.js">
|
|
71
|
-
<script src="https://unpkg.com/hx-tomselect/hx-tomselect.js"
|
|
70
|
+
<script src="https://unpkg.com/tom-select@latest/dist/js/tom-select.complete.min.js"></script>
|
|
71
|
+
<script src="https://unpkg.com/hx-tomselect/hx-tomselect.js"></script>
|
|
72
72
|
</head>
|
|
73
73
|
<body>
|
|
74
74
|
<select hx-ext="tomselect">
|
|
@@ -262,6 +262,17 @@
|
|
|
262
262
|
</code></pre>
|
|
263
263
|
</section>
|
|
264
264
|
</div>
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
<section class="mb-20">
|
|
268
|
+
<h2 class="text-xl font-semibold mb-3">Navigate on change</h2>
|
|
269
|
+
<p>navigate to a new page when the value changes</p>
|
|
270
|
+
<select hx-ext="tomselect" ts-on-change-navigate="{value}">
|
|
271
|
+
<option value="">Select</option>
|
|
272
|
+
<option value="https://www.google.com">Google </option>
|
|
273
|
+
<option value="https://www.bing.com">Bing</option>
|
|
274
|
+
</select>
|
|
275
|
+
</section>
|
|
265
276
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.5.0/prism.min.js"></script>
|
|
266
277
|
</body>
|
|
267
278
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hx-tomselect",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.15",
|
|
4
|
+
"description": "Htmx extension that allows rendering tom-select via plain html elements",
|
|
5
5
|
"main": "hx-tomselect.js",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|