From d1d29779d2f3db8ab1da791370637a4bc22e34eb Mon Sep 17 00:00:00 2001 From: Lena Daxenbichler Date: Thu, 15 Dec 2022 10:17:00 +0100 Subject: [PATCH 1/8] add array hooks --- js/src/widget.js | 18 ++++++++++++++++++ package.json | 6 +++--- src/yafowil/widget/chosen/resources/widget.js | 12 ++++++++++++ .../widget/chosen/resources/widget.min.js | 2 +- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/js/src/widget.js b/js/src/widget.js index 7d45229..6e427f6 100644 --- a/js/src/widget.js +++ b/js/src/widget.js @@ -4,6 +4,9 @@ export class ChosenWidget { static initialize(context) { $('select.chosen', context).each(function (event) { + if ($(this).attr('id').includes('TEMPLATE')) { + return; + } new ChosenWidget($(this)); }); } @@ -46,3 +49,18 @@ export class ChosenWidget { } } } + +////////////////////////////////////////////////////////////////////////////// +// yafowil.widget.array integration +////////////////////////////////////////////////////////////////////////////// + +function chosen_on_array_add(inst, context) { + ChosenWidget.initialize(context, true); +} + +$(function() { + if (yafowil_array === undefined) { + return; + } + yafowil_array.on_array_event('on_add', chosen_on_array_add); +}); diff --git a/package.json b/package.json index 37cbaba..48e7441 100644 --- a/package.json +++ b/package.json @@ -4,13 +4,13 @@ "karma-test:coverage": "node js/karma-coverage.js" }, "devDependencies": { - "karma": "^6.3.20", + "karma": "^6.4.1", "karma-chrome-launcher": "^3.1.1", "karma-coverage": "^2.2.0", "karma-module-resolver-preprocessor": "^1.1.3", "karma-qunit": "^4.1.2", - "qunit": "^2.19.1", - "rollup": "^2.75.3", + "qunit": "^2.19.3", + "rollup": "^2.79.1", "rollup-plugin-cleanup": "^3.2.1", "rollup-plugin-terser": "^7.0.2" } diff --git a/src/yafowil/widget/chosen/resources/widget.js b/src/yafowil/widget/chosen/resources/widget.js index 50aeb93..ec647fe 100644 --- a/src/yafowil/widget/chosen/resources/widget.js +++ b/src/yafowil/widget/chosen/resources/widget.js @@ -4,6 +4,9 @@ var yafowil_chosen = (function (exports, $) { class ChosenWidget { static initialize(context) { $('select.chosen', context).each(function (event) { + if ($(this).attr('id').includes('TEMPLATE')) { + return; + } new ChosenWidget($(this)); }); } @@ -43,6 +46,15 @@ var yafowil_chosen = (function (exports, $) { } } } + function chosen_on_array_add(inst, context) { + ChosenWidget.initialize(context, true); + } + $(function() { + if (yafowil_array === undefined) { + return; + } + yafowil_array.on_array_event('on_add', chosen_on_array_add); + }); $(function() { if (window.ts !== undefined) { diff --git a/src/yafowil/widget/chosen/resources/widget.min.js b/src/yafowil/widget/chosen/resources/widget.min.js index 3b203ac..3dfaaba 100644 --- a/src/yafowil/widget/chosen/resources/widget.min.js +++ b/src/yafowil/widget/chosen/resources/widget.min.js @@ -1 +1 @@ -var yafowil_chosen=function(e,i){"use strict";class t{static initialize(e){i("select.chosen",e).each((function(e){new t(i(this))}))}constructor(e){e.data("yafowil-chosen",this),this.elem=e;let t=e.data();if(e.chosen(t),t.new_values){let t=i(".search-field input",e.parent());t.on("change",this.change_handle.bind(this)),t.on("keyup",this.keyup_handle.bind(this))}}change_handle(e){e.preventDefault();let t=i(e.currentTarget).val();if(!t)return;let n=!1;i("option",this.elem).each((function(){this.value===t&&(n=!0)})),n||(this.elem.append(``),this.elem.trigger("chosen:updated"))}keyup_handle(e){13==(e.keyCode||e.which)&&this.change_handle(e)}}return i((function(){void 0!==window.ts?ts.ajax.register(t.initialize,!0):void 0!==window.bdajax?bdajax.register(t.initialize,!0):t.initialize()})),e.ChosenWidget=t,Object.defineProperty(e,"__esModule",{value:!0}),window.yafowil=window.yafowil||{},window.yafowil.chosen=e,e}({},jQuery); +var yafowil_chosen=function(e,i){"use strict";class t{static initialize(e){i("select.chosen",e).each((function(e){i(this).attr("id").includes("TEMPLATE")||new t(i(this))}))}constructor(e){e.data("yafowil-chosen",this),this.elem=e;let t=e.data();if(e.chosen(t),t.new_values){let t=i(".search-field input",e.parent());t.on("change",this.change_handle.bind(this)),t.on("keyup",this.keyup_handle.bind(this))}}change_handle(e){e.preventDefault();let t=i(e.currentTarget).val();if(!t)return;let n=!1;i("option",this.elem).each((function(){this.value===t&&(n=!0)})),n||(this.elem.append(``),this.elem.trigger("chosen:updated"))}keyup_handle(e){13==(e.keyCode||e.which)&&this.change_handle(e)}}function n(e,i){t.initialize(i,!0)}return i((function(){void 0!==yafowil_array&&yafowil_array.on_array_event("on_add",n)})),i((function(){void 0!==window.ts?ts.ajax.register(t.initialize,!0):void 0!==window.bdajax?bdajax.register(t.initialize,!0):t.initialize()})),e.ChosenWidget=t,Object.defineProperty(e,"__esModule",{value:!0}),window.yafowil=window.yafowil||{},window.yafowil.chosen=e,e}({},jQuery); From 43d09b82b57662954d3681611968120d58fa29e9 Mon Sep 17 00:00:00 2001 From: Lena Daxenbichler Date: Thu, 15 Dec 2022 10:17:52 +0100 Subject: [PATCH 2/8] update test --- js/tests/test_chosen.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/js/tests/test_chosen.js b/js/tests/test_chosen.js index 3615306..0a3eddd 100644 --- a/js/tests/test_chosen.js +++ b/js/tests/test_chosen.js @@ -1,5 +1,7 @@ import { ChosenWidget } from "../src/widget"; +window.yafowil_array = undefined; + QUnit.test('test', assert => { let el = $('').appendTo(container); + }); + + hooks.afterEach(() => { + el.remove(); + container.empty().remove(); + wid = null; + }); + + QUnit.test('init', assert => { + let wid = new ChosenWidget(el); + assert.ok(wid); + assert.deepEqual(wid.elem, el); + }); + + QUnit.test('search field', assert => { + let search_field = $('
').appendTo(container); + let input = $('').appendTo(search_field); + el.on('chosen:updated', (e) => { + assert.step('chosen updated'); + }) + + el.data('new_values', true); + el.data('multivalued', true); + el.data('search_contains', true); + el.data('vocabulary', ['foo', 'bar']); + let wid = new ChosenWidget(el); + + assert.ok(wid); + assert.deepEqual(wid.elem, el); + + // change_handle + input.val('f').trigger('change'); + let opt = $('option', el); + assert.strictEqual(opt.length, 1); + assert.strictEqual(opt.val(), 'f'); + assert.verifySteps(['chosen updated']); + + input.val('').trigger('change'); + opt = $('option', el); + assert.strictEqual(opt.length, 1); + assert.verifySteps([]); + + input.val('f').trigger('change'); + opt = $('option', el); + assert.strictEqual(opt.length, 1); + assert.strictEqual(opt.val(), 'f'); + assert.verifySteps([]); + + // keyup_handle + input.val('b'); + let keyup = $.Event('keyup'); + keyup.which = 13; + input.trigger(keyup); + assert.verifySteps(['chosen updated']); + + let keyup2 = $.Event('keyup'); + keyup2.which = 12; + input.trigger(keyup2); + assert.verifySteps([]); + }); + + QUnit.test('init in array', assert => { + el.attr('id', 'yafowil-TEMPLATE-array'); + + // invoke array on_add - returns + _array_subscribers['on_add'].apply(null, $('body')); + wid = el.data('yafowil-chosen'); + assert.notOk(wid); + + // invoke array on_add + el.attr('id', ''); + _array_subscribers['on_add'].apply(null, $('body')); + wid = el.data('yafowil-chosen'); + assert.ok(wid); + }) +}) -QUnit.test('test', assert => { - let el = $('').appendTo(container); + el = $('').appendTo(search_field); - el.on('chosen:updated', (e) => { - assert.step('chosen updated'); - }) - - el.data('new_values', true); - el.data('multivalued', true); - el.data('search_contains', true); - el.data('vocabulary', ['foo', 'bar']); - let wid = new ChosenWidget(el); - - assert.ok(wid); - assert.deepEqual(wid.elem, el); - - // change_handle - input.val('f').trigger('change'); - let opt = $('option', el); - assert.strictEqual(opt.length, 1); - assert.strictEqual(opt.val(), 'f'); - assert.verifySteps(['chosen updated']); - - input.val('').trigger('change'); - opt = $('option', el); - assert.strictEqual(opt.length, 1); - assert.verifySteps([]); - - input.val('f').trigger('change'); - opt = $('option', el); - assert.strictEqual(opt.length, 1); - assert.strictEqual(opt.val(), 'f'); - assert.verifySteps([]); - - // keyup_handle - input.val('b'); - let keyup = $.Event('keyup'); - keyup.which = 13; - input.trigger(keyup); - assert.verifySteps(['chosen updated']); - - let keyup2 = $.Event('keyup'); - keyup2.which = 12; - input.trigger(keyup2); - assert.verifySteps([]); + QUnit.module('search field', hooks => { + let input; + + hooks.beforeEach((assert) => { + el.appendTo(container); + let search_field = $('
').appendTo(container); + input = $('').appendTo(search_field); + el.on('chosen:updated', (e) => { + assert.step('chosen updated'); + }) + + el.data('new_values', true); + el.data('multivalued', true); + el.data('search_contains', true); + el.data('vocabulary', ['foo', 'bar']); + wid = new ChosenWidget(el); + }); + + QUnit.test('change_handle', assert => { + assert.ok(wid); + input.val('f').trigger('change'); + let opt = $('option', el); + assert.strictEqual(opt.length, 1); + assert.strictEqual(opt.val(), 'f'); + assert.verifySteps(['chosen updated']); + + // returns + input.val('').trigger('change'); + opt = $('option', el); + assert.strictEqual(opt.length, 1); + assert.verifySteps([]); + + input.val('f').trigger('change'); + opt = $('option', el); + assert.strictEqual(opt.length, 1); + assert.strictEqual(opt.val(), 'f'); + assert.verifySteps([]); + + // ignores + input.val('b').trigger('change'); + let opts = $('option', el); + assert.strictEqual(opts.length, 2); + assert.verifySteps(['chosen updated']); + }); + + QUnit.test('keyup_handle', assert => { + assert.ok(wid); + input.val('b'); + let keyup = $.Event('keyup'); + keyup.which = 13; + input.trigger(keyup); + assert.verifySteps(['chosen updated']); + + let keyup2 = $.Event('keyup'); + keyup2.which = 12; + input.trigger(keyup2); + assert.verifySteps([]); + }); }); - QUnit.test('init in array', assert => { + QUnit.test('register_array_subscribers', assert => { + // return if window.yafowil === undefined + register_array_subscribers(); + assert.deepEqual(_array_subscribers['on_add'], []); + + // patch yafowil_array + window.yafowil_array = { + on_array_event: function(evt_name, evt_function) { + _array_subscribers[evt_name] = evt_function; + } + }; + register_array_subscribers(); + + // create table DOM + let table = $('') + .append($('')) + .append($('
')) + .appendTo('body'); + el.attr('id', 'yafowil-TEMPLATE-array'); + el.appendTo($('td', table)); // invoke array on_add - returns - _array_subscribers['on_add'].apply(null, $('body')); + _array_subscribers['on_add'].apply(null, $('tr', table)); wid = el.data('yafowil-chosen'); assert.notOk(wid); // invoke array on_add el.attr('id', ''); - _array_subscribers['on_add'].apply(null, $('body')); + _array_subscribers['on_add'].apply(null, $('tr', table)); wid = el.data('yafowil-chosen'); assert.ok(wid); - }) + + table.remove(); + }); }) diff --git a/src/yafowil/widget/chosen/resources/widget.js b/src/yafowil/widget/chosen/resources/widget.js index f08b6f4..c323fac 100644 --- a/src/yafowil/widget/chosen/resources/widget.js +++ b/src/yafowil/widget/chosen/resources/widget.js @@ -49,12 +49,12 @@ var yafowil_chosen = (function (exports, $) { function chosen_on_array_add(inst, context) { ChosenWidget.initialize(context, true); } - $(function() { + function register_array_subscribers() { if (window.yafowil_array === undefined) { return; } window.yafowil_array.on_array_event('on_add', chosen_on_array_add); - }); + } $(function() { if (window.ts !== undefined) { @@ -64,9 +64,11 @@ var yafowil_chosen = (function (exports, $) { } else { ChosenWidget.initialize(); } + register_array_subscribers(); }); exports.ChosenWidget = ChosenWidget; + exports.register_array_subscribers = register_array_subscribers; Object.defineProperty(exports, '__esModule', { value: true }); diff --git a/src/yafowil/widget/chosen/resources/widget.min.js b/src/yafowil/widget/chosen/resources/widget.min.js index 82fcac6..02ea937 100644 --- a/src/yafowil/widget/chosen/resources/widget.min.js +++ b/src/yafowil/widget/chosen/resources/widget.min.js @@ -1 +1 @@ -var yafowil_chosen=function(e,i){"use strict";class n{static initialize(e){i("select.chosen",e).each((function(e){i(this).attr("id").includes("TEMPLATE")||new n(i(this))}))}constructor(e){e.data("yafowil-chosen",this),this.elem=e;let n=e.data();if(e.chosen(n),n.new_values){let n=i(".search-field input",e.parent());n.on("change",this.change_handle.bind(this)),n.on("keyup",this.keyup_handle.bind(this))}}change_handle(e){e.preventDefault();let n=i(e.currentTarget).val();if(!n)return;let t=!1;i("option",this.elem).each((function(){this.value===n&&(t=!0)})),t||(this.elem.append(``),this.elem.trigger("chosen:updated"))}keyup_handle(e){13==(e.keyCode||e.which)&&this.change_handle(e)}}function t(e,i){n.initialize(i,!0)}return i((function(){void 0!==window.yafowil_array&&window.yafowil_array.on_array_event("on_add",t)})),i((function(){void 0!==window.ts?ts.ajax.register(n.initialize,!0):void 0!==window.bdajax?bdajax.register(n.initialize,!0):n.initialize()})),e.ChosenWidget=n,Object.defineProperty(e,"__esModule",{value:!0}),window.yafowil=window.yafowil||{},window.yafowil.chosen=e,e}({},jQuery); +var yafowil_chosen=function(e,i){"use strict";class t{static initialize(e){i("select.chosen",e).each((function(e){i(this).attr("id").includes("TEMPLATE")||new t(i(this))}))}constructor(e){e.data("yafowil-chosen",this),this.elem=e;let t=e.data();if(e.chosen(t),t.new_values){let t=i(".search-field input",e.parent());t.on("change",this.change_handle.bind(this)),t.on("keyup",this.keyup_handle.bind(this))}}change_handle(e){e.preventDefault();let t=i(e.currentTarget).val();if(!t)return;let n=!1;i("option",this.elem).each((function(){this.value===t&&(n=!0)})),n||(this.elem.append(``),this.elem.trigger("chosen:updated"))}keyup_handle(e){13==(e.keyCode||e.which)&&this.change_handle(e)}}function n(e,i){t.initialize(i,!0)}function a(){void 0!==window.yafowil_array&&window.yafowil_array.on_array_event("on_add",n)}return i((function(){void 0!==window.ts?ts.ajax.register(t.initialize,!0):void 0!==window.bdajax?bdajax.register(t.initialize,!0):t.initialize(),a()})),e.ChosenWidget=t,e.register_array_subscribers=a,Object.defineProperty(e,"__esModule",{value:!0}),window.yafowil=window.yafowil||{},window.yafowil.chosen=e,e}({},jQuery); From 4315935dcad7e352cce519054026783dd6519f54 Mon Sep 17 00:00:00 2001 From: Lena Daxenbichler Date: Tue, 20 Dec 2022 11:02:51 +0100 Subject: [PATCH 5/8] update changelog --- CHANGES.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 6fd5507..c74ef25 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,6 +8,9 @@ Changes functions to enable usage in ``yafowil.widget.array``. [lenadax] +- Prevent initialize of widget if part of array template. + [lenadax] + - Rewrite JavaScript using ES6. [rnix] From f8fb07be99f0608c999edbcc9afdec46b025d8d9 Mon Sep 17 00:00:00 2001 From: Lena Daxenbichler Date: Thu, 22 Dec 2022 08:56:55 +0100 Subject: [PATCH 6/8] instead of checking elem id, check if elem is child of .arraytemplate --- js/src/widget.js | 2 +- js/tests/test_chosen.js | 3 ++- src/yafowil/widget/chosen/resources/widget.js | 2 +- src/yafowil/widget/chosen/resources/widget.min.js | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/js/src/widget.js b/js/src/widget.js index 3a2f5b6..8b9e43b 100644 --- a/js/src/widget.js +++ b/js/src/widget.js @@ -4,7 +4,7 @@ export class ChosenWidget { static initialize(context) { $('select.chosen', context).each(function (event) { - if ($(this).attr('id').includes('TEMPLATE')) { + if ($(this).parents('.arraytemplate').length) { return; } new ChosenWidget($(this)); diff --git a/js/tests/test_chosen.js b/js/tests/test_chosen.js index d2f5ca3..384f138 100644 --- a/js/tests/test_chosen.js +++ b/js/tests/test_chosen.js @@ -103,13 +103,14 @@ QUnit.module('chosen', hooks => { .append($('')) .appendTo('body'); - el.attr('id', 'yafowil-TEMPLATE-array'); + $('td', table).addClass('arraytemplate'); el.appendTo($('td', table)); // invoke array on_add - returns _array_subscribers['on_add'].apply(null, $('tr', table)); wid = el.data('yafowil-chosen'); assert.notOk(wid); + $('td', table).removeClass('arraytemplate'); // invoke array on_add el.attr('id', ''); diff --git a/src/yafowil/widget/chosen/resources/widget.js b/src/yafowil/widget/chosen/resources/widget.js index c323fac..84b2822 100644 --- a/src/yafowil/widget/chosen/resources/widget.js +++ b/src/yafowil/widget/chosen/resources/widget.js @@ -4,7 +4,7 @@ var yafowil_chosen = (function (exports, $) { class ChosenWidget { static initialize(context) { $('select.chosen', context).each(function (event) { - if ($(this).attr('id').includes('TEMPLATE')) { + if ($(this).parents('.arraytemplate').length) { return; } new ChosenWidget($(this)); diff --git a/src/yafowil/widget/chosen/resources/widget.min.js b/src/yafowil/widget/chosen/resources/widget.min.js index 02ea937..d0cf144 100644 --- a/src/yafowil/widget/chosen/resources/widget.min.js +++ b/src/yafowil/widget/chosen/resources/widget.min.js @@ -1 +1 @@ -var yafowil_chosen=function(e,i){"use strict";class t{static initialize(e){i("select.chosen",e).each((function(e){i(this).attr("id").includes("TEMPLATE")||new t(i(this))}))}constructor(e){e.data("yafowil-chosen",this),this.elem=e;let t=e.data();if(e.chosen(t),t.new_values){let t=i(".search-field input",e.parent());t.on("change",this.change_handle.bind(this)),t.on("keyup",this.keyup_handle.bind(this))}}change_handle(e){e.preventDefault();let t=i(e.currentTarget).val();if(!t)return;let n=!1;i("option",this.elem).each((function(){this.value===t&&(n=!0)})),n||(this.elem.append(``),this.elem.trigger("chosen:updated"))}keyup_handle(e){13==(e.keyCode||e.which)&&this.change_handle(e)}}function n(e,i){t.initialize(i,!0)}function a(){void 0!==window.yafowil_array&&window.yafowil_array.on_array_event("on_add",n)}return i((function(){void 0!==window.ts?ts.ajax.register(t.initialize,!0):void 0!==window.bdajax?bdajax.register(t.initialize,!0):t.initialize(),a()})),e.ChosenWidget=t,e.register_array_subscribers=a,Object.defineProperty(e,"__esModule",{value:!0}),window.yafowil=window.yafowil||{},window.yafowil.chosen=e,e}({},jQuery); +var yafowil_chosen=function(e,i){"use strict";class t{static initialize(e){i("select.chosen",e).each((function(e){i(this).parents(".arraytemplate").length||new t(i(this))}))}constructor(e){e.data("yafowil-chosen",this),this.elem=e;let t=e.data();if(e.chosen(t),t.new_values){let t=i(".search-field input",e.parent());t.on("change",this.change_handle.bind(this)),t.on("keyup",this.keyup_handle.bind(this))}}change_handle(e){e.preventDefault();let t=i(e.currentTarget).val();if(!t)return;let n=!1;i("option",this.elem).each((function(){this.value===t&&(n=!0)})),n||(this.elem.append(``),this.elem.trigger("chosen:updated"))}keyup_handle(e){13==(e.keyCode||e.which)&&this.change_handle(e)}}function n(e,i){t.initialize(i,!0)}function a(){void 0!==window.yafowil_array&&window.yafowil_array.on_array_event("on_add",n)}return i((function(){void 0!==window.ts?ts.ajax.register(t.initialize,!0):void 0!==window.bdajax?bdajax.register(t.initialize,!0):t.initialize(),a()})),e.ChosenWidget=t,e.register_array_subscribers=a,Object.defineProperty(e,"__esModule",{value:!0}),window.yafowil=window.yafowil||{},window.yafowil.chosen=e,e}({},jQuery); From 49fc9fa2fff9b972ad751fa2f17a6deacc0a0330 Mon Sep 17 00:00:00 2001 From: Lena Daxenbichler Date: Thu, 9 Mar 2023 11:31:10 +0100 Subject: [PATCH 7/8] Use yafowil_array.inside_template API to check whether widget gets initialized inside array template. --- js/src/widget.js | 3 ++- js/tests/test_chosen.js | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/js/src/widget.js b/js/src/widget.js index 8b9e43b..b04cae8 100644 --- a/js/src/widget.js +++ b/js/src/widget.js @@ -4,7 +4,8 @@ export class ChosenWidget { static initialize(context) { $('select.chosen', context).each(function (event) { - if ($(this).parents('.arraytemplate').length) { + if (window.yafowil_array !== undefined && + window.yafowil_array.inside_template($(this))) { return; } new ChosenWidget($(this)); diff --git a/js/tests/test_chosen.js b/js/tests/test_chosen.js index 384f138..71494d4 100644 --- a/js/tests/test_chosen.js +++ b/js/tests/test_chosen.js @@ -93,6 +93,9 @@ QUnit.module('chosen', hooks => { window.yafowil_array = { on_array_event: function(evt_name, evt_function) { _array_subscribers[evt_name] = evt_function; + }, + inside_template(elem) { + return elem.parents('.arraytemplate').length > 0; } }; register_array_subscribers(); From c363ec8ee574c9d0af124dc4ec3ae7365b9f04f5 Mon Sep 17 00:00:00 2001 From: Lena Daxenbichler Date: Thu, 9 Mar 2023 11:31:33 +0100 Subject: [PATCH 8/8] compiled js --- src/yafowil/widget/chosen/resources/widget.js | 3 ++- src/yafowil/widget/chosen/resources/widget.min.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/yafowil/widget/chosen/resources/widget.js b/src/yafowil/widget/chosen/resources/widget.js index 84b2822..c6a32c5 100644 --- a/src/yafowil/widget/chosen/resources/widget.js +++ b/src/yafowil/widget/chosen/resources/widget.js @@ -4,7 +4,8 @@ var yafowil_chosen = (function (exports, $) { class ChosenWidget { static initialize(context) { $('select.chosen', context).each(function (event) { - if ($(this).parents('.arraytemplate').length) { + if (window.yafowil_array !== undefined && + window.yafowil_array.inside_template($(this))) { return; } new ChosenWidget($(this)); diff --git a/src/yafowil/widget/chosen/resources/widget.min.js b/src/yafowil/widget/chosen/resources/widget.min.js index d0cf144..202fa2a 100644 --- a/src/yafowil/widget/chosen/resources/widget.min.js +++ b/src/yafowil/widget/chosen/resources/widget.min.js @@ -1 +1 @@ -var yafowil_chosen=function(e,i){"use strict";class t{static initialize(e){i("select.chosen",e).each((function(e){i(this).parents(".arraytemplate").length||new t(i(this))}))}constructor(e){e.data("yafowil-chosen",this),this.elem=e;let t=e.data();if(e.chosen(t),t.new_values){let t=i(".search-field input",e.parent());t.on("change",this.change_handle.bind(this)),t.on("keyup",this.keyup_handle.bind(this))}}change_handle(e){e.preventDefault();let t=i(e.currentTarget).val();if(!t)return;let n=!1;i("option",this.elem).each((function(){this.value===t&&(n=!0)})),n||(this.elem.append(``),this.elem.trigger("chosen:updated"))}keyup_handle(e){13==(e.keyCode||e.which)&&this.change_handle(e)}}function n(e,i){t.initialize(i,!0)}function a(){void 0!==window.yafowil_array&&window.yafowil_array.on_array_event("on_add",n)}return i((function(){void 0!==window.ts?ts.ajax.register(t.initialize,!0):void 0!==window.bdajax?bdajax.register(t.initialize,!0):t.initialize(),a()})),e.ChosenWidget=t,e.register_array_subscribers=a,Object.defineProperty(e,"__esModule",{value:!0}),window.yafowil=window.yafowil||{},window.yafowil.chosen=e,e}({},jQuery); +var yafowil_chosen=function(e,i){"use strict";class n{static initialize(e){i("select.chosen",e).each((function(e){void 0!==window.yafowil_array&&window.yafowil_array.inside_template(i(this))||new n(i(this))}))}constructor(e){e.data("yafowil-chosen",this),this.elem=e;let n=e.data();if(e.chosen(n),n.new_values){let n=i(".search-field input",e.parent());n.on("change",this.change_handle.bind(this)),n.on("keyup",this.keyup_handle.bind(this))}}change_handle(e){e.preventDefault();let n=i(e.currentTarget).val();if(!n)return;let t=!1;i("option",this.elem).each((function(){this.value===n&&(t=!0)})),t||(this.elem.append(``),this.elem.trigger("chosen:updated"))}keyup_handle(e){13==(e.keyCode||e.which)&&this.change_handle(e)}}function t(e,i){n.initialize(i,!0)}function a(){void 0!==window.yafowil_array&&window.yafowil_array.on_array_event("on_add",t)}return i((function(){void 0!==window.ts?ts.ajax.register(n.initialize,!0):void 0!==window.bdajax?bdajax.register(n.initialize,!0):n.initialize(),a()})),e.ChosenWidget=n,e.register_array_subscribers=a,Object.defineProperty(e,"__esModule",{value:!0}),window.yafowil=window.yafowil||{},window.yafowil.chosen=e,e}({},jQuery);