PluginProbe ʕ •ᴥ•ʔ
Simple Author Box / 2.52
Simple Author Box v2.52
trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.9 2.0 2.0.1 2.0.2 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.11 2.3.12 2.3.15 2.3.16 2.3.2 2.3.20 2.3.21 2.3.22 2.4 2.41 2.42 2.45 2.46 2.47 2.48 2.49 2.50 2.51 2.52 2.54 2.55 2.56 2.57 2.59 2.60
simple-author-box / assets / js / sabox-admin.js
simple-author-box / assets / js Last commit date
sab-pointers.js 4 years ago sab-preview.js 3 years ago sab_gutenberg_editor_script.js 3 years ago sabox-admin.js 4 years ago sabox-editor.js 4 years ago sabox-picker.js 4 years ago sweetalert2.min.js 5 years ago webfont.js 3 years ago
sabox-admin.js
341 lines
1 /**
2 * SAB
3 * (c) WebFactory Ltd, 2016 - 2021
4 */
5
6 (function ($) {
7 var context = $("#sabox-container");
8 context.find(".saboxfield").on("change", function () {
9 var show_tabs = false;
10 if ($("#sab_show_custom_html").is(":checked")) {
11 show_tabs = true;
12 $('[data-tab="other"]').show();
13 } else {
14 $('[data-tab="other"]').hide();
15 }
16
17 if ($("#sab_show_latest_posts").is(":checked")) {
18 show_tabs = true;
19 $('[data-tab="latest_posts"]').show();
20 } else {
21 $('[data-tab="latest_posts"]').hide();
22 }
23
24 if (show_tabs == true) {
25 $('[data-tab="about"]').show();
26 } else {
27 $('[data-tab="about"]').hide();
28 }
29
30 var value = getElementValue($(this));
31 var elements = context.find(".show_if_" + $(this).attr("id"));
32
33 if (value && "0" != value) {
34 elements.show(300);
35 } else {
36 elements.hide(250);
37 }
38 });
39
40 function getElementValue($element) {
41 var type = $element.attr("type");
42 var name = $element.attr("name");
43
44 if ("checkbox" === type) {
45 if ($element.is(":checked")) {
46 return 1;
47 } else {
48 return 0;
49 }
50 } else {
51 return $element.val();
52 }
53 }
54
55 function adminTabSwitching() {
56 var navTabSelector = ".nav-tab-wrapper .epfw-tab:not( .epfw-tab-link ):not( .not-tab )",
57 initialTabHref,
58 initialTabID,
59 url;
60
61 // Get the current tab
62 if ("" !== window.location.hash && $(window.location.hash + "-tab.epfw-turn-into-tab").length > 0) {
63 initialTabHref = window.location.hash;
64 } else {
65 initialTabHref = $(navTabSelector + ":first").attr("href");
66 }
67
68 initialTabID = initialTabHref + "-tab";
69 if (initialTabID == "#license-tab" || initialTabID == "#support-tab") {
70 $(".sabox-preview").hide();
71 } else {
72 $(".sabox-preview").show();
73 }
74
75 // Make the first tab active by default
76 $(navTabSelector + '[href="' + initialTabHref + '"]').addClass("nav-tab-active");
77
78 // Make all the tabs, except the first one hidden
79 $(".epfw-turn-into-tab").each(function (index, value) {
80 if ("#" + $(this).attr("id") !== initialTabID) {
81 $(this).hide();
82 }
83 });
84
85 $(navTabSelector).click(function (event) {
86 var clickedTab = $(this).attr("href") + "-tab";
87
88 if (clickedTab == "#license-tab" || clickedTab == "#support-tab") {
89 $(".sabox-preview").hide();
90 } else {
91 $(".sabox-preview").show();
92 }
93
94 $(navTabSelector).removeClass("nav-tab-active"); // Remove class from previous selector
95 $(this).addClass("nav-tab-active").blur(); // Add class to currently clicked selector
96
97 $(".epfw-turn-into-tab").each(function (index, value) {
98 if ("#" + $(this).attr("id") !== clickedTab) {
99 $(this).hide();
100 }
101
102 $(clickedTab).fadeIn();
103 });
104 });
105 } // adminTabSwitching
106
107 $(document).on("click", function (e) {
108 if ($(e.target).closest(".iris-picker").length === 0) {
109 $(".iris-picker").hide();
110 }
111 });
112
113 $(document).ready(function () {
114 var elements = context.find(".saboxfield"),
115 sliders = context.find(".sabox-slider"),
116 colorpickers = context.find(".sabox-color");
117
118 elements.each(function ($index, $element) {
119 var element = $($element),
120 value = getElementValue(element),
121 elements = context.find(".show_if_" + element.attr("id"));
122 if (value && "0" !== value) {
123 elements.removeClass("hide");
124 } else {
125 elements.addClass("hide");
126 }
127 });
128 if (sliders.length > 0) {
129 sliders.each(function ($index, $slider) {
130 var input = $($slider).parent().find(".saboxfield"),
131 max = input.data("max"),
132 min = input.data("min"),
133 step = input.data("step"),
134 value = parseInt(input.val(), 10);
135
136 $($slider).slider({
137 value: value,
138 min: min,
139 max: max,
140 step: step,
141 slide: function (event, ui) {
142 input.val(ui.value + "px").trigger("change");
143 },
144 });
145 });
146 }
147 if (colorpickers.length > 0) {
148 colorpickers.each(function ($index, $colorpicker) {
149 $($colorpicker).wpColorPicker({
150 change: function (event, ui) {
151 jQuery(event.target).val(ui.color.toString()).trigger("change");
152 },
153 });
154 });
155 }
156
157 adminTabSwitching();
158
159 $(".saboxplugin-tabs-wrapper").on("click", "li", function () {
160 $(".saboxplugin-tabs-wrapper ul li").removeClass("active");
161 $(".saboxplugin-tab").hide();
162 $(this).addClass("active");
163 $(".saboxplugin-tab-" + $(this).data("tab")).show();
164 });
165
166 window.onmessage = function (e) {
167 if (e.data.messageType == "sabox-iframe") {
168 document.querySelector("span.sabox-modal-selected-path").innerText = e.data.pathToSelect;
169 }
170 if (e.data.messageType == "sabox-close-iframe") {
171 const pathToSelect = document.querySelector("span.sabox-modal-selected-path").innerText;
172 const id = document.querySelector("div.sabox-modal").getAttribute("data-element-id");
173 const element = document.querySelector("div.sabox-modal").getAttribute("data-element");
174 document.querySelector("input#" + element).value = pathToSelect;
175 document.querySelector("div.sabox-modal").style.display = "none";
176 document.querySelector("body").style.overflow = "";
177 }
178 };
179
180 $("button.sabox-modal-close-btn").on("click", function () {
181 $("body").css("overflow", "");
182 $("div.sabox-modal").css("display", "none");
183 });
184
185 $("#sabox_use_normal_click").on("change", function () {
186 const iframe = $("iframe#sabox-modal-iframe")[0];
187 iframe.contentWindow.postMessage(
188 {
189 messageType: "sabox-tick",
190 canClick: this.checked,
191 },
192 "*"
193 );
194 });
195 });
196
197 // dismiss notice
198 $(".sab-alert .notice-dismiss").on("click", function (e) {
199 e.preventDefault();
200
201 $(this).parents(".sab-alert").fadeOut();
202
203 return false;
204 });
205
206 var preview_visible = window.localStorage.getItem("sab_preview");
207 if (preview_visible !== "hidden") {
208 preview_visible = "visible";
209 }
210
211 if (preview_visible === "visible") {
212 $(".sabox-preview").show();
213 }
214
215 $('.sabox-table').on('change', 'select', function(e) {
216 option_class = $('#' + $(this).attr('id') + ' :selected').attr('class');
217 if(option_class == 'pro-option'){
218 option_text = $('#' + $(this).attr('id') + ' :selected').text();
219 $(this).val(0);
220 open_upsell($(this).attr('id'));
221 $('.show_if_' + $(this).attr('id')).hide();
222 }
223 });
224
225 $(".sabox-content").on("click", ".confirm-action", function (e) {
226 message = $(this).data("confirm");
227 e.preventDefault();
228 wfsab_swal
229 .fire({
230 type: "question",
231 title: message,
232 text: "",
233 confirmButtonText: "Continue",
234 cancelButtonText: "Cancel",
235 showConfirmButton: true,
236 showCancelButton: true,
237 })
238 .then((result) => {
239 if (result.value) {
240 window.location.href = $(this).attr("href");
241 }
242 });
243 }); // confirm action before link click
244
245 old_settings = $("#sabox-container *").not(".skip-save").serialize();
246 $("#sabox-container").on("submit", function () {
247 old_settings = $("#sabox-container *").not(".skip-save").serialize();
248 });
249
250 $(window).on("beforeunload", function (e) {
251 if ($("#sabox-container *").not(".skip-save").serialize() != old_settings) {
252 msg = "There are unsaved changes that will not be visible in the preview. Please save changes first.\nContinue?";
253 e.returnValue = msg;
254 return msg;
255 }
256 });
257
258 $("#sab-preview").on("click", function (e) {
259 if ($("#sabox-container *").not(".skip-save").serialize() != old_settings) {
260 e.preventDefault();
261 wfsab_swal
262 .fire({
263 type: "question",
264 title: "There are unsaved changes that will not be visible in the preview. Please save changes first.<br />Continue?",
265 text: "",
266 confirmButtonText: "Continue",
267 cancelButtonText: "Cancel",
268 showConfirmButton: true,
269 showCancelButton: true,
270 })
271 .then((result) => {
272 if (result.value) {
273 window.open($(this).attr("href"), "_blank");
274 }
275 });
276 }
277
278 return true;
279 });
280
281 function clean_feature(feature) {
282 feature = feature || 'pricing-table';
283 feature = feature.toLowerCase();
284 feature = feature.replace(' ', '_');
285
286 return feature;
287 }
288
289 $('#wpbody-content').on('click', '.open-upsell', function(e) {
290 e.preventDefault();
291 feature = $(this).data('feature');
292
293 open_upsell(feature);
294
295 return false;
296 });
297
298 function open_upsell(feature) {
299 feature = clean_feature(feature);
300
301 $('#sab-pro-dialog').dialog('open');
302
303 $('#sab-pro-table .button-buy').each(function(ind, el) {
304 tmp = $(el).data('href-org');
305 tmp = tmp.replace('pricing-table', feature);
306 $(el).attr('href', tmp);
307 });
308 } // open_upsell
309
310 $('#sab-pro-dialog').dialog({
311 dialogClass: 'wp-dialog sab-pro-dialog',
312 modal: true,
313 resizable: false,
314 width: 800,
315 height: 'auto',
316 show: 'fade',
317 hide: 'fade',
318 close: function (event, ui) {
319 },
320 open: function (event, ui) {
321 $(this).siblings().find('span.ui-dialog-title').html('WP Simple Author Box PRO is here!');
322 sab_fix_dialog_close(event, ui);
323 },
324 autoOpen: false,
325 closeOnEscape: true,
326 });
327
328 if (window.localStorage.getItem('sab_upsell_shown') != 'true') {
329 open_upsell('welcome');
330 window.localStorage.setItem('sab_upsell_shown', 'true');
331 }
332
333 $('.sab-saved').delay(10000).fadeOut(300);
334 })(jQuery);
335
336 function sab_fix_dialog_close(event, ui) {
337 jQuery('.ui-widget-overlay').bind('click', function () {
338 jQuery('#' + event.target.id).dialog('close');
339 });
340 } // sab_fix_dialog_close
341