From 6b11b813e5984688c3e0aef1c57df2ba9565e7de Mon Sep 17 00:00:00 2001 From: "Soare Robert Daniel (Mac 2023)" Date: Mon, 4 Mar 2024 17:20:47 +0200 Subject: [PATCH 1/4] fix: filter key for select components --- includes/views/js/chosen.js | 64 +++++++++++++----------- includes/views/js/import-metabox-edit.js | 25 +++++++++ 2 files changed, 59 insertions(+), 30 deletions(-) diff --git a/includes/views/js/chosen.js b/includes/views/js/chosen.js index d9d2eb04..d4b258cc 100644 --- a/includes/views/js/chosen.js +++ b/includes/views/js/chosen.js @@ -91,7 +91,7 @@ This file is generated by `grunt build`, do not edit it by hand. return SelectParser; - })(); + }()); SelectParser.select_to_array = function(select) { var child, i, len, parser, ref; @@ -126,12 +126,12 @@ This file is generated by `grunt build`, do not edit it by hand. return function(evt) { return _this.test_active_click(evt); }; - })(this); + }(this)); this.activate_action = (function(_this) { return function(evt) { return _this.activate_field(evt); }; - })(this); + }(this)); this.active_field = false; this.mouse_on_container = false; this.results_showing = false; @@ -624,7 +624,7 @@ This file is generated by `grunt build`, do not edit it by hand. return AbstractChosen; - })(); + }()); $ = jQuery; @@ -715,123 +715,123 @@ This file is generated by `grunt build`, do not edit it by hand. return function(evt) { _this.container_mousedown(evt); }; - })(this)); + }(this))); this.container.on('touchend.chosen', (function(_this) { return function(evt) { _this.container_mouseup(evt); }; - })(this)); + }(this))); this.container.on('mousedown.chosen', (function(_this) { return function(evt) { _this.container_mousedown(evt); }; - })(this)); + }(this))); this.container.on('mouseup.chosen', (function(_this) { return function(evt) { _this.container_mouseup(evt); }; - })(this)); + }(this))); this.container.on('mouseenter.chosen', (function(_this) { return function(evt) { _this.mouse_enter(evt); }; - })(this)); + }(this))); this.container.on('mouseleave.chosen', (function(_this) { return function(evt) { _this.mouse_leave(evt); }; - })(this)); + }(this))); this.search_results.on('mouseup.chosen', (function(_this) { return function(evt) { _this.search_results_mouseup(evt); }; - })(this)); + }(this))); this.search_results.on('mouseover.chosen', (function(_this) { return function(evt) { _this.search_results_mouseover(evt); }; - })(this)); + }(this))); this.search_results.on('mouseout.chosen', (function(_this) { return function(evt) { _this.search_results_mouseout(evt); }; - })(this)); + }(this))); this.search_results.on('mousewheel.chosen DOMMouseScroll.chosen', (function(_this) { return function(evt) { _this.search_results_mousewheel(evt); }; - })(this)); + }(this))); this.search_results.on('touchstart.chosen', (function(_this) { return function(evt) { _this.search_results_touchstart(evt); }; - })(this)); + }(this))); this.search_results.on('touchmove.chosen', (function(_this) { return function(evt) { _this.search_results_touchmove(evt); }; - })(this)); + }(this))); this.search_results.on('touchend.chosen', (function(_this) { return function(evt) { _this.search_results_touchend(evt); }; - })(this)); + }(this))); this.form_field_jq.on("chosen:updated.chosen", (function(_this) { return function(evt) { _this.results_update_field(evt); }; - })(this)); + }(this))); this.form_field_jq.on("chosen:activate.chosen", (function(_this) { return function(evt) { _this.activate_field(evt); }; - })(this)); + }(this))); this.form_field_jq.on("chosen:open.chosen", (function(_this) { return function(evt) { _this.container_mousedown(evt); }; - })(this)); + }(this))); this.form_field_jq.on("chosen:close.chosen", (function(_this) { return function(evt) { _this.close_field(evt); }; - })(this)); + }(this))); this.search_field.on('blur.chosen', (function(_this) { return function(evt) { _this.input_blur(evt); }; - })(this)); + }(this))); this.search_field.on('keyup.chosen', (function(_this) { return function(evt) { _this.keyup_checker(evt); }; - })(this)); + }(this))); this.search_field.on('keydown.chosen', (function(_this) { return function(evt) { _this.keydown_checker(evt); }; - })(this)); + }(this))); this.search_field.on('focus.chosen', (function(_this) { return function(evt) { _this.input_focus(evt); }; - })(this)); + }(this))); this.search_field.on('cut.chosen', (function(_this) { return function(evt) { _this.clipboard_event_checker(evt); }; - })(this)); + }(this))); this.search_field.on('paste.chosen', (function(_this) { return function(evt) { _this.clipboard_event_checker(evt); }; - })(this)); + }(this))); if (this.is_multiple) { return this.search_choices.on('click.chosen', (function(_this) { return function(evt) { _this.choices_click(evt); }; - })(this)); + }(this))); } else { return this.container.on('click.chosen', function(evt) { evt.preventDefault(); @@ -1098,7 +1098,7 @@ This file is generated by `grunt build`, do not edit it by hand. return function(evt) { return _this.choice_destroy_link_click(evt); }; - })(this)); + }(this))); choice.append(close_link); } return this.search_container.before(choice); @@ -1164,6 +1164,10 @@ This file is generated by `grunt build`, do not edit it by hand. item = this.results_data[high[0].getAttribute("data-option-array-index")]; item.selected = true; this.form_field.options[item.options_index].selected = true; + + // Trigger the change event to it can be listened to. + const event = new Event('change', { bubbles: true }); + this.form_field.dispatchEvent(event); this.selected_option_count = null; if (this.is_multiple) { this.choice_build(item); @@ -1361,6 +1365,6 @@ This file is generated by `grunt build`, do not edit it by hand. return Chosen; - })(AbstractChosen); + }(AbstractChosen)); }).call(this); diff --git a/includes/views/js/import-metabox-edit.js b/includes/views/js/import-metabox-edit.js index 74f42ee7..8c6f1732 100644 --- a/includes/views/js/import-metabox-edit.js +++ b/includes/views/js/import-metabox-edit.js @@ -836,4 +836,29 @@ $( '.feedzy-open-media' ).html( feedzy.i10n.action_btn_text_1 ); }); } + + + /** + * BUG: When a user select a value for `inc_on` or `exc_on` and then modifies the filter the keywords, the last selected value is not retained. + * Temporary FIX: Store the selected value in the session storage and then re-add it when the form is submitted. + */ + document.querySelector('[name="feedzy_meta_data[inc_on]"]').addEventListener('change', (event) => { + sessionStorage.setItem('feedzy_meta_data[inc_on]', event.target.selectedIndex); + }); + + document.querySelector('[name="feedzy_meta_data[exc_on]"]').addEventListener('change', (event) => { + sessionStorage.setItem('feedzy_meta_data[exc_on]', event.target.selectedIndex); + }); + + document.querySelector('#post').addEventListener('submit', () => { + if (sessionStorage.getItem('feedzy_meta_data[inc_on]') !== null) { + document.querySelector('[name="feedzy_meta_data[inc_on]"]').selectedIndex = sessionStorage.getItem('feedzy_meta_data[inc_on]') ?? 0; + sessionStorage.removeItem('feedzy_meta_data[inc_on]'); + } + + if (sessionStorage.getItem('feedzy_meta_data[exc_on]') !== null) { + document.querySelector('[name="feedzy_meta_data[exc_on]"]').selectedIndex = sessionStorage.getItem('feedzy_meta_data[exc_on]') ?? 0; + sessionStorage.removeItem('feedzy_meta_data[exc_on]'); + } + }); }(jQuery, feedzy)); From f67a97e86af215e2917f79eacf691b9449c89988 Mon Sep 17 00:00:00 2001 From: "Soare Robert Daniel (Mac 2023)" Date: Mon, 4 Mar 2024 17:33:48 +0200 Subject: [PATCH 2/4] chore: undefined check --- includes/views/js/import-metabox-edit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/views/js/import-metabox-edit.js b/includes/views/js/import-metabox-edit.js index 8c6f1732..911c0276 100644 --- a/includes/views/js/import-metabox-edit.js +++ b/includes/views/js/import-metabox-edit.js @@ -842,11 +842,11 @@ * BUG: When a user select a value for `inc_on` or `exc_on` and then modifies the filter the keywords, the last selected value is not retained. * Temporary FIX: Store the selected value in the session storage and then re-add it when the form is submitted. */ - document.querySelector('[name="feedzy_meta_data[inc_on]"]').addEventListener('change', (event) => { + document.querySelector('[name="feedzy_meta_data[inc_on]"]')?.addEventListener('change', (event) => { sessionStorage.setItem('feedzy_meta_data[inc_on]', event.target.selectedIndex); }); - document.querySelector('[name="feedzy_meta_data[exc_on]"]').addEventListener('change', (event) => { + document.querySelector('[name="feedzy_meta_data[exc_on]"]')?.addEventListener('change', (event) => { sessionStorage.setItem('feedzy_meta_data[exc_on]', event.target.selectedIndex); }); From 72fa327c09e9bd7671c9ce5b2151f010505b2470 Mon Sep 17 00:00:00 2001 From: "Soare Robert Daniel (Mac 2023)" Date: Tue, 5 Mar 2024 10:41:11 +0200 Subject: [PATCH 3/4] fix: tags reset in metabox --- includes/views/js/import-metabox-edit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/views/js/import-metabox-edit.js b/includes/views/js/import-metabox-edit.js index 911c0276..4bef8aef 100644 --- a/includes/views/js/import-metabox-edit.js +++ b/includes/views/js/import-metabox-edit.js @@ -46,7 +46,7 @@ return false; } - outsideWrap.find( '.form-control' ).val(''); + outsideWrap.find( '.form-control .tag-list' )?.val(''); if ( outsideWrap.next( '.tag-list' ).length > 0 ) { outsideWrap. next( '.tag-list' ) From ff7776c7ec5a39cbcca8df2b45a756877e81fa0a Mon Sep 17 00:00:00 2001 From: "Soare Robert Daniel (Mac 2023)" Date: Tue, 5 Mar 2024 10:43:08 +0200 Subject: [PATCH 4/4] Revert "fix: filter key for select components" This reverts commit 6b11b813e5984688c3e0aef1c57df2ba9565e7de. --- includes/views/js/chosen.js | 64 +++++++++++------------- includes/views/js/import-metabox-edit.js | 25 --------- 2 files changed, 30 insertions(+), 59 deletions(-) diff --git a/includes/views/js/chosen.js b/includes/views/js/chosen.js index d4b258cc..d9d2eb04 100644 --- a/includes/views/js/chosen.js +++ b/includes/views/js/chosen.js @@ -91,7 +91,7 @@ This file is generated by `grunt build`, do not edit it by hand. return SelectParser; - }()); + })(); SelectParser.select_to_array = function(select) { var child, i, len, parser, ref; @@ -126,12 +126,12 @@ This file is generated by `grunt build`, do not edit it by hand. return function(evt) { return _this.test_active_click(evt); }; - }(this)); + })(this); this.activate_action = (function(_this) { return function(evt) { return _this.activate_field(evt); }; - }(this)); + })(this); this.active_field = false; this.mouse_on_container = false; this.results_showing = false; @@ -624,7 +624,7 @@ This file is generated by `grunt build`, do not edit it by hand. return AbstractChosen; - }()); + })(); $ = jQuery; @@ -715,123 +715,123 @@ This file is generated by `grunt build`, do not edit it by hand. return function(evt) { _this.container_mousedown(evt); }; - }(this))); + })(this)); this.container.on('touchend.chosen', (function(_this) { return function(evt) { _this.container_mouseup(evt); }; - }(this))); + })(this)); this.container.on('mousedown.chosen', (function(_this) { return function(evt) { _this.container_mousedown(evt); }; - }(this))); + })(this)); this.container.on('mouseup.chosen', (function(_this) { return function(evt) { _this.container_mouseup(evt); }; - }(this))); + })(this)); this.container.on('mouseenter.chosen', (function(_this) { return function(evt) { _this.mouse_enter(evt); }; - }(this))); + })(this)); this.container.on('mouseleave.chosen', (function(_this) { return function(evt) { _this.mouse_leave(evt); }; - }(this))); + })(this)); this.search_results.on('mouseup.chosen', (function(_this) { return function(evt) { _this.search_results_mouseup(evt); }; - }(this))); + })(this)); this.search_results.on('mouseover.chosen', (function(_this) { return function(evt) { _this.search_results_mouseover(evt); }; - }(this))); + })(this)); this.search_results.on('mouseout.chosen', (function(_this) { return function(evt) { _this.search_results_mouseout(evt); }; - }(this))); + })(this)); this.search_results.on('mousewheel.chosen DOMMouseScroll.chosen', (function(_this) { return function(evt) { _this.search_results_mousewheel(evt); }; - }(this))); + })(this)); this.search_results.on('touchstart.chosen', (function(_this) { return function(evt) { _this.search_results_touchstart(evt); }; - }(this))); + })(this)); this.search_results.on('touchmove.chosen', (function(_this) { return function(evt) { _this.search_results_touchmove(evt); }; - }(this))); + })(this)); this.search_results.on('touchend.chosen', (function(_this) { return function(evt) { _this.search_results_touchend(evt); }; - }(this))); + })(this)); this.form_field_jq.on("chosen:updated.chosen", (function(_this) { return function(evt) { _this.results_update_field(evt); }; - }(this))); + })(this)); this.form_field_jq.on("chosen:activate.chosen", (function(_this) { return function(evt) { _this.activate_field(evt); }; - }(this))); + })(this)); this.form_field_jq.on("chosen:open.chosen", (function(_this) { return function(evt) { _this.container_mousedown(evt); }; - }(this))); + })(this)); this.form_field_jq.on("chosen:close.chosen", (function(_this) { return function(evt) { _this.close_field(evt); }; - }(this))); + })(this)); this.search_field.on('blur.chosen', (function(_this) { return function(evt) { _this.input_blur(evt); }; - }(this))); + })(this)); this.search_field.on('keyup.chosen', (function(_this) { return function(evt) { _this.keyup_checker(evt); }; - }(this))); + })(this)); this.search_field.on('keydown.chosen', (function(_this) { return function(evt) { _this.keydown_checker(evt); }; - }(this))); + })(this)); this.search_field.on('focus.chosen', (function(_this) { return function(evt) { _this.input_focus(evt); }; - }(this))); + })(this)); this.search_field.on('cut.chosen', (function(_this) { return function(evt) { _this.clipboard_event_checker(evt); }; - }(this))); + })(this)); this.search_field.on('paste.chosen', (function(_this) { return function(evt) { _this.clipboard_event_checker(evt); }; - }(this))); + })(this)); if (this.is_multiple) { return this.search_choices.on('click.chosen', (function(_this) { return function(evt) { _this.choices_click(evt); }; - }(this))); + })(this)); } else { return this.container.on('click.chosen', function(evt) { evt.preventDefault(); @@ -1098,7 +1098,7 @@ This file is generated by `grunt build`, do not edit it by hand. return function(evt) { return _this.choice_destroy_link_click(evt); }; - }(this))); + })(this)); choice.append(close_link); } return this.search_container.before(choice); @@ -1164,10 +1164,6 @@ This file is generated by `grunt build`, do not edit it by hand. item = this.results_data[high[0].getAttribute("data-option-array-index")]; item.selected = true; this.form_field.options[item.options_index].selected = true; - - // Trigger the change event to it can be listened to. - const event = new Event('change', { bubbles: true }); - this.form_field.dispatchEvent(event); this.selected_option_count = null; if (this.is_multiple) { this.choice_build(item); @@ -1365,6 +1361,6 @@ This file is generated by `grunt build`, do not edit it by hand. return Chosen; - }(AbstractChosen)); + })(AbstractChosen); }).call(this); diff --git a/includes/views/js/import-metabox-edit.js b/includes/views/js/import-metabox-edit.js index 4bef8aef..e1c184f0 100644 --- a/includes/views/js/import-metabox-edit.js +++ b/includes/views/js/import-metabox-edit.js @@ -836,29 +836,4 @@ $( '.feedzy-open-media' ).html( feedzy.i10n.action_btn_text_1 ); }); } - - - /** - * BUG: When a user select a value for `inc_on` or `exc_on` and then modifies the filter the keywords, the last selected value is not retained. - * Temporary FIX: Store the selected value in the session storage and then re-add it when the form is submitted. - */ - document.querySelector('[name="feedzy_meta_data[inc_on]"]')?.addEventListener('change', (event) => { - sessionStorage.setItem('feedzy_meta_data[inc_on]', event.target.selectedIndex); - }); - - document.querySelector('[name="feedzy_meta_data[exc_on]"]')?.addEventListener('change', (event) => { - sessionStorage.setItem('feedzy_meta_data[exc_on]', event.target.selectedIndex); - }); - - document.querySelector('#post').addEventListener('submit', () => { - if (sessionStorage.getItem('feedzy_meta_data[inc_on]') !== null) { - document.querySelector('[name="feedzy_meta_data[inc_on]"]').selectedIndex = sessionStorage.getItem('feedzy_meta_data[inc_on]') ?? 0; - sessionStorage.removeItem('feedzy_meta_data[inc_on]'); - } - - if (sessionStorage.getItem('feedzy_meta_data[exc_on]') !== null) { - document.querySelector('[name="feedzy_meta_data[exc_on]"]').selectedIndex = sessionStorage.getItem('feedzy_meta_data[exc_on]') ?? 0; - sessionStorage.removeItem('feedzy_meta_data[exc_on]'); - } - }); }(jQuery, feedzy));