Changeset 3393682
- Timestamp:
- 11/11/2025 01:13:53 PM (4 months ago)
- Location:
- coupon-countdown-timer
- Files:
-
- 4 edited
-
tags/1.0.0/assets/editor.min.js (modified) (1 diff)
-
tags/1.0.0/inc/class-admin.php (modified) (1 diff)
-
trunk/assets/editor.min.js (modified) (1 diff)
-
trunk/inc/class-admin.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
coupon-countdown-timer/tags/1.0.0/assets/editor.min.js
r3392436 r3393682 1 window.Coupon_Timer_App=null;import Utils from"./utils.min.js?v=1.0.0";import App_Watchers from"./partials/watch.min.js?v=1.0.0";import App_Methods from"./partials/methods.min.js?v=1.0.0";import Template_Methods from"./partials/methods-template.min.js?v=1.0.0";import Input_Color from"./modules/input-color.min.js?v=1.0.0";import Input_Image from"./modules/input-image.min.js?v=1.0.0";import WP_Editor from"./modules/input-wpeditor.min.js?v=1.0.0";import Input_Border from"./modules/input-border.min.js?v=1.0.0";import Input_Position from"./modules/input-position.min.js?v=1.0.0";import Input_Typography from"./modules/input-typography.min.js?v=1.0.0";import Input_Background from"./modules/input-background.min.js?v=1.0.0";import Input_Code_Editor from"./modules/input-code-editor.min.js?v=1.0.0";import Input_Font_Family from"./modules/input-font-family.min.js?v=1.0.0";import Input_Dimensions from"./modules/input-dimensions.min.js?v=1.0.0";import Input_Box_Shadow from"./modules/input-box-shadow.min.js?v=1.0.0";import Input_Range_Slider from"./modules/input-range-slider.min.js?v=1.0.0";import Display_Condition_Group from"./components/display-condition-group.min.js?v=1.0.0";(s=>{let o=wp.i18n.__,a=s("#coupon-countdown-timer-editor"),e=(window.addEventListener("message",e=>{var t,{source:o,action:n,data:i}=e.data;"coupon_countdown_timer"===o&&("preview_ready"===n&&(Utils.send_post_message(),Coupon_Timer_App.editor_preview_status="ready"),"template_structure_updated"===n&&(o=JSON.parse(i),!Array.isArray(o)&&"object"!=typeof o||(e.data?.default_settings&&"object"==typeof(i=JSON.parse(e.data?.default_settings||"{}"))&&((t={id:e.data.new_element,...Coupon_Timer_App.elements_settings_data[e.data.new_element]}).settings=i,Coupon_Timer_App.elements_settings_data[e.data.new_element]={...t},e.data?.new_element)&&Utils.get_dynamic_content(t),Coupon_Timer_App.elements_data=Utils.sanitize_element_item_data(o),Coupon_Timer_App.set_current_element_data(e.data?.new_element))),"edit_element"===n)&&Coupon_Timer_App.set_current_element_data(e.data.id)}),wp.hooks.applyFilters("coupon_countdown_timer_helper_models",{saving:!1,current_modal:"",loading_app:!0,used_colors:[],custom_style_collapse:!1,retrive_readymade_templates:!1,editor_preview_status:"loading",toast_message:null,show_toast_message:!1,toast_message_type:"error",preview_template_id:null,customize_template_id:null,preview_template_status:"",customize_template_importing:!1,main_navigation:"primary-settings",current_device:"desktop",coupon_settings_current_tab:"general",editing_element_data:null,editing_element_current_tab:"",structure_item_opened:[],last_dynamic_element_id:null,hold_dynamic_elements_content:{},hold_readymade_templates:coupon_countdown_timer_editor.readymade_templates})),n=0;var t={data(){return{id:0,title:"",coupon_code:"",custom_css:"",status:"draft",view_type:"popup",elements_data:null,generated_styles:{},used_fonts:[],display_conditions:null,coupon_timer_styles:{},coupon_timer_settings:{},settings_panel_position:{top:150,left:200},expiry_date:coupon_countdown_timer_editor.new_expiry_date,element_structure_position:{top:150,left:s(window).width()-400},...e,...coupon_countdown_timer_editor.coupon_models}},components:{"display-condition-group":Display_Condition_Group},computed:{is_pro_activated(){return wp.hooks.applyFilters("coupon_countdown_timer_editor.is_pro_activated",!1)},current_screen(){return["primary-settings","choose-template"].includes(this.main_navigation)?this.main_navigation:"editor"},get_root_element(){return s(this.$el.parentElement)},watch_coupon_data(){return JSON.stringify({view_type:this.view_type,coupon_code:this.coupon_code,expiry_dates:this.additional_expiry_dates})},coupon_stringify_data(){let t=JSON.parse(JSON.stringify(this.$data));return delete t.id,Object.keys(e).forEach(e=>delete t[e]),JSON.stringify(t)},readymade_templates(){return this.hold_readymade_templates},has_readymade_templates(){return"object"==typeof this.readymade_templates&&0<Object.values(this.readymade_templates).length},editor_iframe_classes(){var e=["current-view-"+this.current_device];return"ready"==this.editor_preview_status&&e.push("preview-ready"),e.join(" ")},get_preview_url(){return coupon_countdown_timer_editor.site_url+"?cct-preview="+this.id+"&nonce="+coupon_countdown_timer_editor.preview_nonce},get_view_type_settings_title(){return{popup:o("Popup Settings","coupon-countdown-timer"),stickybar:o("Stickybar Settings","coupon-countdown-timer"),floating_box:o("Floating Settings","coupon-countdown-timer")}[this.view_type]},show_settings_panel(){return null!==this.editing_element_data||"coupon-timer-settings"==this.main_navigation},get_current_element_id(){return this.editing_element_data?.id},get_current_element_type(){return this.editing_element_data?.type},get_panel_title(){return this.get_element_title(this.get_current_element_type)},has_elements_data(){return!(!Array.isArray(this.elements_data)||!this.elements_data)&&0<this.elements_data?.length},elements_settings_data(){return this.capture_elements_settings_data(this.elements_data)},editing_element_settings_string(){return JSON.stringify(this.editing_element_data?.settings||"")},editing_element_style_string(){return JSON.stringify({...this.editing_element_data?.styles,custom_css:this.editing_element_data?.custom_css})},get_shortcode_text(){return`[coupon_countdown_timer id="${this.id}"]`}},watch:{...App_Watchers,...wp.hooks.applyFilters("coupon_countdown_timer_editor_watch",{},{Utils:Utils}),loading_app(){!1===this.loading_app&&this.get_root_element.removeClass("loading")},editor_preview_status(e){"failed"===e&&(this.current_modal="preview-failed")}},beforeMount(){var e;Utils.coupon_app=this,(window.Coupon_Timer_App=this).elements_data?.length&&0<this.id&&(this.main_navigation="editor"),"display-settings"===new URLSearchParams(window.location.search).get("screen")&&(this.main_navigation="display-settings",(e=new URL(window.location.href)).searchParams.delete("screen"),window.history.replaceState({},document.title,e.toString())),this.sanitize_coupon_data(),this.elements_data&&(this.elements_data=Utils.sanitize_element_item_data(this.elements_data)),this.display_conditions||(this.display_conditions=[[{group:"general:all"}]])},mounted(){let t=this,e=(this.loading_app=!1,0),o=setInterval(()=>{if(e+=5,"ready"==this.editor_preview_status)return clearInterval(o);35<=e&&(this.editor_preview_status="failed",clearInterval(o))},5e3);this.generate_stylesheets(),a.on("click",".cct-custom-dropdown:not(.opened)",function(){a.find(".cct-custom-dropdown").removeClass("opened"),s(this).addClass("opened")}),a.on("click",".cct-custom-dropdown.opened span",function(){a.find(".cct-custom-dropdown").removeClass("opened")}),s(document).keyup(function(e){"Escape"===e.key&&(t.close_modal(),t.preview_template_id=null,a.find(".cct-custom-dropdown").removeClass("opened"),a.find(".coupon-countdown-popover").removeClass("opened"))}),s("body").on("click",function(e){s(e.target).closest(".cct-custom-dropdown").length||a.find(".cct-custom-dropdown").removeClass("opened"),s(e.target).closest(".coupon-countdown-popover").length||s(".cct-color-picker.visible").length||s(e.target).closest(".cct-custom-dropdown").length||a.find(".coupon-countdown-popover").removeClass("opened")}),s("body").on("click",".coupon-countdown-timer-modal",function(e){s(e.target).closest(".coupon-countdown-timer-modal .modal-body").length||t.close_modal()}),a.on("click",".btn-popover",function(e){e.stopPropagation();var e=s(this).closest(".field-row-item").find(".coupon-countdown-popover").toggleClass("opened"),t=(a.find(".coupon-countdown-popover").not(e).removeClass("opened"),s("body").find("#coupon-settings-panel")),o=t.offset();e.css({width:t.outerWidth()-30,left:o.left+15+"px",top:s(this).offset().top+35+"px"})});var n=!1,i={panel:null,x:0,y:0};s(document).on("mousedown","#coupon-settings-panel .panel-heading",function(e){n=!0,i.panel="settings-panel",i.x=e.pageX-s("#coupon-settings-panel").offset().left,i.y=e.pageY-s("#coupon-settings-panel").offset().top,e.preventDefault()}),s(document).on("mousedown","#coupon-element-structure .header",function(e){n=!0,i.panel="element-structure",i.x=e.pageX-s("#coupon-element-structure").offset().left,i.y=e.pageY-s("#coupon-element-structure").offset().top,e.preventDefault()}),s(document).on("mousemove",function(e){n&&"settings-panel"==i.panel&&(t.settings_panel_position={top:e.pageY-i.y,left:e.pageX-i.x}),n&&"element-structure"==i.panel&&(t.element_structure_position={top:e.pageY-i.y,left:e.pageX-i.x})}),s(document).on("mouseup",function(){n=!1})},methods:{...App_Methods,...Template_Methods,...wp.hooks.applyFilters("coupon_countdown_timer.editor_methods",{}),get_responsive_model_key(e){return"desktop"===this.current_device?e:e+"_"+this.current_device},window_reload(){window.location.reload()},validate_coupon(){return this.title?.length?160<this.title?.length?{input:"coupon-title-input",message:o("Please enter a coupon title of up to 160 characters.","coupon-countdown-timer")}:this.coupon_code?.length?!!this.expiry_date?.length||{input:"expiry-date-input",message:o("Please set an expiry date to specify when this coupon should expire.","coupon-countdown-timer")}:{input:"coupon-code-input",message:o("Please enter the coupon code. Coupon code is required.","coupon-countdown-timer")}:{input:"coupon-title-input",message:o("Please provide a title for the coupon at the top.","coupon-countdown-timer")}},get_element_title(e){return coupon_countdown_timer_global.elements?.[e]?.title},close_modal(){this.current_modal=null},copy_coupon_shortcode(){navigator.clipboard.writeText(this.get_shortcode_text).then(()=>{this.set_toast_message(o("Shortcode copied! You can now paste it wherever needed.","coupon-countdown-timer"),"success")})},set_toast_message(e,t="error"){e&&(this.toast_message=e,this.show_toast_message=!0,this.toast_message_type=t,clearTimeout(n),n=setTimeout(()=>this.show_toast_message=!1,3500))},save_display_settings(e=!1){!1===e&&this.save("display_settings"),e&&(this.main_navigation="")},save(e=null){var t=this.validate_coupon();if(!0!==t)return this.$refs?.[t?.input]?.focus(),this.set_toast_message(t.message);this.saving=!0;t=new FormData;t.append("id",this.id),t.append("data",this.coupon_stringify_data),t.append("nonce",this.get_root_element.data("nonce")),t.append("action","coupon_countdown_timer/save_coupon"),fetch(coupon_countdown_timer_global.ajax_url,{method:"POST",body:t}).then(async e=>{var t=await e.json();if("object"!=typeof t||!e.ok)throw new Error(o("Something went wrong while saving the data.","coupon-countdown-timer"));if(!1===t.success)throw new Error(t?.data?.message); this.id=t.data.id,t?.data?.new&&((e=new URL(window.location.href)).searchParams.set("id",t.data.id),e.searchParams.set("screen","display-settings"),window.location=e.toString()),this.set_toast_message(o("Successfully saved coupon.","coupon-countdown-timer"),"success")}).catch(e=>this.set_toast_message(e.message)).finally(()=>{this.saving=!1,"display_settings"==e&&this.save_display_settings(!0)})}}};if(s("#coupon-countdown-timer-editor").length){Coupon_Timer_App=Vue.createApp(t);var i,r={"input-color":Input_Color,"input-image":Input_Image,"input-wpeditor":WP_Editor,"input-border":Input_Border,"input-position":Input_Position,"input-background":Input_Background,"input-typography":Input_Typography,"input-font-family":Input_Font_Family,"input-dimensions":Input_Dimensions,"input-box-shadow":Input_Box_Shadow,"input-code-editor":Input_Code_Editor,"input-range-slider":Input_Range_Slider};for(i in r)Coupon_Timer_App.component(i,r[i]);Coupon_Timer_App.mount("#coupon-countdown-timer-editor")}s("body").on("click","#coupon-element-structure .btn-collapse",function(e){e.stopPropagation();var e=s(this).closest(".container-item").data("id"),t=Coupon_Timer_App.structure_item_opened.indexOf(e);-1!==t?Coupon_Timer_App.structure_item_opened.splice(t,1):Coupon_Timer_App.structure_item_opened.push(e)}),s("body").on("click","#coupon-element-structure [data-id]",function(e){e.preventDefault(),e.stopPropagation(),"coupon-timer-settings"===s(this).data("id")?Coupon_Timer_App.update_main_navigation("coupon-timer-settings"):Coupon_Timer_App.set_current_element_data(s(this).data("id"))}),s("body").on("dragstart","#elements-container .element-item",function(e){e=s(e.target).data("type");window.coupon_countdown_timer_element_drag_data={id:Utils.generate_uuid(),type:e}}),s("#coupon-countdown-timer-editor").on("dragend","#elements-container .element-item",function(e){Coupon_Timer_App.$refs["editor-preview"]?.contentWindow.postMessage({source:"coupon_countdown_timer",action:"element_dragend"},"*")})})(jQuery);1 window.Coupon_Timer_App=null;import Utils from"./utils.min.js?v=1.0.0";import App_Watchers from"./partials/watch.min.js?v=1.0.0";import App_Methods from"./partials/methods.min.js?v=1.0.0";import Template_Methods from"./partials/methods-template.min.js?v=1.0.0";import Input_Color from"./modules/input-color.min.js?v=1.0.0";import Input_Image from"./modules/input-image.min.js?v=1.0.0";import WP_Editor from"./modules/input-wpeditor.min.js?v=1.0.0";import Input_Border from"./modules/input-border.min.js?v=1.0.0";import Input_Position from"./modules/input-position.min.js?v=1.0.0";import Input_Typography from"./modules/input-typography.min.js?v=1.0.0";import Input_Background from"./modules/input-background.min.js?v=1.0.0";import Input_Code_Editor from"./modules/input-code-editor.min.js?v=1.0.0";import Input_Font_Family from"./modules/input-font-family.min.js?v=1.0.0";import Input_Dimensions from"./modules/input-dimensions.min.js?v=1.0.0";import Input_Box_Shadow from"./modules/input-box-shadow.min.js?v=1.0.0";import Input_Range_Slider from"./modules/input-range-slider.min.js?v=1.0.0";import Display_Condition_Group from"./components/display-condition-group.min.js?v=1.0.0";(s=>{let o=wp.i18n.__,a=s("#coupon-countdown-timer-editor"),e=(window.addEventListener("message",e=>{var t,{source:o,action:n,data:i}=e.data;"coupon_countdown_timer"===o&&("preview_ready"===n&&(Utils.send_post_message(),Coupon_Timer_App.editor_preview_status="ready"),"template_structure_updated"===n&&(o=JSON.parse(i),!Array.isArray(o)&&"object"!=typeof o||(e.data?.default_settings&&"object"==typeof(i=JSON.parse(e.data?.default_settings||"{}"))&&((t={id:e.data.new_element,...Coupon_Timer_App.elements_settings_data[e.data.new_element]}).settings=i,Coupon_Timer_App.elements_settings_data[e.data.new_element]={...t},e.data?.new_element)&&Utils.get_dynamic_content(t),Coupon_Timer_App.elements_data=Utils.sanitize_element_item_data(o),Coupon_Timer_App.set_current_element_data(e.data?.new_element))),"edit_element"===n)&&Coupon_Timer_App.set_current_element_data(e.data.id)}),wp.hooks.applyFilters("coupon_countdown_timer_helper_models",{saving:!1,current_modal:"",loading_app:!0,used_colors:[],custom_style_collapse:!1,retrive_readymade_templates:!1,editor_preview_status:"loading",toast_message:null,show_toast_message:!1,toast_message_type:"error",preview_template_id:null,customize_template_id:null,preview_template_status:"",customize_template_importing:!1,main_navigation:"primary-settings",current_device:"desktop",coupon_settings_current_tab:"general",editing_element_data:null,editing_element_current_tab:"",structure_item_opened:[],last_dynamic_element_id:null,hold_dynamic_elements_content:{},hold_readymade_templates:coupon_countdown_timer_editor.readymade_templates})),n=0;var t={data(){return{id:0,title:"",coupon_code:"",custom_css:"",status:"draft",view_type:"popup",elements_data:null,generated_styles:{},used_fonts:[],display_conditions:null,coupon_timer_styles:{},coupon_timer_settings:{},settings_panel_position:{top:150,left:200},expiry_date:coupon_countdown_timer_editor.new_expiry_date,element_structure_position:{top:150,left:s(window).width()-400},...e,...coupon_countdown_timer_editor.coupon_models}},components:{"display-condition-group":Display_Condition_Group},computed:{is_pro_activated(){return wp.hooks.applyFilters("coupon_countdown_timer_editor.is_pro_activated",!1)},current_screen(){return["primary-settings","choose-template"].includes(this.main_navigation)?this.main_navigation:"editor"},get_root_element(){return s(this.$el.parentElement)},watch_coupon_data(){return JSON.stringify({view_type:this.view_type,coupon_code:this.coupon_code,expiry_dates:this.additional_expiry_dates})},coupon_stringify_data(){let t=JSON.parse(JSON.stringify(this.$data));return delete t.id,Object.keys(e).forEach(e=>delete t[e]),JSON.stringify(t)},readymade_templates(){return this.hold_readymade_templates},has_readymade_templates(){return"object"==typeof this.readymade_templates&&0<Object.values(this.readymade_templates).length},editor_iframe_classes(){var e=["current-view-"+this.current_device];return"ready"==this.editor_preview_status&&e.push("preview-ready"),e.join(" ")},get_preview_url(){return coupon_countdown_timer_editor.site_url+"?cct-preview="+this.id+"&nonce="+coupon_countdown_timer_editor.preview_nonce},get_view_type_settings_title(){return{popup:o("Popup Settings","coupon-countdown-timer"),stickybar:o("Stickybar Settings","coupon-countdown-timer"),floating_box:o("Floating Settings","coupon-countdown-timer")}[this.view_type]},show_settings_panel(){return null!==this.editing_element_data||"coupon-timer-settings"==this.main_navigation},get_current_element_id(){return this.editing_element_data?.id},get_current_element_type(){return this.editing_element_data?.type},get_panel_title(){return this.get_element_title(this.get_current_element_type)},has_elements_data(){return!(!Array.isArray(this.elements_data)||!this.elements_data)&&0<this.elements_data?.length},elements_settings_data(){return this.capture_elements_settings_data(this.elements_data)},editing_element_settings_string(){return JSON.stringify(this.editing_element_data?.settings||"")},editing_element_style_string(){return JSON.stringify({...this.editing_element_data?.styles,custom_css:this.editing_element_data?.custom_css})},get_shortcode_text(){return`[coupon_countdown_timer id="${this.id}"]`}},watch:{...App_Watchers,...wp.hooks.applyFilters("coupon_countdown_timer_editor_watch",{},{Utils:Utils}),loading_app(){!1===this.loading_app&&this.get_root_element.removeClass("loading")},editor_preview_status(e){"failed"===e&&(this.current_modal="preview-failed")}},beforeMount(){var e;Utils.coupon_app=this,(window.Coupon_Timer_App=this).elements_data?.length&&0<this.id&&(this.main_navigation="editor"),"display-settings"===new URLSearchParams(window.location.search).get("screen")&&(this.main_navigation="display-settings",(e=new URL(window.location.href)).searchParams.delete("screen"),window.history.replaceState({},document.title,e.toString())),this.sanitize_coupon_data(),this.elements_data&&(this.elements_data=Utils.sanitize_element_item_data(this.elements_data)),this.display_conditions||(this.display_conditions=[[{group:"general:all"}]])},mounted(){let t=this,e=(this.loading_app=!1,0),o=setInterval(()=>{if(e+=5,"ready"==this.editor_preview_status)return clearInterval(o);35<=e&&(this.editor_preview_status="failed",clearInterval(o))},5e3);this.generate_stylesheets(),a.on("click",".cct-custom-dropdown:not(.opened)",function(){a.find(".cct-custom-dropdown").removeClass("opened"),s(this).addClass("opened")}),a.on("click",".cct-custom-dropdown.opened span",function(){a.find(".cct-custom-dropdown").removeClass("opened")}),s(document).keyup(function(e){"Escape"===e.key&&(t.close_modal(),t.preview_template_id=null,a.find(".cct-custom-dropdown").removeClass("opened"),a.find(".coupon-countdown-popover").removeClass("opened"))}),s("body").on("click",function(e){s(e.target).closest(".cct-custom-dropdown").length||a.find(".cct-custom-dropdown").removeClass("opened"),s(e.target).closest(".coupon-countdown-popover").length||s(".cct-color-picker.visible").length||s(e.target).closest(".cct-custom-dropdown").length||a.find(".coupon-countdown-popover").removeClass("opened")}),s("body").on("click",".coupon-countdown-timer-modal",function(e){s(e.target).closest(".coupon-countdown-timer-modal .modal-body").length||t.close_modal()}),a.on("click",".btn-popover",function(e){e.stopPropagation();var e=s(this).closest(".field-row-item").find(".coupon-countdown-popover").toggleClass("opened"),t=(a.find(".coupon-countdown-popover").not(e).removeClass("opened"),s("body").find("#coupon-settings-panel")),o=t.offset();e.css({width:t.outerWidth()-30,left:o.left+15+"px",top:s(this).offset().top+35+"px"})});var n=!1,i={panel:null,x:0,y:0};s(document).on("mousedown","#coupon-settings-panel .panel-heading",function(e){n=!0,i.panel="settings-panel",i.x=e.pageX-s("#coupon-settings-panel").offset().left,i.y=e.pageY-s("#coupon-settings-panel").offset().top,e.preventDefault()}),s(document).on("mousedown","#coupon-element-structure .header",function(e){n=!0,i.panel="element-structure",i.x=e.pageX-s("#coupon-element-structure").offset().left,i.y=e.pageY-s("#coupon-element-structure").offset().top,e.preventDefault()}),s(document).on("mousemove",function(e){n&&"settings-panel"==i.panel&&(t.settings_panel_position={top:e.pageY-i.y,left:e.pageX-i.x}),n&&"element-structure"==i.panel&&(t.element_structure_position={top:e.pageY-i.y,left:e.pageX-i.x})}),s(document).on("mouseup",function(){n=!1})},methods:{...App_Methods,...Template_Methods,...wp.hooks.applyFilters("coupon_countdown_timer.editor_methods",{}),get_responsive_model_key(e){return"desktop"===this.current_device?e:e+"_"+this.current_device},window_reload(){window.location.reload()},validate_coupon(){return this.title?.length?160<this.title?.length?{input:"coupon-title-input",message:o("Please enter a coupon title of up to 160 characters.","coupon-countdown-timer")}:this.coupon_code?.length?!!this.expiry_date?.length||{input:"expiry-date-input",message:o("Please set an expiry date to specify when this coupon should expire.","coupon-countdown-timer")}:{input:"coupon-code-input",message:o("Please enter the coupon code. Coupon code is required.","coupon-countdown-timer")}:{input:"coupon-title-input",message:o("Please provide a title for the coupon at the top.","coupon-countdown-timer")}},get_element_title(e){return coupon_countdown_timer_global.elements?.[e]?.title},close_modal(){this.current_modal=null},copy_coupon_shortcode(){navigator.clipboard.writeText(this.get_shortcode_text).then(()=>{this.set_toast_message(o("Shortcode copied! You can now paste it wherever needed.","coupon-countdown-timer"),"success")})},set_toast_message(e,t="error"){e&&(this.toast_message=e,this.show_toast_message=!0,this.toast_message_type=t,clearTimeout(n),n=setTimeout(()=>this.show_toast_message=!1,3500))},save_display_settings(e=!1){!1===e&&this.save("display_settings"),e&&(this.main_navigation="")},save(e=null){var t=this.validate_coupon();if(!0!==t)return this.$refs?.[t?.input]?.focus(),this.set_toast_message(t.message);this.saving=!0;t=new FormData;t.append("id",this.id),t.append("data",this.coupon_stringify_data),t.append("nonce",this.get_root_element.data("nonce")),t.append("action","coupon_countdown_timer/save_coupon"),fetch(coupon_countdown_timer_global.ajax_url,{method:"POST",body:t}).then(async e=>{var t=await e.json();if("object"!=typeof t||!e.ok)throw new Error(o("Something went wrong while saving the data.","coupon-countdown-timer"));if(!1===t.success)throw new Error(t?.data?.message);console.log(t.data),this.id=t.data.id,t?.data?.new&&((e=new URL(window.location.href)).searchParams.set("id",t.data.id),e.searchParams.set("screen","display-settings"),window.location=t.data.edit_url),this.set_toast_message(o("Successfully saved coupon.","coupon-countdown-timer"),"success")}).catch(e=>this.set_toast_message(e.message)).finally(()=>{this.saving=!1,"display_settings"==e&&this.save_display_settings(!0)})}}};if(s("#coupon-countdown-timer-editor").length){Coupon_Timer_App=Vue.createApp(t);var i,r={"input-color":Input_Color,"input-image":Input_Image,"input-wpeditor":WP_Editor,"input-border":Input_Border,"input-position":Input_Position,"input-background":Input_Background,"input-typography":Input_Typography,"input-font-family":Input_Font_Family,"input-dimensions":Input_Dimensions,"input-box-shadow":Input_Box_Shadow,"input-code-editor":Input_Code_Editor,"input-range-slider":Input_Range_Slider};for(i in r)Coupon_Timer_App.component(i,r[i]);Coupon_Timer_App.mount("#coupon-countdown-timer-editor")}s("body").on("click","#coupon-element-structure .btn-collapse",function(e){e.stopPropagation();var e=s(this).closest(".container-item").data("id"),t=Coupon_Timer_App.structure_item_opened.indexOf(e);-1!==t?Coupon_Timer_App.structure_item_opened.splice(t,1):Coupon_Timer_App.structure_item_opened.push(e)}),s("body").on("click","#coupon-element-structure [data-id]",function(e){e.preventDefault(),e.stopPropagation(),"coupon-timer-settings"===s(this).data("id")?Coupon_Timer_App.update_main_navigation("coupon-timer-settings"):Coupon_Timer_App.set_current_element_data(s(this).data("id"))}),s("body").on("dragstart","#elements-container .element-item",function(e){e=s(e.target).data("type");window.coupon_countdown_timer_element_drag_data={id:Utils.generate_uuid(),type:e}}),s("#coupon-countdown-timer-editor").on("dragend","#elements-container .element-item",function(e){Coupon_Timer_App.$refs["editor-preview"]?.contentWindow.postMessage({source:"coupon_countdown_timer",action:"element_dragend"},"*")})})(jQuery); -
coupon-countdown-timer/tags/1.0.0/inc/class-admin.php
r3392298 r3393682 115 115 } 116 116 117 wp_send_json_success(array('id' => $coupon->get_id(), 'new' => $coupon->is_new())); 117 $new_coupon_url = add_query_arg(array( 118 'id' => $coupon->get_id(), 119 'nonce' => wp_create_nonce('_nonce_coupon_countdown_timer_editor') 120 ), admin_url('admin.php?page=coupon-countdown-timer-edit') ); 121 122 wp_send_json_success(array('id' => $coupon->get_id(), 'new' => $coupon->is_new(), 'edit_url' => $new_coupon_url)); 118 123 } 119 124 -
coupon-countdown-timer/trunk/assets/editor.min.js
r3392436 r3393682 1 window.Coupon_Timer_App=null;import Utils from"./utils.min.js?v=1.0.0";import App_Watchers from"./partials/watch.min.js?v=1.0.0";import App_Methods from"./partials/methods.min.js?v=1.0.0";import Template_Methods from"./partials/methods-template.min.js?v=1.0.0";import Input_Color from"./modules/input-color.min.js?v=1.0.0";import Input_Image from"./modules/input-image.min.js?v=1.0.0";import WP_Editor from"./modules/input-wpeditor.min.js?v=1.0.0";import Input_Border from"./modules/input-border.min.js?v=1.0.0";import Input_Position from"./modules/input-position.min.js?v=1.0.0";import Input_Typography from"./modules/input-typography.min.js?v=1.0.0";import Input_Background from"./modules/input-background.min.js?v=1.0.0";import Input_Code_Editor from"./modules/input-code-editor.min.js?v=1.0.0";import Input_Font_Family from"./modules/input-font-family.min.js?v=1.0.0";import Input_Dimensions from"./modules/input-dimensions.min.js?v=1.0.0";import Input_Box_Shadow from"./modules/input-box-shadow.min.js?v=1.0.0";import Input_Range_Slider from"./modules/input-range-slider.min.js?v=1.0.0";import Display_Condition_Group from"./components/display-condition-group.min.js?v=1.0.0";(s=>{let o=wp.i18n.__,a=s("#coupon-countdown-timer-editor"),e=(window.addEventListener("message",e=>{var t,{source:o,action:n,data:i}=e.data;"coupon_countdown_timer"===o&&("preview_ready"===n&&(Utils.send_post_message(),Coupon_Timer_App.editor_preview_status="ready"),"template_structure_updated"===n&&(o=JSON.parse(i),!Array.isArray(o)&&"object"!=typeof o||(e.data?.default_settings&&"object"==typeof(i=JSON.parse(e.data?.default_settings||"{}"))&&((t={id:e.data.new_element,...Coupon_Timer_App.elements_settings_data[e.data.new_element]}).settings=i,Coupon_Timer_App.elements_settings_data[e.data.new_element]={...t},e.data?.new_element)&&Utils.get_dynamic_content(t),Coupon_Timer_App.elements_data=Utils.sanitize_element_item_data(o),Coupon_Timer_App.set_current_element_data(e.data?.new_element))),"edit_element"===n)&&Coupon_Timer_App.set_current_element_data(e.data.id)}),wp.hooks.applyFilters("coupon_countdown_timer_helper_models",{saving:!1,current_modal:"",loading_app:!0,used_colors:[],custom_style_collapse:!1,retrive_readymade_templates:!1,editor_preview_status:"loading",toast_message:null,show_toast_message:!1,toast_message_type:"error",preview_template_id:null,customize_template_id:null,preview_template_status:"",customize_template_importing:!1,main_navigation:"primary-settings",current_device:"desktop",coupon_settings_current_tab:"general",editing_element_data:null,editing_element_current_tab:"",structure_item_opened:[],last_dynamic_element_id:null,hold_dynamic_elements_content:{},hold_readymade_templates:coupon_countdown_timer_editor.readymade_templates})),n=0;var t={data(){return{id:0,title:"",coupon_code:"",custom_css:"",status:"draft",view_type:"popup",elements_data:null,generated_styles:{},used_fonts:[],display_conditions:null,coupon_timer_styles:{},coupon_timer_settings:{},settings_panel_position:{top:150,left:200},expiry_date:coupon_countdown_timer_editor.new_expiry_date,element_structure_position:{top:150,left:s(window).width()-400},...e,...coupon_countdown_timer_editor.coupon_models}},components:{"display-condition-group":Display_Condition_Group},computed:{is_pro_activated(){return wp.hooks.applyFilters("coupon_countdown_timer_editor.is_pro_activated",!1)},current_screen(){return["primary-settings","choose-template"].includes(this.main_navigation)?this.main_navigation:"editor"},get_root_element(){return s(this.$el.parentElement)},watch_coupon_data(){return JSON.stringify({view_type:this.view_type,coupon_code:this.coupon_code,expiry_dates:this.additional_expiry_dates})},coupon_stringify_data(){let t=JSON.parse(JSON.stringify(this.$data));return delete t.id,Object.keys(e).forEach(e=>delete t[e]),JSON.stringify(t)},readymade_templates(){return this.hold_readymade_templates},has_readymade_templates(){return"object"==typeof this.readymade_templates&&0<Object.values(this.readymade_templates).length},editor_iframe_classes(){var e=["current-view-"+this.current_device];return"ready"==this.editor_preview_status&&e.push("preview-ready"),e.join(" ")},get_preview_url(){return coupon_countdown_timer_editor.site_url+"?cct-preview="+this.id+"&nonce="+coupon_countdown_timer_editor.preview_nonce},get_view_type_settings_title(){return{popup:o("Popup Settings","coupon-countdown-timer"),stickybar:o("Stickybar Settings","coupon-countdown-timer"),floating_box:o("Floating Settings","coupon-countdown-timer")}[this.view_type]},show_settings_panel(){return null!==this.editing_element_data||"coupon-timer-settings"==this.main_navigation},get_current_element_id(){return this.editing_element_data?.id},get_current_element_type(){return this.editing_element_data?.type},get_panel_title(){return this.get_element_title(this.get_current_element_type)},has_elements_data(){return!(!Array.isArray(this.elements_data)||!this.elements_data)&&0<this.elements_data?.length},elements_settings_data(){return this.capture_elements_settings_data(this.elements_data)},editing_element_settings_string(){return JSON.stringify(this.editing_element_data?.settings||"")},editing_element_style_string(){return JSON.stringify({...this.editing_element_data?.styles,custom_css:this.editing_element_data?.custom_css})},get_shortcode_text(){return`[coupon_countdown_timer id="${this.id}"]`}},watch:{...App_Watchers,...wp.hooks.applyFilters("coupon_countdown_timer_editor_watch",{},{Utils:Utils}),loading_app(){!1===this.loading_app&&this.get_root_element.removeClass("loading")},editor_preview_status(e){"failed"===e&&(this.current_modal="preview-failed")}},beforeMount(){var e;Utils.coupon_app=this,(window.Coupon_Timer_App=this).elements_data?.length&&0<this.id&&(this.main_navigation="editor"),"display-settings"===new URLSearchParams(window.location.search).get("screen")&&(this.main_navigation="display-settings",(e=new URL(window.location.href)).searchParams.delete("screen"),window.history.replaceState({},document.title,e.toString())),this.sanitize_coupon_data(),this.elements_data&&(this.elements_data=Utils.sanitize_element_item_data(this.elements_data)),this.display_conditions||(this.display_conditions=[[{group:"general:all"}]])},mounted(){let t=this,e=(this.loading_app=!1,0),o=setInterval(()=>{if(e+=5,"ready"==this.editor_preview_status)return clearInterval(o);35<=e&&(this.editor_preview_status="failed",clearInterval(o))},5e3);this.generate_stylesheets(),a.on("click",".cct-custom-dropdown:not(.opened)",function(){a.find(".cct-custom-dropdown").removeClass("opened"),s(this).addClass("opened")}),a.on("click",".cct-custom-dropdown.opened span",function(){a.find(".cct-custom-dropdown").removeClass("opened")}),s(document).keyup(function(e){"Escape"===e.key&&(t.close_modal(),t.preview_template_id=null,a.find(".cct-custom-dropdown").removeClass("opened"),a.find(".coupon-countdown-popover").removeClass("opened"))}),s("body").on("click",function(e){s(e.target).closest(".cct-custom-dropdown").length||a.find(".cct-custom-dropdown").removeClass("opened"),s(e.target).closest(".coupon-countdown-popover").length||s(".cct-color-picker.visible").length||s(e.target).closest(".cct-custom-dropdown").length||a.find(".coupon-countdown-popover").removeClass("opened")}),s("body").on("click",".coupon-countdown-timer-modal",function(e){s(e.target).closest(".coupon-countdown-timer-modal .modal-body").length||t.close_modal()}),a.on("click",".btn-popover",function(e){e.stopPropagation();var e=s(this).closest(".field-row-item").find(".coupon-countdown-popover").toggleClass("opened"),t=(a.find(".coupon-countdown-popover").not(e).removeClass("opened"),s("body").find("#coupon-settings-panel")),o=t.offset();e.css({width:t.outerWidth()-30,left:o.left+15+"px",top:s(this).offset().top+35+"px"})});var n=!1,i={panel:null,x:0,y:0};s(document).on("mousedown","#coupon-settings-panel .panel-heading",function(e){n=!0,i.panel="settings-panel",i.x=e.pageX-s("#coupon-settings-panel").offset().left,i.y=e.pageY-s("#coupon-settings-panel").offset().top,e.preventDefault()}),s(document).on("mousedown","#coupon-element-structure .header",function(e){n=!0,i.panel="element-structure",i.x=e.pageX-s("#coupon-element-structure").offset().left,i.y=e.pageY-s("#coupon-element-structure").offset().top,e.preventDefault()}),s(document).on("mousemove",function(e){n&&"settings-panel"==i.panel&&(t.settings_panel_position={top:e.pageY-i.y,left:e.pageX-i.x}),n&&"element-structure"==i.panel&&(t.element_structure_position={top:e.pageY-i.y,left:e.pageX-i.x})}),s(document).on("mouseup",function(){n=!1})},methods:{...App_Methods,...Template_Methods,...wp.hooks.applyFilters("coupon_countdown_timer.editor_methods",{}),get_responsive_model_key(e){return"desktop"===this.current_device?e:e+"_"+this.current_device},window_reload(){window.location.reload()},validate_coupon(){return this.title?.length?160<this.title?.length?{input:"coupon-title-input",message:o("Please enter a coupon title of up to 160 characters.","coupon-countdown-timer")}:this.coupon_code?.length?!!this.expiry_date?.length||{input:"expiry-date-input",message:o("Please set an expiry date to specify when this coupon should expire.","coupon-countdown-timer")}:{input:"coupon-code-input",message:o("Please enter the coupon code. Coupon code is required.","coupon-countdown-timer")}:{input:"coupon-title-input",message:o("Please provide a title for the coupon at the top.","coupon-countdown-timer")}},get_element_title(e){return coupon_countdown_timer_global.elements?.[e]?.title},close_modal(){this.current_modal=null},copy_coupon_shortcode(){navigator.clipboard.writeText(this.get_shortcode_text).then(()=>{this.set_toast_message(o("Shortcode copied! You can now paste it wherever needed.","coupon-countdown-timer"),"success")})},set_toast_message(e,t="error"){e&&(this.toast_message=e,this.show_toast_message=!0,this.toast_message_type=t,clearTimeout(n),n=setTimeout(()=>this.show_toast_message=!1,3500))},save_display_settings(e=!1){!1===e&&this.save("display_settings"),e&&(this.main_navigation="")},save(e=null){var t=this.validate_coupon();if(!0!==t)return this.$refs?.[t?.input]?.focus(),this.set_toast_message(t.message);this.saving=!0;t=new FormData;t.append("id",this.id),t.append("data",this.coupon_stringify_data),t.append("nonce",this.get_root_element.data("nonce")),t.append("action","coupon_countdown_timer/save_coupon"),fetch(coupon_countdown_timer_global.ajax_url,{method:"POST",body:t}).then(async e=>{var t=await e.json();if("object"!=typeof t||!e.ok)throw new Error(o("Something went wrong while saving the data.","coupon-countdown-timer"));if(!1===t.success)throw new Error(t?.data?.message); this.id=t.data.id,t?.data?.new&&((e=new URL(window.location.href)).searchParams.set("id",t.data.id),e.searchParams.set("screen","display-settings"),window.location=e.toString()),this.set_toast_message(o("Successfully saved coupon.","coupon-countdown-timer"),"success")}).catch(e=>this.set_toast_message(e.message)).finally(()=>{this.saving=!1,"display_settings"==e&&this.save_display_settings(!0)})}}};if(s("#coupon-countdown-timer-editor").length){Coupon_Timer_App=Vue.createApp(t);var i,r={"input-color":Input_Color,"input-image":Input_Image,"input-wpeditor":WP_Editor,"input-border":Input_Border,"input-position":Input_Position,"input-background":Input_Background,"input-typography":Input_Typography,"input-font-family":Input_Font_Family,"input-dimensions":Input_Dimensions,"input-box-shadow":Input_Box_Shadow,"input-code-editor":Input_Code_Editor,"input-range-slider":Input_Range_Slider};for(i in r)Coupon_Timer_App.component(i,r[i]);Coupon_Timer_App.mount("#coupon-countdown-timer-editor")}s("body").on("click","#coupon-element-structure .btn-collapse",function(e){e.stopPropagation();var e=s(this).closest(".container-item").data("id"),t=Coupon_Timer_App.structure_item_opened.indexOf(e);-1!==t?Coupon_Timer_App.structure_item_opened.splice(t,1):Coupon_Timer_App.structure_item_opened.push(e)}),s("body").on("click","#coupon-element-structure [data-id]",function(e){e.preventDefault(),e.stopPropagation(),"coupon-timer-settings"===s(this).data("id")?Coupon_Timer_App.update_main_navigation("coupon-timer-settings"):Coupon_Timer_App.set_current_element_data(s(this).data("id"))}),s("body").on("dragstart","#elements-container .element-item",function(e){e=s(e.target).data("type");window.coupon_countdown_timer_element_drag_data={id:Utils.generate_uuid(),type:e}}),s("#coupon-countdown-timer-editor").on("dragend","#elements-container .element-item",function(e){Coupon_Timer_App.$refs["editor-preview"]?.contentWindow.postMessage({source:"coupon_countdown_timer",action:"element_dragend"},"*")})})(jQuery);1 window.Coupon_Timer_App=null;import Utils from"./utils.min.js?v=1.0.0";import App_Watchers from"./partials/watch.min.js?v=1.0.0";import App_Methods from"./partials/methods.min.js?v=1.0.0";import Template_Methods from"./partials/methods-template.min.js?v=1.0.0";import Input_Color from"./modules/input-color.min.js?v=1.0.0";import Input_Image from"./modules/input-image.min.js?v=1.0.0";import WP_Editor from"./modules/input-wpeditor.min.js?v=1.0.0";import Input_Border from"./modules/input-border.min.js?v=1.0.0";import Input_Position from"./modules/input-position.min.js?v=1.0.0";import Input_Typography from"./modules/input-typography.min.js?v=1.0.0";import Input_Background from"./modules/input-background.min.js?v=1.0.0";import Input_Code_Editor from"./modules/input-code-editor.min.js?v=1.0.0";import Input_Font_Family from"./modules/input-font-family.min.js?v=1.0.0";import Input_Dimensions from"./modules/input-dimensions.min.js?v=1.0.0";import Input_Box_Shadow from"./modules/input-box-shadow.min.js?v=1.0.0";import Input_Range_Slider from"./modules/input-range-slider.min.js?v=1.0.0";import Display_Condition_Group from"./components/display-condition-group.min.js?v=1.0.0";(s=>{let o=wp.i18n.__,a=s("#coupon-countdown-timer-editor"),e=(window.addEventListener("message",e=>{var t,{source:o,action:n,data:i}=e.data;"coupon_countdown_timer"===o&&("preview_ready"===n&&(Utils.send_post_message(),Coupon_Timer_App.editor_preview_status="ready"),"template_structure_updated"===n&&(o=JSON.parse(i),!Array.isArray(o)&&"object"!=typeof o||(e.data?.default_settings&&"object"==typeof(i=JSON.parse(e.data?.default_settings||"{}"))&&((t={id:e.data.new_element,...Coupon_Timer_App.elements_settings_data[e.data.new_element]}).settings=i,Coupon_Timer_App.elements_settings_data[e.data.new_element]={...t},e.data?.new_element)&&Utils.get_dynamic_content(t),Coupon_Timer_App.elements_data=Utils.sanitize_element_item_data(o),Coupon_Timer_App.set_current_element_data(e.data?.new_element))),"edit_element"===n)&&Coupon_Timer_App.set_current_element_data(e.data.id)}),wp.hooks.applyFilters("coupon_countdown_timer_helper_models",{saving:!1,current_modal:"",loading_app:!0,used_colors:[],custom_style_collapse:!1,retrive_readymade_templates:!1,editor_preview_status:"loading",toast_message:null,show_toast_message:!1,toast_message_type:"error",preview_template_id:null,customize_template_id:null,preview_template_status:"",customize_template_importing:!1,main_navigation:"primary-settings",current_device:"desktop",coupon_settings_current_tab:"general",editing_element_data:null,editing_element_current_tab:"",structure_item_opened:[],last_dynamic_element_id:null,hold_dynamic_elements_content:{},hold_readymade_templates:coupon_countdown_timer_editor.readymade_templates})),n=0;var t={data(){return{id:0,title:"",coupon_code:"",custom_css:"",status:"draft",view_type:"popup",elements_data:null,generated_styles:{},used_fonts:[],display_conditions:null,coupon_timer_styles:{},coupon_timer_settings:{},settings_panel_position:{top:150,left:200},expiry_date:coupon_countdown_timer_editor.new_expiry_date,element_structure_position:{top:150,left:s(window).width()-400},...e,...coupon_countdown_timer_editor.coupon_models}},components:{"display-condition-group":Display_Condition_Group},computed:{is_pro_activated(){return wp.hooks.applyFilters("coupon_countdown_timer_editor.is_pro_activated",!1)},current_screen(){return["primary-settings","choose-template"].includes(this.main_navigation)?this.main_navigation:"editor"},get_root_element(){return s(this.$el.parentElement)},watch_coupon_data(){return JSON.stringify({view_type:this.view_type,coupon_code:this.coupon_code,expiry_dates:this.additional_expiry_dates})},coupon_stringify_data(){let t=JSON.parse(JSON.stringify(this.$data));return delete t.id,Object.keys(e).forEach(e=>delete t[e]),JSON.stringify(t)},readymade_templates(){return this.hold_readymade_templates},has_readymade_templates(){return"object"==typeof this.readymade_templates&&0<Object.values(this.readymade_templates).length},editor_iframe_classes(){var e=["current-view-"+this.current_device];return"ready"==this.editor_preview_status&&e.push("preview-ready"),e.join(" ")},get_preview_url(){return coupon_countdown_timer_editor.site_url+"?cct-preview="+this.id+"&nonce="+coupon_countdown_timer_editor.preview_nonce},get_view_type_settings_title(){return{popup:o("Popup Settings","coupon-countdown-timer"),stickybar:o("Stickybar Settings","coupon-countdown-timer"),floating_box:o("Floating Settings","coupon-countdown-timer")}[this.view_type]},show_settings_panel(){return null!==this.editing_element_data||"coupon-timer-settings"==this.main_navigation},get_current_element_id(){return this.editing_element_data?.id},get_current_element_type(){return this.editing_element_data?.type},get_panel_title(){return this.get_element_title(this.get_current_element_type)},has_elements_data(){return!(!Array.isArray(this.elements_data)||!this.elements_data)&&0<this.elements_data?.length},elements_settings_data(){return this.capture_elements_settings_data(this.elements_data)},editing_element_settings_string(){return JSON.stringify(this.editing_element_data?.settings||"")},editing_element_style_string(){return JSON.stringify({...this.editing_element_data?.styles,custom_css:this.editing_element_data?.custom_css})},get_shortcode_text(){return`[coupon_countdown_timer id="${this.id}"]`}},watch:{...App_Watchers,...wp.hooks.applyFilters("coupon_countdown_timer_editor_watch",{},{Utils:Utils}),loading_app(){!1===this.loading_app&&this.get_root_element.removeClass("loading")},editor_preview_status(e){"failed"===e&&(this.current_modal="preview-failed")}},beforeMount(){var e;Utils.coupon_app=this,(window.Coupon_Timer_App=this).elements_data?.length&&0<this.id&&(this.main_navigation="editor"),"display-settings"===new URLSearchParams(window.location.search).get("screen")&&(this.main_navigation="display-settings",(e=new URL(window.location.href)).searchParams.delete("screen"),window.history.replaceState({},document.title,e.toString())),this.sanitize_coupon_data(),this.elements_data&&(this.elements_data=Utils.sanitize_element_item_data(this.elements_data)),this.display_conditions||(this.display_conditions=[[{group:"general:all"}]])},mounted(){let t=this,e=(this.loading_app=!1,0),o=setInterval(()=>{if(e+=5,"ready"==this.editor_preview_status)return clearInterval(o);35<=e&&(this.editor_preview_status="failed",clearInterval(o))},5e3);this.generate_stylesheets(),a.on("click",".cct-custom-dropdown:not(.opened)",function(){a.find(".cct-custom-dropdown").removeClass("opened"),s(this).addClass("opened")}),a.on("click",".cct-custom-dropdown.opened span",function(){a.find(".cct-custom-dropdown").removeClass("opened")}),s(document).keyup(function(e){"Escape"===e.key&&(t.close_modal(),t.preview_template_id=null,a.find(".cct-custom-dropdown").removeClass("opened"),a.find(".coupon-countdown-popover").removeClass("opened"))}),s("body").on("click",function(e){s(e.target).closest(".cct-custom-dropdown").length||a.find(".cct-custom-dropdown").removeClass("opened"),s(e.target).closest(".coupon-countdown-popover").length||s(".cct-color-picker.visible").length||s(e.target).closest(".cct-custom-dropdown").length||a.find(".coupon-countdown-popover").removeClass("opened")}),s("body").on("click",".coupon-countdown-timer-modal",function(e){s(e.target).closest(".coupon-countdown-timer-modal .modal-body").length||t.close_modal()}),a.on("click",".btn-popover",function(e){e.stopPropagation();var e=s(this).closest(".field-row-item").find(".coupon-countdown-popover").toggleClass("opened"),t=(a.find(".coupon-countdown-popover").not(e).removeClass("opened"),s("body").find("#coupon-settings-panel")),o=t.offset();e.css({width:t.outerWidth()-30,left:o.left+15+"px",top:s(this).offset().top+35+"px"})});var n=!1,i={panel:null,x:0,y:0};s(document).on("mousedown","#coupon-settings-panel .panel-heading",function(e){n=!0,i.panel="settings-panel",i.x=e.pageX-s("#coupon-settings-panel").offset().left,i.y=e.pageY-s("#coupon-settings-panel").offset().top,e.preventDefault()}),s(document).on("mousedown","#coupon-element-structure .header",function(e){n=!0,i.panel="element-structure",i.x=e.pageX-s("#coupon-element-structure").offset().left,i.y=e.pageY-s("#coupon-element-structure").offset().top,e.preventDefault()}),s(document).on("mousemove",function(e){n&&"settings-panel"==i.panel&&(t.settings_panel_position={top:e.pageY-i.y,left:e.pageX-i.x}),n&&"element-structure"==i.panel&&(t.element_structure_position={top:e.pageY-i.y,left:e.pageX-i.x})}),s(document).on("mouseup",function(){n=!1})},methods:{...App_Methods,...Template_Methods,...wp.hooks.applyFilters("coupon_countdown_timer.editor_methods",{}),get_responsive_model_key(e){return"desktop"===this.current_device?e:e+"_"+this.current_device},window_reload(){window.location.reload()},validate_coupon(){return this.title?.length?160<this.title?.length?{input:"coupon-title-input",message:o("Please enter a coupon title of up to 160 characters.","coupon-countdown-timer")}:this.coupon_code?.length?!!this.expiry_date?.length||{input:"expiry-date-input",message:o("Please set an expiry date to specify when this coupon should expire.","coupon-countdown-timer")}:{input:"coupon-code-input",message:o("Please enter the coupon code. Coupon code is required.","coupon-countdown-timer")}:{input:"coupon-title-input",message:o("Please provide a title for the coupon at the top.","coupon-countdown-timer")}},get_element_title(e){return coupon_countdown_timer_global.elements?.[e]?.title},close_modal(){this.current_modal=null},copy_coupon_shortcode(){navigator.clipboard.writeText(this.get_shortcode_text).then(()=>{this.set_toast_message(o("Shortcode copied! You can now paste it wherever needed.","coupon-countdown-timer"),"success")})},set_toast_message(e,t="error"){e&&(this.toast_message=e,this.show_toast_message=!0,this.toast_message_type=t,clearTimeout(n),n=setTimeout(()=>this.show_toast_message=!1,3500))},save_display_settings(e=!1){!1===e&&this.save("display_settings"),e&&(this.main_navigation="")},save(e=null){var t=this.validate_coupon();if(!0!==t)return this.$refs?.[t?.input]?.focus(),this.set_toast_message(t.message);this.saving=!0;t=new FormData;t.append("id",this.id),t.append("data",this.coupon_stringify_data),t.append("nonce",this.get_root_element.data("nonce")),t.append("action","coupon_countdown_timer/save_coupon"),fetch(coupon_countdown_timer_global.ajax_url,{method:"POST",body:t}).then(async e=>{var t=await e.json();if("object"!=typeof t||!e.ok)throw new Error(o("Something went wrong while saving the data.","coupon-countdown-timer"));if(!1===t.success)throw new Error(t?.data?.message);console.log(t.data),this.id=t.data.id,t?.data?.new&&((e=new URL(window.location.href)).searchParams.set("id",t.data.id),e.searchParams.set("screen","display-settings"),window.location=t.data.edit_url),this.set_toast_message(o("Successfully saved coupon.","coupon-countdown-timer"),"success")}).catch(e=>this.set_toast_message(e.message)).finally(()=>{this.saving=!1,"display_settings"==e&&this.save_display_settings(!0)})}}};if(s("#coupon-countdown-timer-editor").length){Coupon_Timer_App=Vue.createApp(t);var i,r={"input-color":Input_Color,"input-image":Input_Image,"input-wpeditor":WP_Editor,"input-border":Input_Border,"input-position":Input_Position,"input-background":Input_Background,"input-typography":Input_Typography,"input-font-family":Input_Font_Family,"input-dimensions":Input_Dimensions,"input-box-shadow":Input_Box_Shadow,"input-code-editor":Input_Code_Editor,"input-range-slider":Input_Range_Slider};for(i in r)Coupon_Timer_App.component(i,r[i]);Coupon_Timer_App.mount("#coupon-countdown-timer-editor")}s("body").on("click","#coupon-element-structure .btn-collapse",function(e){e.stopPropagation();var e=s(this).closest(".container-item").data("id"),t=Coupon_Timer_App.structure_item_opened.indexOf(e);-1!==t?Coupon_Timer_App.structure_item_opened.splice(t,1):Coupon_Timer_App.structure_item_opened.push(e)}),s("body").on("click","#coupon-element-structure [data-id]",function(e){e.preventDefault(),e.stopPropagation(),"coupon-timer-settings"===s(this).data("id")?Coupon_Timer_App.update_main_navigation("coupon-timer-settings"):Coupon_Timer_App.set_current_element_data(s(this).data("id"))}),s("body").on("dragstart","#elements-container .element-item",function(e){e=s(e.target).data("type");window.coupon_countdown_timer_element_drag_data={id:Utils.generate_uuid(),type:e}}),s("#coupon-countdown-timer-editor").on("dragend","#elements-container .element-item",function(e){Coupon_Timer_App.$refs["editor-preview"]?.contentWindow.postMessage({source:"coupon_countdown_timer",action:"element_dragend"},"*")})})(jQuery); -
coupon-countdown-timer/trunk/inc/class-admin.php
r3392298 r3393682 115 115 } 116 116 117 wp_send_json_success(array('id' => $coupon->get_id(), 'new' => $coupon->is_new())); 117 $new_coupon_url = add_query_arg(array( 118 'id' => $coupon->get_id(), 119 'nonce' => wp_create_nonce('_nonce_coupon_countdown_timer_editor') 120 ), admin_url('admin.php?page=coupon-countdown-timer-edit') ); 121 122 wp_send_json_success(array('id' => $coupon->get_id(), 'new' => $coupon->is_new(), 'edit_url' => $new_coupon_url)); 118 123 } 119 124
Note: See TracChangeset
for help on using the changeset viewer.