admin.js
103 lines
| 1 | (function ($) { |
| 2 | "use strict"; |
| 3 | $(function () { |
| 4 | |
| 5 | // STATISTICS TABS |
| 6 | $("#wpp-stats-tabs a").click(function(e){ |
| 7 | var activeTab = $(this).attr("rel"); |
| 8 | $(this).removeClass("button-secondary").addClass("button-primary").siblings().removeClass("button-primary").addClass("button-secondary"); |
| 9 | $(".wpp-stats:visible").hide("fast", function(){ |
| 10 | $("#"+activeTab).slideDown("fast"); |
| 11 | }); |
| 12 | |
| 13 | e.preventDefault(); |
| 14 | }); |
| 15 | |
| 16 | $(".wpp-stats").each(function(){ |
| 17 | if ($("li", this).length == 1) { |
| 18 | $("li", this).addClass("wpp-stats-last-item"); |
| 19 | } else { |
| 20 | $("li:last", this).addClass("wpp-stats-last-item"); |
| 21 | } |
| 22 | }); |
| 23 | |
| 24 | // TOOLS |
| 25 | // thumb source selection |
| 26 | $("#thumb_source").change(function() { |
| 27 | if ($(this).val() == "custom_field") { |
| 28 | $("#lbl_field, #thumb_field, #row_custom_field, #row_custom_field_resize").show(); |
| 29 | } else { |
| 30 | $("#lbl_field, #thumb_field, #row_custom_field, #row_custom_field_resize").hide(); |
| 31 | } |
| 32 | }); |
| 33 | // file upload |
| 34 | $('#upload_thumb_button').click(function(e) { |
| 35 | tb_show('Upload a thumbnail', 'media-upload.php?referer=wpp_admin&type=image&TB_iframe=true&post_id=0', false); |
| 36 | e.preventDefault(); |
| 37 | }); |
| 38 | window.send_to_editor = function(html) { |
| 39 | var regex = /<img[^>]+src="(http:\/\/[^">]+)"/g; |
| 40 | var result = regex.exec(html); |
| 41 | |
| 42 | if ( null != result ) { |
| 43 | $('#upload_thumb_src').val(result[1]); |
| 44 | |
| 45 | var img = new Image(); |
| 46 | img.onload = function() { |
| 47 | $("#thumb-review").html( this ).parent().fadeIn(); |
| 48 | } |
| 49 | img.src = result[1]; |
| 50 | } |
| 51 | |
| 52 | tb_remove(); |
| 53 | }; |
| 54 | // cache interval |
| 55 | $("#cache").change(function() { |
| 56 | if ($(this).val() == 1) { |
| 57 | $("#cache_refresh_interval").show(); |
| 58 | } else { |
| 59 | $("#cache_refresh_interval, #cache_too_long").hide(); |
| 60 | } |
| 61 | }); |
| 62 | // interval |
| 63 | $("#cache_interval_time").change(function() { |
| 64 | var value = parseInt( $("#cache_interval_value").val() ); |
| 65 | var time = $(this).val(); |
| 66 | |
| 67 | console.log(time + " " + value); |
| 68 | |
| 69 | if ( time == "hour" && value > 72 ) { |
| 70 | $("#cache_too_long").show(); |
| 71 | } else if ( time == "day" && value > 3 ) { |
| 72 | $("#cache_too_long").show(); |
| 73 | } else if ( time == "week" && value > 1 ) { |
| 74 | $("#cache_too_long").show(); |
| 75 | } else if ( time == "month" && value >= 1 ) { |
| 76 | $("#cache_too_long").show(); |
| 77 | } else if ( time == "year" && value >= 1 ) { |
| 78 | $("#cache_too_long").show(); |
| 79 | } else { |
| 80 | $("#cache_too_long").hide(); |
| 81 | } |
| 82 | }); |
| 83 | |
| 84 | $("#cache_interval_value").change(function() { |
| 85 | var value = parseInt( $(this).val() ); |
| 86 | var time = $("#cache_interval_time").val(); |
| 87 | |
| 88 | if ( time == "hour" && value > 72 ) { |
| 89 | $("#cache_too_long").show(); |
| 90 | } else if ( time == "day" && value > 3 ) { |
| 91 | $("#cache_too_long").show(); |
| 92 | } else if ( time == "week" && value > 1 ) { |
| 93 | $("#cache_too_long").show(); |
| 94 | } else if ( time == "month" && value >= 1 ) { |
| 95 | $("#cache_too_long").show(); |
| 96 | } else if ( time == "year" && value >= 1 ) { |
| 97 | $("#cache_too_long").show(); |
| 98 | } else { |
| 99 | $("#cache_too_long").hide(); |
| 100 | } |
| 101 | }); |
| 102 | }); |
| 103 | }(jQuery)); |