admin.js
2 years ago
eael-essential-blocks-promo.js
3 years ago
eael-templately-promo.js
2 years ago
eael-templately-promo.js
172 lines
| 1 | (function ($) { |
| 2 | $("document").ready(function () { |
| 3 | let templateAddSection = $("#tmpl-elementor-add-section"); |
| 4 | if (0 < templateAddSection.length) { |
| 5 | var oldTemplateButton = templateAddSection.html(); |
| 6 | oldTemplateButton = oldTemplateButton.replace( |
| 7 | '<div class="elementor-add-section-drag-title', |
| 8 | '<div class="elementor-add-section-area-button elementor-add-templately-promo-button"></div><div class="elementor-add-section-drag-title' |
| 9 | ); |
| 10 | templateAddSection.html(oldTemplateButton); |
| 11 | } |
| 12 | |
| 13 | elementor.on("preview:loaded", function () { |
| 14 | $(elementor.$previewContents[0].body).on("click", ".elementor-add-templately-promo-button", function (event) { |
| 15 | window.tmPromo = elementorCommon.dialogsManager.createWidget( |
| 16 | "lightbox", |
| 17 | { |
| 18 | id: "eael-templately-promo-popup", |
| 19 | headerMessage: !1, |
| 20 | message: "", |
| 21 | hide: { |
| 22 | auto: !1, |
| 23 | onClick: !1, |
| 24 | onOutsideClick: false, |
| 25 | onOutsideContextMenu: !1, |
| 26 | onBackgroundClick: !0, |
| 27 | }, |
| 28 | position: { |
| 29 | my: "center", |
| 30 | at: "center", |
| 31 | }, |
| 32 | onShow: function () { |
| 33 | var contentTemp = $(".dialog-content-tempromo") |
| 34 | var cloneMarkup = $("#eael-promo-temp-wrap") |
| 35 | cloneMarkup = cloneMarkup.clone(true).show() |
| 36 | contentTemp.html(cloneMarkup); |
| 37 | }, |
| 38 | onHide: function () { |
| 39 | window.tmPromo.destroy(); |
| 40 | } |
| 41 | } |
| 42 | ); |
| 43 | window.tmPromo.getElements("header").remove(); |
| 44 | window.tmPromo.getElements("message").append( |
| 45 | window.tmPromo.addElement("content-tempromo") |
| 46 | ); |
| 47 | window.tmPromo.show(); |
| 48 | }); |
| 49 | }); |
| 50 | |
| 51 | $(document).on('change', '.eael-temp-promo-confirmation', function (e) { |
| 52 | var $this = $(this) |
| 53 | if ($this.val() == 'dnd') { |
| 54 | $(".wpdeveloper-plugin-installer").hide(); |
| 55 | $(".eael-prmo-status-submit").show(); |
| 56 | } else { |
| 57 | $(".wpdeveloper-plugin-installer").show(); |
| 58 | $(".eael-prmo-status-submit").hide(); |
| 59 | } |
| 60 | }); |
| 61 | |
| 62 | $(document).on('click','.eael-prmo-status-submit',function (e){ |
| 63 | e.preventDefault(); |
| 64 | var $this = $(this); |
| 65 | $this.prop("disabled",true); |
| 66 | $(".eael-temp-promo-confirmation").prop("disabled", true); |
| 67 | |
| 68 | $.ajax({ |
| 69 | url: ajaxurl, |
| 70 | type: "POST", |
| 71 | data: { |
| 72 | action: "templately_promo_status", |
| 73 | security: localize.nonce, |
| 74 | }, |
| 75 | success: function (response) { |
| 76 | if (response.success) { |
| 77 | $(elementor.$previewContents[0].body).find(".elementor-add-templately-promo-button").remove(); |
| 78 | window.tmPromo.destroy(); |
| 79 | } |
| 80 | }, |
| 81 | error: function (err) { |
| 82 | $this.prop("disabled",false); |
| 83 | console.log(err) |
| 84 | }, |
| 85 | }); |
| 86 | }) |
| 87 | |
| 88 | $(document).on('click','.eael-promo-temp__times',function (e){ |
| 89 | e.preventDefault(); |
| 90 | window.tmPromo.destroy(); |
| 91 | }) |
| 92 | |
| 93 | // install/activate plugin |
| 94 | $(document).on("click", ".wpdeveloper-plugin-installer", function (ev) { |
| 95 | ev.preventDefault(); |
| 96 | |
| 97 | var button = $(this); |
| 98 | var action = $(this).data("action"); |
| 99 | var slug = $(this).data("slug"); |
| 100 | var basename = $(this).data("basename"); |
| 101 | |
| 102 | if ($.active && typeof action != "undefined") { |
| 103 | button.text("Waiting...").attr("disabled", true); |
| 104 | |
| 105 | setInterval(function () { |
| 106 | if (!$.active) { |
| 107 | button.attr("disabled", false).trigger("click"); |
| 108 | } |
| 109 | }, 1000); |
| 110 | } |
| 111 | |
| 112 | if (action == "install" && !$.active) { |
| 113 | button.text("Installing...").attr("disabled", true); |
| 114 | |
| 115 | $.ajax({ |
| 116 | url: localize.ajaxurl, |
| 117 | type: "POST", |
| 118 | data: { |
| 119 | action: "wpdeveloper_install_plugin", |
| 120 | security: localize.nonce, |
| 121 | slug: slug, |
| 122 | }, |
| 123 | success: function (response) { |
| 124 | if (response.success) { |
| 125 | button.text("Activated"); |
| 126 | button.data("action", null); |
| 127 | elementor.saver.update.apply().then(function () { |
| 128 | location.reload(); |
| 129 | }); |
| 130 | } else { |
| 131 | button.text("Install"); |
| 132 | } |
| 133 | |
| 134 | button.attr("disabled", false); |
| 135 | }, |
| 136 | error: function (err) { |
| 137 | console.log(err.responseJSON); |
| 138 | }, |
| 139 | }); |
| 140 | } else if (action == "activate" && !$.active) { |
| 141 | button.text("Activating...").attr("disabled", true); |
| 142 | |
| 143 | $.ajax({ |
| 144 | url: localize.ajaxurl, |
| 145 | type: "POST", |
| 146 | data: { |
| 147 | action: "wpdeveloper_activate_plugin", |
| 148 | security: localize.nonce, |
| 149 | basename: basename, |
| 150 | }, |
| 151 | success: function (response) { |
| 152 | if (response.success) { |
| 153 | button.text("Activated"); |
| 154 | button.data("action", null); |
| 155 | elementor.saver.update.apply().then(function () { |
| 156 | location.reload(); |
| 157 | }); |
| 158 | } else { |
| 159 | button.text("Activate"); |
| 160 | } |
| 161 | |
| 162 | button.attr("disabled", false); |
| 163 | }, |
| 164 | error: function (err) { |
| 165 | console.log(err.responseJSON); |
| 166 | }, |
| 167 | }); |
| 168 | } |
| 169 | }); |
| 170 | }); |
| 171 | })(jQuery); |
| 172 |