From f0628c310c8451429271afd602ad1c1b54082e4b Mon Sep 17 00:00:00 2001 From: Tieptk Date: Thu, 9 May 2024 11:16:07 +0700 Subject: [PATCH] global.js --- assets/script/global.js | 65 +++++++++++++++++++++++++++++++++++++++++ template/theme.html | 2 +- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 assets/script/global.js diff --git a/assets/script/global.js b/assets/script/global.js new file mode 100644 index 0000000..4b872c8 --- /dev/null +++ b/assets/script/global.js @@ -0,0 +1,65 @@ +"use strict"; +const AdminFunction = (() => { + function capNhatTrangThaiMenu(hideMenuBig) { + if (hideMenuBig === false) { + $('#js-admin-content-container').addClass('show-large-menu'); + } + else { + $('#js-admin-content-container').removeClass('show-large-menu'); + } + $('#js-menu-big').toggleClass('hidden', hideMenuBig); + $('#js-menu-small').toggleClass('hidden', !hideMenuBig); + $('#js-form-search').toggleClass('menu-hide', hideMenuBig); + localStorage.setItem(hideMenuBig ? 'menu_big' : 'menu_small', 'hidden'); + localStorage.removeItem(hideMenuBig ? 'menu_small' : 'menu_big'); + } + function debounce(func, wait, immediate) { + let timeout = null; + return function (...args) { + const context = this; + const later = function () { + timeout = null; + if (!immediate) + func.apply(context, args); + }; + const callNow = immediate && !timeout; + if (timeout !== null) { + clearTimeout(timeout); + } + timeout = setTimeout(later, wait); + if (callNow) + func.apply(context, args); + }; + } + function add_product_to_category(id) { + $('#status_' + id).html('Đang xử lý..'); + setTimeout(() => { + $('#status_' + id).html(''); + }, 1000); + } + function run_search(holder) { + $(holder).keyup(debounce(function () { + //const inputString = $(this).val(); + $('#js-show-search').show(); + }, 300, false)); // Cast debounce to any to avoid type inference issues + $('body').click(function () { + $("#js-show-search").hide(); + }); + } + function update_product_hot(id) { + $('#js-status-hottype-' + id).html('Đang xử lý..'); + setTimeout(() => { + $('#js-status-hottype-' + id).html(''); + }, 1000); + } + function searchSelect(holder) { + $(holder).select2(); + } + return { + capNhatTrangThaiMenu, + add_product_to_category, + run_search, + searchSelect, + update_product_hot + }; +})(); \ No newline at end of file diff --git a/template/theme.html b/template/theme.html index 34f8380..6fc3d4f 100644 --- a/template/theme.html +++ b/template/theme.html @@ -303,7 +303,7 @@ - + {% include javascript/index %}