Plugin Directory

Changeset 3396449


Ignore:
Timestamp:
11/16/2025 03:27:09 AM (4 months ago)
Author:
repon.wp
Message:

first release

Location:
coupon-countdown-timer
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • coupon-countdown-timer/tags/1.0.0/assets/editor.min.js

    r3393682 r3396449  
    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);
     1window.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=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/assets/utils.min.js

    r3392298 r3396449  
    1 import Elements_View from"./elements-view.min.js?v=1.0.0";let __=wp.i18n.__,Utils={coupon_app:null,get_deep_model(e,t){return t.split(".").reduce((e,t)=>e?.[t],e)},generate_uuid(){return Math.random().toString(36).slice(2,9)},base64_encode(e){e=(new TextEncoder).encode(e);let t="";return e.forEach(e=>t+=String.fromCharCode(e)),btoa(t).replaceAll("=","")},get_element_content_id(e){e=this.clone_object(e);return"object"==typeof e?.settings&&!Array.isArray(e?.settings)||(e.settings={}),"coupon_code"===e?.type&&(e.settings.dynamic_data_coupon_code=Utils.coupon_app.coupon_code),"countdown_timer"===e?.type&&(e.settings.dynamic_data_expiry_date=Utils.coupon_app.expiry_date),this.base64_encode(e.id+JSON.stringify(e.settings))},clone_object(e){if(null===e||"object"!=typeof e)return e;if(Array.isArray(e))return e.map(Utils.clone_object);var t,n={};for(t in e)n[t]=Utils.clone_object(e[t]);return n},send_post_message(e=null){this.coupon_app.$refs["editor-preview"]?.contentWindow.postMessage({source:"coupon_countdown_timer",action:"coupon_data_updated",data:JSON.stringify({coupon_timer_id:this.coupon_app.id,custom_css:this.coupon_app.custom_css,used_fonts:this.coupon_app.used_fonts,generated_styles:this.coupon_app.generated_styles,html_template:this.coupon_app.get_html_template(this.coupon_app.elements_data),current_editing_element_id:this.coupon_app.get_current_element_id,...e})},"*")},send_element_data(e){this.coupon_app.$refs["editor-preview"]?.contentWindow.postMessage({source:"coupon_countdown_timer",action:"element_data_updated",data:JSON.stringify(e)},"*")},sanitize_element_item_data(t,n=!0){if(Array.isArray(t))return t.map(e=>this.sanitize_element_item_data(e,n));if("object"!=typeof t)return t;{let e={...t};return e.hasOwnProperty("id")||(e.id=this.generate_uuid()),n&&(e={...e,...this.coupon_app.elements_settings_data?.[e.id]}),Array.isArray(e.children)&&(e.children=this.sanitize_element_item_data(e.children,n)),e}},generate_html_string(e){let t="";if(!0===coupon_countdown_timer_global.elements?.[e.type]?.dynamic){var n=Utils.get_element_content_id(e);if(Utils.coupon_app.hold_dynamic_elements_content?.[n])return Utils.coupon_app.hold_dynamic_elements_content[n];Utils.get_dynamic_content(e),t=`<div class="element-holder" data-id="${e.id}" data-type="${e.type}"><span class="coupon-countdown-timer-loading-indicator"></span></div>`}return t="function"==typeof Elements_View[e.type]?Elements_View[e.type](e,Utils.coupon_app):t},get_element_structure(e){return(e||[]).map(function e(t){let n="";var o,i=t.id===Utils.coupon_app.get_current_element_id?"editing-item":"";return"container"===t.type&&Array.isArray(t.children)?(o=Utils.coupon_app.structure_item_opened.includes(t.id)?"opened":"",n+=`<li class="has-child-item ${o} ${i}"><div class="container-item" data-id="${t.id}"><span class="btn-collapse"></span> ${Utils.coupon_app.get_element_title(t.type)}</div><ul class="container">${(t.children||[]).map(e).join("")}</ul></li>`):(o=Array(Utils.coupon_app.get_element_title(t.type)),"text"===t.type&&t?.settings?.content&&o.push(t?.settings?.content),"heading"===t.type&&t?.settings?.title&&o.push(t.settings.title),"button"===t.type&&o.push(t.settings.button_text||__("Button Text","coupon-countdown-timer")),n+='<li class="'+i+'" data-id="'+t.id+'">'+o.join(": ")+"</li>"),n}).join("")},get_elements_selector_styles(e,t){if("object"!=typeof e)return{};var n,o="#coupon-countdown-timer-wrapper-"+t,i={};for(n in e){var a=e[n];if("object"==typeof a)for(var s in"object"!=typeof i[n]&&(i[n]={}),a){let e=s.replaceAll("coupon_overlay_wrapper",".coupon-countdown-timer-wrapper-overlay-"+t);e=(e=e.replaceAll("coupon_wrapper",o)).replaceAll("element_selector",o+" .cct-element-"+n),Array.isArray(a[s])&&(i[n][e]=a[s].join(";"))}}return i},generate_elements_style(t,n){var o,e=this.get_elements_selector_styles(t?.desktop,n),i=this.get_elements_selector_styles(t?.tablet,n),a=this.get_elements_selector_styles(t?.mobile,n),s={};for(o in e){var p=e[o];if("object"==typeof p){let e=Array('<style id="cct-style-'+o+'">');for(var r in p)e.push(`${r} {${p[r]}}`);if("object"==typeof i[o]){for(var _ in e.push("@media screen and (max-width: 991px) {"),i[o])i[o]?.[_]?.length&&e.push(`#coupon-countdown-timer-builder-area ${_} {${i[o][_]}}`);e.push("}")}if("object"==typeof a[o]){for(var c in e.push("@media screen and (max-width: 575px) {"),a[o])a[o]?.[c]?.length&&e.push(`#coupon-countdown-timer-builder-area ${c} {${a[o][c]}}`);e.push("}")}(e=wp.hooks.applyFilters("coupon_countdown_timer.generate_elements_style",e,{coupon_timer_id:n,element_id:o,coupon_styles:t})).push("</style>"),s[o]=e.join(" ")}}return s},get_dynamic_content(e){if(!0===coupon_countdown_timer_global.elements?.[e.type]?.dynamic){var t=this.get_element_content_id(e);if(Utils.coupon_app.hold_dynamic_elements_content?.[t])return Utils.coupon_app.last_dynamic_element_id=e.id+"::"+t;var n=new FormData;n.append("content_id",t),n.append("element_id",e.id),n.append("element_data",JSON.stringify(e)),n.append("coupon_data",Utils.coupon_app.coupon_stringify_data),n.append("nonce",Utils.coupon_app.get_root_element.data("dynamic-nonce")),n.append("action","coupon_countdown_timer/get_dynamic_element_content"),fetch(coupon_countdown_timer_global.ajax_url,{method:"POST",body:n}).then(async e=>{e=await e.json();!1!==e?.success&&(Utils.coupon_app.last_dynamic_element_id=e.data.element_id+"::"+e.data.content_id,Utils.coupon_app.hold_dynamic_elements_content[e.data.content_id]=e.data.element_content)}).catch(()=>{})}},get_coupon_fonts(t){if("object"!=typeof t)return Array();var n,o=Array();for(n in t){let e=t[n].name;Array.isArray(t[n].weights)&&0<t[n].weights.length&&(t[n].weights.includes(400)||t[n].weights.push(400),e=e+":"+t[n].weights.join(",")),o.push(e)}return o}};export default Utils;
     1import Elements_View from"./elements-view.min.js?v=1.0.0";let __=wp.i18n.__,Utils={coupon_app:null,get_deep_model(e,t){return t.split(".").reduce((e,t)=>e?.[t],e)},generate_uuid(){return Math.random().toString(36).slice(2,9)},base64_encode(e){e=(new TextEncoder).encode(e);let t="";return e.forEach(e=>t+=String.fromCharCode(e)),btoa(t).replaceAll("=","")},get_element_content_id(e){e=this.clone_object(e);return"object"==typeof e?.settings&&!Array.isArray(e?.settings)||(e.settings={}),"coupon_code"===e?.type&&(e.settings.dynamic_data_coupon_code=Utils.coupon_app.coupon_code),"countdown_timer"===e?.type&&(e.settings.dynamic_data_expiry_date=Utils.coupon_app.expiry_date),this.base64_encode(e.id+JSON.stringify(e.settings))},clone_object(e){if(null===e||"object"!=typeof e)return e;if(Array.isArray(e))return e.map(Utils.clone_object);var t,n={};for(t in e)n[t]=Utils.clone_object(e[t]);return n},send_post_message(e=null){this.coupon_app.$refs["editor-preview"]?.contentWindow.postMessage({source:"coupon_countdown_timer",action:"coupon_data_updated",data:JSON.stringify({coupon_timer_id:this.coupon_app.id,custom_css:this.coupon_app.custom_css,used_fonts:this.coupon_app.used_fonts,generated_styles:this.coupon_app.generated_styles,html_template:this.coupon_app.get_html_template(this.coupon_app.elements_data),current_editing_element_id:this.coupon_app.get_current_element_id,...e})},"*")},send_element_data(e){this.coupon_app.$refs["editor-preview"]?.contentWindow.postMessage({source:"coupon_countdown_timer",action:"element_data_updated",data:JSON.stringify(e)},"*")},sanitize_element_item_data(t,n=!0){if(Array.isArray(t))return t.map(e=>this.sanitize_element_item_data(e,n));if("object"!=typeof t)return t;{let e={...t};return e.hasOwnProperty("id")||(e.id=this.generate_uuid()),n&&(e={...e,...this.coupon_app.elements_settings_data?.[e.id]}),Array.isArray(e.children)&&(e.children=this.sanitize_element_item_data(e.children,n)),e}},generate_html_string(e){let t="";if(!0===coupon_countdown_timer_global.elements?.[e.type]?.dynamic){var n=Utils.get_element_content_id(e);if(Utils.coupon_app.hold_dynamic_elements_content?.[n])return Utils.coupon_app.hold_dynamic_elements_content[n];Utils.get_dynamic_content(e),t=`<div class="element-holder" data-id="${e.id}" data-type="${e.type}"><span class="coupon-countdown-timer-loading-indicator"></span></div>`}return t="function"==typeof Elements_View[e.type]?Elements_View[e.type](e,Utils.coupon_app):t},get_element_structure(e){return(e||[]).map(function e(t){let n="";var o,i=t.id===Utils.coupon_app.get_current_element_id?"editing-item":"";return"container"===t.type&&Array.isArray(t.children)?(o=Utils.coupon_app.structure_item_opened.includes(t.id)?"opened":"",n+=`<li class="has-child-item ${o} ${i}"><div class="container-item" data-id="${t.id}"><span class="btn-collapse"></span> ${Utils.coupon_app.get_element_title(t.type)}</div><ul class="container">${(t.children||[]).map(e).join("")}</ul></li>`):(o=Array(Utils.coupon_app.get_element_title(t.type)),"text"===t.type&&t?.settings?.content&&o.push(t?.settings?.content),"heading"===t.type&&t?.settings?.title&&o.push(t.settings.title),"button"===t.type&&o.push(t.settings.button_text||__("Button Text","coupon-countdown-timer")),n+='<li class="'+i+'" data-id="'+t.id+'">'+o.join(": ")+"</li>"),n}).join("")},get_elements_selector_styles(e,t){if("object"!=typeof e)return{};var n,o="#coupon-countdown-timer-wrapper-"+t,i={};for(n in e){var a=e[n];if("object"==typeof a)for(var s in"object"!=typeof i[n]&&(i[n]={}),a){let e=s.replaceAll("coupon_overlay_wrapper",".coupon-countdown-timer-wrapper-overlay-"+t);e=(e=e.replaceAll("coupon_wrapper",o)).replaceAll("element_selector",o+" .cct-element-"+n),Array.isArray(a[s])&&(i[n][e]=a[s].join(";"))}}return i},generate_elements_style(e,t){var n,o=this.get_elements_selector_styles(e?.desktop,t),i=this.get_elements_selector_styles(e?.tablet,t),a=this.get_elements_selector_styles(e?.mobile,t),s={};for(n in o){var r=o[n];if("object"==typeof r){var p,_,c=Array('<style id="cct-style-'+n+'">');for(p in r)c.push(`${p} {${r[p]}}`);if("object"==typeof i[n]){for(var l in c.push("@media screen and (max-width: 991px) {"),i[n])i[n]?.[l]?.length&&c.push(`#coupon-countdown-timer-builder-area ${l} {${i[n][l]}}`);c.push("}")}if("object"==typeof a[n]){for(var d in c.push("@media screen and (max-width: 575px) {"),a[n])a[n]?.[d]?.length&&c.push(`#coupon-countdown-timer-builder-area ${d} {${a[n][d]}}`);c.push("}")}e?.element_custom_css?.[n]&&(_=e?.element_custom_css?.[n]?.replaceAll("element_selector","#coupon-countdown-timer-wrapper-"+t+" .cct-element-"+n),c.push(_)),c.push("</style>"),s[n]=c.join(" ")}}return s},get_dynamic_content(e){if(!0===coupon_countdown_timer_global.elements?.[e.type]?.dynamic){var t=this.get_element_content_id(e);if(Utils.coupon_app.hold_dynamic_elements_content?.[t])return Utils.coupon_app.last_dynamic_element_id=e.id+"::"+t;var n=new FormData;n.append("content_id",t),n.append("element_id",e.id),n.append("element_data",JSON.stringify(e)),n.append("coupon_data",Utils.coupon_app.coupon_stringify_data),n.append("nonce",Utils.coupon_app.get_root_element.data("dynamic-nonce")),n.append("action","coupon_countdown_timer/get_dynamic_element_content"),fetch(coupon_countdown_timer_global.ajax_url,{method:"POST",body:n}).then(async e=>{e=await e.json();!1!==e?.success&&(Utils.coupon_app.last_dynamic_element_id=e.data.element_id+"::"+e.data.content_id,Utils.coupon_app.hold_dynamic_elements_content[e.data.content_id]=e.data.element_content)}).catch(()=>{})}},get_coupon_fonts(t){if("object"!=typeof t)return Array();var n,o=Array();for(n in t){let e=t[n].name;Array.isArray(t[n].weights)&&0<t[n].weights.length&&(t[n].weights.includes(400)||t[n].weights.push(400),e=e+":"+t[n].weights.join(",")),o.push(e)}return o}};export default Utils;
  • coupon-countdown-timer/tags/1.0.0/inc/class-coupon.php

    r3392298 r3396449  
    427427        }
    428428
    429         return $desktop_styles . $tablet_styles . $mobile_styles . $this->custom_css;
     429        $all_element_custom_css = '';
     430        if (isset($styles['element_custom_css']) && is_array($styles['element_custom_css'])) {
     431            foreach ($styles['element_custom_css'] as $element_id => $element_custom_css) {
     432                $all_element_custom_css .= str_replace('element_selector', $wrapper_id . ' .cct-element-' . $element_id,  $element_custom_css);
     433            }
     434        }
     435
     436        return $desktop_styles . $tablet_styles . $mobile_styles . $all_element_custom_css . $this->custom_css;
    430437    }
    431438
  • coupon-countdown-timer/trunk/assets/editor.min.js

    r3393682 r3396449  
    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);
     1window.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=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/assets/utils.min.js

    r3392298 r3396449  
    1 import Elements_View from"./elements-view.min.js?v=1.0.0";let __=wp.i18n.__,Utils={coupon_app:null,get_deep_model(e,t){return t.split(".").reduce((e,t)=>e?.[t],e)},generate_uuid(){return Math.random().toString(36).slice(2,9)},base64_encode(e){e=(new TextEncoder).encode(e);let t="";return e.forEach(e=>t+=String.fromCharCode(e)),btoa(t).replaceAll("=","")},get_element_content_id(e){e=this.clone_object(e);return"object"==typeof e?.settings&&!Array.isArray(e?.settings)||(e.settings={}),"coupon_code"===e?.type&&(e.settings.dynamic_data_coupon_code=Utils.coupon_app.coupon_code),"countdown_timer"===e?.type&&(e.settings.dynamic_data_expiry_date=Utils.coupon_app.expiry_date),this.base64_encode(e.id+JSON.stringify(e.settings))},clone_object(e){if(null===e||"object"!=typeof e)return e;if(Array.isArray(e))return e.map(Utils.clone_object);var t,n={};for(t in e)n[t]=Utils.clone_object(e[t]);return n},send_post_message(e=null){this.coupon_app.$refs["editor-preview"]?.contentWindow.postMessage({source:"coupon_countdown_timer",action:"coupon_data_updated",data:JSON.stringify({coupon_timer_id:this.coupon_app.id,custom_css:this.coupon_app.custom_css,used_fonts:this.coupon_app.used_fonts,generated_styles:this.coupon_app.generated_styles,html_template:this.coupon_app.get_html_template(this.coupon_app.elements_data),current_editing_element_id:this.coupon_app.get_current_element_id,...e})},"*")},send_element_data(e){this.coupon_app.$refs["editor-preview"]?.contentWindow.postMessage({source:"coupon_countdown_timer",action:"element_data_updated",data:JSON.stringify(e)},"*")},sanitize_element_item_data(t,n=!0){if(Array.isArray(t))return t.map(e=>this.sanitize_element_item_data(e,n));if("object"!=typeof t)return t;{let e={...t};return e.hasOwnProperty("id")||(e.id=this.generate_uuid()),n&&(e={...e,...this.coupon_app.elements_settings_data?.[e.id]}),Array.isArray(e.children)&&(e.children=this.sanitize_element_item_data(e.children,n)),e}},generate_html_string(e){let t="";if(!0===coupon_countdown_timer_global.elements?.[e.type]?.dynamic){var n=Utils.get_element_content_id(e);if(Utils.coupon_app.hold_dynamic_elements_content?.[n])return Utils.coupon_app.hold_dynamic_elements_content[n];Utils.get_dynamic_content(e),t=`<div class="element-holder" data-id="${e.id}" data-type="${e.type}"><span class="coupon-countdown-timer-loading-indicator"></span></div>`}return t="function"==typeof Elements_View[e.type]?Elements_View[e.type](e,Utils.coupon_app):t},get_element_structure(e){return(e||[]).map(function e(t){let n="";var o,i=t.id===Utils.coupon_app.get_current_element_id?"editing-item":"";return"container"===t.type&&Array.isArray(t.children)?(o=Utils.coupon_app.structure_item_opened.includes(t.id)?"opened":"",n+=`<li class="has-child-item ${o} ${i}"><div class="container-item" data-id="${t.id}"><span class="btn-collapse"></span> ${Utils.coupon_app.get_element_title(t.type)}</div><ul class="container">${(t.children||[]).map(e).join("")}</ul></li>`):(o=Array(Utils.coupon_app.get_element_title(t.type)),"text"===t.type&&t?.settings?.content&&o.push(t?.settings?.content),"heading"===t.type&&t?.settings?.title&&o.push(t.settings.title),"button"===t.type&&o.push(t.settings.button_text||__("Button Text","coupon-countdown-timer")),n+='<li class="'+i+'" data-id="'+t.id+'">'+o.join(": ")+"</li>"),n}).join("")},get_elements_selector_styles(e,t){if("object"!=typeof e)return{};var n,o="#coupon-countdown-timer-wrapper-"+t,i={};for(n in e){var a=e[n];if("object"==typeof a)for(var s in"object"!=typeof i[n]&&(i[n]={}),a){let e=s.replaceAll("coupon_overlay_wrapper",".coupon-countdown-timer-wrapper-overlay-"+t);e=(e=e.replaceAll("coupon_wrapper",o)).replaceAll("element_selector",o+" .cct-element-"+n),Array.isArray(a[s])&&(i[n][e]=a[s].join(";"))}}return i},generate_elements_style(t,n){var o,e=this.get_elements_selector_styles(t?.desktop,n),i=this.get_elements_selector_styles(t?.tablet,n),a=this.get_elements_selector_styles(t?.mobile,n),s={};for(o in e){var p=e[o];if("object"==typeof p){let e=Array('<style id="cct-style-'+o+'">');for(var r in p)e.push(`${r} {${p[r]}}`);if("object"==typeof i[o]){for(var _ in e.push("@media screen and (max-width: 991px) {"),i[o])i[o]?.[_]?.length&&e.push(`#coupon-countdown-timer-builder-area ${_} {${i[o][_]}}`);e.push("}")}if("object"==typeof a[o]){for(var c in e.push("@media screen and (max-width: 575px) {"),a[o])a[o]?.[c]?.length&&e.push(`#coupon-countdown-timer-builder-area ${c} {${a[o][c]}}`);e.push("}")}(e=wp.hooks.applyFilters("coupon_countdown_timer.generate_elements_style",e,{coupon_timer_id:n,element_id:o,coupon_styles:t})).push("</style>"),s[o]=e.join(" ")}}return s},get_dynamic_content(e){if(!0===coupon_countdown_timer_global.elements?.[e.type]?.dynamic){var t=this.get_element_content_id(e);if(Utils.coupon_app.hold_dynamic_elements_content?.[t])return Utils.coupon_app.last_dynamic_element_id=e.id+"::"+t;var n=new FormData;n.append("content_id",t),n.append("element_id",e.id),n.append("element_data",JSON.stringify(e)),n.append("coupon_data",Utils.coupon_app.coupon_stringify_data),n.append("nonce",Utils.coupon_app.get_root_element.data("dynamic-nonce")),n.append("action","coupon_countdown_timer/get_dynamic_element_content"),fetch(coupon_countdown_timer_global.ajax_url,{method:"POST",body:n}).then(async e=>{e=await e.json();!1!==e?.success&&(Utils.coupon_app.last_dynamic_element_id=e.data.element_id+"::"+e.data.content_id,Utils.coupon_app.hold_dynamic_elements_content[e.data.content_id]=e.data.element_content)}).catch(()=>{})}},get_coupon_fonts(t){if("object"!=typeof t)return Array();var n,o=Array();for(n in t){let e=t[n].name;Array.isArray(t[n].weights)&&0<t[n].weights.length&&(t[n].weights.includes(400)||t[n].weights.push(400),e=e+":"+t[n].weights.join(",")),o.push(e)}return o}};export default Utils;
     1import Elements_View from"./elements-view.min.js?v=1.0.0";let __=wp.i18n.__,Utils={coupon_app:null,get_deep_model(e,t){return t.split(".").reduce((e,t)=>e?.[t],e)},generate_uuid(){return Math.random().toString(36).slice(2,9)},base64_encode(e){e=(new TextEncoder).encode(e);let t="";return e.forEach(e=>t+=String.fromCharCode(e)),btoa(t).replaceAll("=","")},get_element_content_id(e){e=this.clone_object(e);return"object"==typeof e?.settings&&!Array.isArray(e?.settings)||(e.settings={}),"coupon_code"===e?.type&&(e.settings.dynamic_data_coupon_code=Utils.coupon_app.coupon_code),"countdown_timer"===e?.type&&(e.settings.dynamic_data_expiry_date=Utils.coupon_app.expiry_date),this.base64_encode(e.id+JSON.stringify(e.settings))},clone_object(e){if(null===e||"object"!=typeof e)return e;if(Array.isArray(e))return e.map(Utils.clone_object);var t,n={};for(t in e)n[t]=Utils.clone_object(e[t]);return n},send_post_message(e=null){this.coupon_app.$refs["editor-preview"]?.contentWindow.postMessage({source:"coupon_countdown_timer",action:"coupon_data_updated",data:JSON.stringify({coupon_timer_id:this.coupon_app.id,custom_css:this.coupon_app.custom_css,used_fonts:this.coupon_app.used_fonts,generated_styles:this.coupon_app.generated_styles,html_template:this.coupon_app.get_html_template(this.coupon_app.elements_data),current_editing_element_id:this.coupon_app.get_current_element_id,...e})},"*")},send_element_data(e){this.coupon_app.$refs["editor-preview"]?.contentWindow.postMessage({source:"coupon_countdown_timer",action:"element_data_updated",data:JSON.stringify(e)},"*")},sanitize_element_item_data(t,n=!0){if(Array.isArray(t))return t.map(e=>this.sanitize_element_item_data(e,n));if("object"!=typeof t)return t;{let e={...t};return e.hasOwnProperty("id")||(e.id=this.generate_uuid()),n&&(e={...e,...this.coupon_app.elements_settings_data?.[e.id]}),Array.isArray(e.children)&&(e.children=this.sanitize_element_item_data(e.children,n)),e}},generate_html_string(e){let t="";if(!0===coupon_countdown_timer_global.elements?.[e.type]?.dynamic){var n=Utils.get_element_content_id(e);if(Utils.coupon_app.hold_dynamic_elements_content?.[n])return Utils.coupon_app.hold_dynamic_elements_content[n];Utils.get_dynamic_content(e),t=`<div class="element-holder" data-id="${e.id}" data-type="${e.type}"><span class="coupon-countdown-timer-loading-indicator"></span></div>`}return t="function"==typeof Elements_View[e.type]?Elements_View[e.type](e,Utils.coupon_app):t},get_element_structure(e){return(e||[]).map(function e(t){let n="";var o,i=t.id===Utils.coupon_app.get_current_element_id?"editing-item":"";return"container"===t.type&&Array.isArray(t.children)?(o=Utils.coupon_app.structure_item_opened.includes(t.id)?"opened":"",n+=`<li class="has-child-item ${o} ${i}"><div class="container-item" data-id="${t.id}"><span class="btn-collapse"></span> ${Utils.coupon_app.get_element_title(t.type)}</div><ul class="container">${(t.children||[]).map(e).join("")}</ul></li>`):(o=Array(Utils.coupon_app.get_element_title(t.type)),"text"===t.type&&t?.settings?.content&&o.push(t?.settings?.content),"heading"===t.type&&t?.settings?.title&&o.push(t.settings.title),"button"===t.type&&o.push(t.settings.button_text||__("Button Text","coupon-countdown-timer")),n+='<li class="'+i+'" data-id="'+t.id+'">'+o.join(": ")+"</li>"),n}).join("")},get_elements_selector_styles(e,t){if("object"!=typeof e)return{};var n,o="#coupon-countdown-timer-wrapper-"+t,i={};for(n in e){var a=e[n];if("object"==typeof a)for(var s in"object"!=typeof i[n]&&(i[n]={}),a){let e=s.replaceAll("coupon_overlay_wrapper",".coupon-countdown-timer-wrapper-overlay-"+t);e=(e=e.replaceAll("coupon_wrapper",o)).replaceAll("element_selector",o+" .cct-element-"+n),Array.isArray(a[s])&&(i[n][e]=a[s].join(";"))}}return i},generate_elements_style(e,t){var n,o=this.get_elements_selector_styles(e?.desktop,t),i=this.get_elements_selector_styles(e?.tablet,t),a=this.get_elements_selector_styles(e?.mobile,t),s={};for(n in o){var r=o[n];if("object"==typeof r){var p,_,c=Array('<style id="cct-style-'+n+'">');for(p in r)c.push(`${p} {${r[p]}}`);if("object"==typeof i[n]){for(var l in c.push("@media screen and (max-width: 991px) {"),i[n])i[n]?.[l]?.length&&c.push(`#coupon-countdown-timer-builder-area ${l} {${i[n][l]}}`);c.push("}")}if("object"==typeof a[n]){for(var d in c.push("@media screen and (max-width: 575px) {"),a[n])a[n]?.[d]?.length&&c.push(`#coupon-countdown-timer-builder-area ${d} {${a[n][d]}}`);c.push("}")}e?.element_custom_css?.[n]&&(_=e?.element_custom_css?.[n]?.replaceAll("element_selector","#coupon-countdown-timer-wrapper-"+t+" .cct-element-"+n),c.push(_)),c.push("</style>"),s[n]=c.join(" ")}}return s},get_dynamic_content(e){if(!0===coupon_countdown_timer_global.elements?.[e.type]?.dynamic){var t=this.get_element_content_id(e);if(Utils.coupon_app.hold_dynamic_elements_content?.[t])return Utils.coupon_app.last_dynamic_element_id=e.id+"::"+t;var n=new FormData;n.append("content_id",t),n.append("element_id",e.id),n.append("element_data",JSON.stringify(e)),n.append("coupon_data",Utils.coupon_app.coupon_stringify_data),n.append("nonce",Utils.coupon_app.get_root_element.data("dynamic-nonce")),n.append("action","coupon_countdown_timer/get_dynamic_element_content"),fetch(coupon_countdown_timer_global.ajax_url,{method:"POST",body:n}).then(async e=>{e=await e.json();!1!==e?.success&&(Utils.coupon_app.last_dynamic_element_id=e.data.element_id+"::"+e.data.content_id,Utils.coupon_app.hold_dynamic_elements_content[e.data.content_id]=e.data.element_content)}).catch(()=>{})}},get_coupon_fonts(t){if("object"!=typeof t)return Array();var n,o=Array();for(n in t){let e=t[n].name;Array.isArray(t[n].weights)&&0<t[n].weights.length&&(t[n].weights.includes(400)||t[n].weights.push(400),e=e+":"+t[n].weights.join(",")),o.push(e)}return o}};export default Utils;
  • coupon-countdown-timer/trunk/inc/class-coupon.php

    r3392298 r3396449  
    427427        }
    428428
    429         return $desktop_styles . $tablet_styles . $mobile_styles . $this->custom_css;
     429        $all_element_custom_css = '';
     430        if (isset($styles['element_custom_css']) && is_array($styles['element_custom_css'])) {
     431            foreach ($styles['element_custom_css'] as $element_id => $element_custom_css) {
     432                $all_element_custom_css .= str_replace('element_selector', $wrapper_id . ' .cct-element-' . $element_id,  $element_custom_css);
     433            }
     434        }
     435
     436        return $desktop_styles . $tablet_styles . $mobile_styles . $all_element_custom_css . $this->custom_css;
    430437    }
    431438
Note: See TracChangeset for help on using the changeset viewer.