From ae27bbe3c00e3988a25745a0b83c12a8240af777 Mon Sep 17 00:00:00 2001 From: marination Date: Mon, 29 Nov 2021 13:45:33 +0530 Subject: [PATCH 1/3] feat: Allow addition of custom search box - allow passing custom search box class to bind search actions on - this allows users to inject and get a custom search box running on any page --- erpnext/e_commerce/product_ui/search.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/erpnext/e_commerce/product_ui/search.js b/erpnext/e_commerce/product_ui/search.js index 9bae1c10bc4..a2d8566e750 100644 --- a/erpnext/e_commerce/product_ui/search.js +++ b/erpnext/e_commerce/product_ui/search.js @@ -1,7 +1,10 @@ erpnext.ProductSearch = class { - constructor() { + constructor(opts) { + /* Options: search_box_class (for custom search box) */ + $.extend(this, opts); this.MAX_RECENT_SEARCHES = 4; - this.searchBox = $("#search-box"); + this.search_box_class = this.search_box_class || "#search-box" + this.searchBox = $(this.search_box_class); this.setupSearchDropDown(); this.bindSearchAction(); @@ -24,7 +27,7 @@ erpnext.ProductSearch = class { // If click occurs outside search input/results, hide results. // Click can happen anywhere on the page $("body").on("click", (e) => { - let searchEvent = $(e.target).closest('#search-box').length; + let searchEvent = $(e.target).closest(this.search_box_class).length; let resultsEvent = $(e.target).closest('#search-results-container').length; let isResultHidden = this.search_dropdown.hasClass("hidden"); From 9ec58dec4d870a1cc81fa8873d3fc97f3532b495 Mon Sep 17 00:00:00 2001 From: marination Date: Mon, 29 Nov 2021 13:59:45 +0530 Subject: [PATCH 2/3] fix: Sider (missing semicolon) --- erpnext/e_commerce/product_ui/search.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/e_commerce/product_ui/search.js b/erpnext/e_commerce/product_ui/search.js index a2d8566e750..cfaf2cf109c 100644 --- a/erpnext/e_commerce/product_ui/search.js +++ b/erpnext/e_commerce/product_ui/search.js @@ -3,7 +3,7 @@ erpnext.ProductSearch = class { /* Options: search_box_class (for custom search box) */ $.extend(this, opts); this.MAX_RECENT_SEARCHES = 4; - this.search_box_class = this.search_box_class || "#search-box" + this.search_box_class = this.search_box_class || "#search-box"; this.searchBox = $(this.search_box_class); this.setupSearchDropDown(); From 7fec4ab88bdecdde02291ff6d055f9af634bdc6b Mon Sep 17 00:00:00 2001 From: marination Date: Mon, 29 Nov 2021 14:23:32 +0530 Subject: [PATCH 3/3] fix: search_box_id instead of search_box_class --- erpnext/e_commerce/product_ui/search.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/erpnext/e_commerce/product_ui/search.js b/erpnext/e_commerce/product_ui/search.js index cfaf2cf109c..61922459e56 100644 --- a/erpnext/e_commerce/product_ui/search.js +++ b/erpnext/e_commerce/product_ui/search.js @@ -1,10 +1,10 @@ erpnext.ProductSearch = class { constructor(opts) { - /* Options: search_box_class (for custom search box) */ + /* Options: search_box_id (for custom search box) */ $.extend(this, opts); this.MAX_RECENT_SEARCHES = 4; - this.search_box_class = this.search_box_class || "#search-box"; - this.searchBox = $(this.search_box_class); + this.search_box_id = this.search_box_id || "#search-box"; + this.searchBox = $(this.search_box_id); this.setupSearchDropDown(); this.bindSearchAction(); @@ -27,7 +27,7 @@ erpnext.ProductSearch = class { // If click occurs outside search input/results, hide results. // Click can happen anywhere on the page $("body").on("click", (e) => { - let searchEvent = $(e.target).closest(this.search_box_class).length; + let searchEvent = $(e.target).closest(this.search_box_id).length; let resultsEvent = $(e.target).closest('#search-results-container').length; let isResultHidden = this.search_dropdown.hasClass("hidden");