| 1 |
jQuery(document).ready(function(t){function a(a,e){if(e){if(e.status_html){var n=a.closest("td").find(".tptn-fast-config-status").first();n.length||(n=t(".tptn-fast-config-status").first()),n.length&&n.replaceWith(t(e.status_html))}if(e.generate_nonce&&t(".tptn-generate-fast-config").data("nonce",e.generate_nonce),e.delete_nonce&&t(".tptn-delete-fast-config").data("nonce",e.delete_nonce),void 0!==e.has_config){var i=t(".tptn-delete-fast-config");i.length&&i.prop("disabled",!e.has_config)}e.message&&alert(e.message)}}t('button[name="tptn_cache_clear"]').on("click",function(){var a=t(this),e="1"===a.attr("data-network-wide"),n=e&&top_ten_admin_data.strings.network_confirm_message?top_ten_admin_data.strings.network_confirm_message:top_ten_admin_data.strings.confirm_message;if(confirm(n)){var i=a.text(),o=top_ten_admin_data.strings.clearing_text?top_ten_admin_data.strings.clearing_text:"Clearing...";a.prop("disabled",!0).text(o).append(' <span class="spinner is-active"></span>'),function(a,e,n){t.post(ajaxurl,{action:"tptn_clear_cache",security:top_ten_admin_data.security,network_wide:n?"1":"0"},function(t){t.success?alert(t.data.message):alert(top_ten_admin_data.strings.fail_message)}).fail(function(t,a){alert(top_ten_admin_data.strings.request_fail_message+a)}).always(function(){a&&a.length&&a.prop("disabled",!1).text(e).find(".spinner").remove()})}(a,i,e)}}),function(){var t=document.querySelector('select[name="tptn_settings[tptn_styles]"]');if(t){var a=top_ten_admin_data.strings||{},e={left_thumbs:"left_thumbs_message",grid_thumbs:"grid_thumbs_message",text_only:"text_only_message"};n(),t.addEventListener("change",n)}function n(){var n=t.value,i=document.querySelectorAll('input[name="tptn_settings[post_thumb_op]"]');if(function(t){var n=e[t],i=document.querySelectorAll('input[name="tptn_settings[post_thumb_op]"]');if(0!==i.length){var o=i[0].closest("td");if(o){var s=o.querySelector(".tptn-js-message");if(n){var d=a[n]||"";if(s)s.textContent!==d&&(s.textContent=d);else{var r=document.createElement("p");r.className="description tptn-js-message",r.style.color="#9B0800",r.textContent=d,o.appendChild(r)}}else s&&s.remove()}}}(n),i.forEach(function(t){t.disabled=!1}),"left_thumbs"===n||"grid_thumbs"===n){var o=["inline","after","thumbs_only"],s=document.querySelector('input[name="tptn_settings[post_thumb_op]"]:checked'),d=!s||-1===o.indexOf(s.value);if(i.forEach(function(t){-1===o.indexOf(t.value)&&(t.disabled=!0)}),d){var r=document.querySelector('input[name="tptn_settings[post_thumb_op]"][value="inline"]');r&&(r.checked=!0)}}if("text_only"===n){i.forEach(function(t){t.disabled=!0});var c=document.querySelector('input[name="tptn_settings[post_thumb_op]"][value="text_only"]');c&&(c.checked=!0)}}}(),t("body").on("click",".tptn-generate-fast-config",function(){var e,n,i=t(this).data("confirm");confirm(i)&&(e=t(this),n=e.text(),e.prop("disabled",!0).text("Generating..."),t.post(ajaxurl,{action:"tptn_generate_fast_config",security:e.data("nonce")},function(t){t&&t.data&&(t.data.nonce&&e.data("nonce",t.data.nonce),a(e,t.data))}).fail(function(t,a){window.console&&window.console.error&&window.console.error(top_ten_admin_data.strings.request_fail_message+a)}).always(function(){e.prop("disabled",!1).text(n)}))}),t("body").on("click",".tptn-delete-fast-config",function(){var e,n,i=t(this).data("confirm");confirm(i)&&(e=t(this),n=e.text(),e.prop("disabled",!0).text("Deleting..."),t.post(ajaxurl,{action:"tptn_delete_fast_config",security:e.data("nonce")},function(t){t&&t.data&&(t.data.nonce&&e.data("nonce",t.data.nonce),a(e,t.data))}).fail(function(t,a){window.console&&window.console.error&&window.console.error(top_ten_admin_data.strings.request_fail_message+a)}).always(function(){e.text(n),e.data("nonce")&&e.prop("disabled",!1)}))}),t(function(){var a=t("#dashboard-historical-visits");a.length&&(a.tabs({create:function(a,e){t(e.tab.find("a")).addClass("nav-tab-active")},activate:function(e,n){t(n.oldTab.find("a")).removeClass("nav-tab-active"),t(n.newTab.find("a")).addClass("nav-tab-active"),function(e){if(e.length&&!e.data("tptn-loaded")&&!e.data("tptn-loading")){var n=e.find(".tptn-dashboard-tab-content");n.length&&(e.data("tptn-loading",!0).attr("aria-busy","true"),t.post(tptn_chart_data.tabs_url||ajaxurl,{action:"tptn_dashboard_tab",security:tptn_chart_data.security,tab:e.data("tptn-tab"),network:parseInt(a.data("tptn-network"),10)||0},function(t){t&&t.success&&t.data&&void 0!==t.data.html?n.html(t.data.html).data("tptn-loaded",!0):n.html("<p>"+tptn_chart_data.tab_error+"</p>")},"json").fail(function(){n.html("<p>"+tptn_chart_data.tab_error+"</p>")}).always(function(){e.data("tptn-loading",!1).removeAttr("aria-busy")}))}}(n.newPanel)}}),setTimeout(function(){var e=a.tabs(),n=0;a.find(".nav-tab-wrapper li a").each(function(a){if(t(this).text().indexOf("Today")>=0)return n=a,!1}),e.tabs("option","active",n),a.find(".nav-tab-wrapper li a").removeClass("nav-tab-active"),a.find(".nav-tab-wrapper li").eq(n).find("a").addClass("nav-tab-active")},10))}),t(function(){var a="dd M yy",e=t("#datepicker-from").datepicker({changeMonth:!0,maxDate:0,dateFormat:a}).on("change",function(){n.datepicker("option","minDate",i(this))}),n=t("#datepicker-to").datepicker({changeMonth:!0,maxDate:0,dateFormat:a}).on("change",function(){e.datepicker("option","maxDate",i(this))});function i(e){var n;try{n=t.datepicker.parseDate(a,e.value)}catch(t){n=null}return n}}),t(".live_edit").on("click",function(){t(this).addClass("live_edit_mode").removeClass("live_edit_mode_success live_edit_mode_error")}),t(".live_edit").on("focusout keypress",function(a){if("focusout"===a.type||13===a.which){13==a.which&&a.preventDefault();var e=t(this),n=e.attr("data-wp-post-id"),i=e.attr("data-wp-blog-id"),o=e.attr("data-wp-count"),s=e.text();e.removeClass("live_edit_mode");var d={action:"tptn_edit_count_ajax",post_id:n,total_count:s,total_count_original:o,top_ten_admin_nonce:top_ten_admin.nonce};i&&(d.blog_id=i),t.ajax({type:"POST",dataType:"json",url:ajaxurl,data:d,success:function(t){!1===t?(e.addClass("live_edit_mode_error"),e.html(o)):t>0&&e.addClass("live_edit_mode_success")}})}})}); |