diff --git a/assets/admin/js/script.min.js b/assets/admin/js/script.min.js index 4f59acd..75a333d 100644 --- a/assets/admin/js/script.min.js +++ b/assets/admin/js/script.min.js @@ -1 +1 @@ -!function(e,t){"use strict";if(!e)return;let i=null;const n={cache(){n.els={},n.vars={},n.vars.widgetID='[id*="social_network_widget"]',n.vars.widgetName='[name*="social_network_widget"]',n.vars.colorpicker=".social-network-widget-color-picker",n.vars.iconsList=".social-network-icons-widget-list",n.vars.addBtnClassname=".social-network-widget.add-button button",n.vars.removeBtnClassname=".social-network-widget-item__remove a"},ready(){n.cache(),n.onAddClick(),n.onRemoveClick(),n.onOpen(),n.onAdded(),n.onUpdated(),n.onFocusOut(),n.onKeyDown(),n.onKeyUp(),n.onChange()},onAddClick(){t(document).on("click",n.vars.addBtnClassname,function(e){e.preventDefault(),e.stopPropagation();const i=t(t.trim(t("#tmpl-social-network-widget").html())),o=t(this).parents(".widget-content"),a=o.find(n.vars.iconsList),d=a.data("url-icon-id"),r=a.data("url-icon-name");i.find(".social-network-widget-item__url input").attr("id",d).attr("name",r+"[]"),a.append(i),o.find(".social-network-widget-item:last").find("input:first").trigger("focus")})},onRemoveClick(){t(document).on("click",n.vars.removeBtnClassname,function(e){e.preventDefault(),e.stopPropagation();const i=t(this).parents(".form").find(".widget-control-save");t(this).parents(".social-network-widget-item").remove(),n._livePreviewUpdate(i)})},onOpen(){t(document).on("click",`div.widget${n.vars.widgetID} .widget-title, div.widget${n.vars.widgetID} .widget-action`,function(){t(this).parents("#available-widgets").length>0||(n._initWidget(t(this).parents(`.widget${n.vars.widgetID}`)),n._initColorPicker(t(this).parents(`.widget${n.vars.widgetID}`)))})},onAdded(){t(document).on("widget-added",function(e,i){i.is(n.vars.widgetID)&&(e.preventDefault(),n._initWidget(i),n._initColorPicker(t(this).parents(`.widget${n.vars.widgetID}`)))})},onUpdated(){t(document).on("widget-updated",function(e,i){i.is(n.vars.widgetID)&&(e.preventDefault(),n._initWidget(i),n._initColorPicker(t(this)))})},onFocusOut(){t(document).on("focusout",`input${n.widgetName}`,function(){n._livePreviewUpdate(t(this).parents(".form").find(".widget-control-save"))})},onKeyDown(){t(document).on("keydown",`input${n.widgetName}`,function(e){13===e.keyCode&&n._livePreviewUpdate(t(this).parents(".form").find(".widget-control-save"))})},onKeyUp(){t(document).on("keyup",`input${n.widgetName}`,function(){clearTimeout(i),i=setTimeout(function(){n._livePreviewUpdate(t(this).parents(".form").find(".widget-control-save"))},1e3)})},onChange(){t(document).on("change",`select${n.widgetName}`,function(){t(this).parents(".form").find(".widget-control-save")})},_initWidget(e){e.find(n.vars.iconsList).sortable({items:"> .social-network-widget-item",handle:".handle",cursor:"move",axis:"y",placeholder:"social-network-widget-item ui-state-placeholder",containment:e,forcePlaceholderSize:!0,update(){n._livePreviewUpdate(t(this).parents(".form").find(".widget-control-save"))}})},_initColorPicker(e){e.find(n.vars.colorpicker).wpColorPicker({change:_.throttle(function(){t(this).trigger("change")},3e3)})},_livePreviewUpdate(e){t(document.body).hasClass("wp-customizer")&&e.length&&e.trigger("click").hide()}};t(document).ready(n.ready())}(window.wp,jQuery); \ No newline at end of file +!function(e,t){"use strict";if(!e)return;const r={cache(){r.els={},r.vars={},r.vars.name="social-network-widget",r.vars.id='[id*="social_network_widget"]',r.vars.list=".social-network-icons-widget-list",r.vars.color=`.${r.vars.name}-color-picker`,r.vars.add=`.${r.vars.name}.add-button button`,r.vars.remove=`.${r.vars.name}-item__remove a`,r.els.$doc=t(document)},ready(){r.cache(),r.onOpen(),r.onAdd(),r.onUpdate(),r.onRemove()},onOpen(){r.els.$doc.on("click",`div.widget${r.vars.id} .widget-title, div.widget${r.vars.id} .widget-action`,e=>{const a=t(e.target);a.parents("#available-widgets").length||(r._sortable(a.parents(`.widget${r.vars.id}`)),r._colorPicker(a.parents(`.widget${r.vars.id}`)))})},onAdd(){r.els.$doc.on("click",r.vars.add,e=>{e.preventDefault();const a=t(e.target),i=a.parents(`.widget${r.vars.id}`),n=t(t.trim(t(`#tmpl-${r.vars.name}`).html())),o=a.parents(".widget-content"),d=o.find(r.vars.list),s=d.data("url-icon-id"),c=d.data("url-icon-name");n.find(`.${r.vars.name}-item__url input`).attr("id",s).attr("name",`${c}[]`),d.append(n),o.find(`.${r.vars.name}-item:last`).find("input:first").trigger("focus"),r._triggerChange(i)})},onRemove(){r.els.$doc.on("click",r.vars.remove,e=>{e.preventDefault();const a=t(e.target),i=a.parents(`.widget${r.vars.id}`),n=a.parents(".form").find(".widget-control-save");a.parents(`.${r.vars.name}-item`).remove(),r._triggerChange(i),r._previewUpdate(n)})},onUpdate(){r.els.$doc.on("widget-updated",(e,t)=>{t.is(r.vars.id)&&(e.preventDefault(),r._sortable(t),r._colorPicker(t))})},_sortable(e){e.find(r.vars.list).sortable({axis:"y",items:`> .${r.vars.name}-item`,handle:".handle",cursor:"grabbing",placeholder:`${r.vars.name}-item ui-state-placeholder`,containment:e,forcePlaceholderSize:!0,start(e,t){t.placeholder.height(t.item.height())},update(a,i){r._triggerChange(e),r._previewUpdate(t(i).parents(".form").find(".widget-control-save"))}})},_colorPicker(e){e.find(r.vars.color).wpColorPicker({change:_.throttle(function(){t(this).trigger("change")},3e3)})},_triggerChange(e){e.find('input[name*="[title]"]').trigger("change")},_previewUpdate(e){!t(document.body).hasClass("wp-customizer")||!e.length>0||e.trigger("click").hide()}};t(document).ready(r.ready())}(window.wp,jQuery); \ No newline at end of file