| 1 |
jQuery(document).ready(function() { |
| 2 |
wp_insert_click_handler( |
| 3 |
'wp_insert_adstxt_generate', |
| 4 |
'Create / Update ads.txt', |
| 5 |
jQuery("body").width() * 0.8, |
| 6 |
jQuery("body").height() * 0.8, |
| 7 |
function() { |
| 8 |
jQuery('#wp_insert_adstxt_content').css('height', (jQuery('body').height() * 0.5)+'px'); |
| 9 |
jQuery('.ui-dialog-buttonset').find('button').first().unbind('click').click(function() { |
| 10 |
jQuery('.ui-dialog-buttonset').find('button').last().button('disable'); |
| 11 |
jQuery('.ui-dialog-titlebar').find('button').last().button('disable'); |
| 12 |
var wp_insert_adstxt_content = jQuery('#wp_insert_adstxt_content').val(); |
| 13 |
jQuery('.ui-dialog-content').html('<div class="wp_insert_ajaxloader"></div>'); |
| 14 |
jQuery('.wp_insert_ajaxloader').show(); |
| 15 |
jQuery.post( |
| 16 |
jQuery('#wp_insert_admin_ajax').val(), { |
| 17 |
'action': 'wp_insert_adstxt_generate_form_save_action', |
| 18 |
'wp_insert_nonce': jQuery('#wp_insert_nonce').val(), |
| 19 |
'wp_insert_adstxt_content': wp_insert_adstxt_content, |
| 20 |
}, function(response) { |
| 21 |
if(response == '###SUCCESS###') { |
| 22 |
jQuery('.ui-dialog-titlebar').find('button').last().button('enable').click(); |
| 23 |
} else { |
| 24 |
jQuery('.ui-dialog-buttonset').find('button').first().button('disable'); |
| 25 |
jQuery('.ui-dialog-buttonset').find('button').last().button('enable'); |
| 26 |
jQuery('.ui-dialog-titlebar').find('button').last().button('enable'); |
| 27 |
jQuery('.ui-dialog-content').html(response); |
| 28 |
} |
| 29 |
} |
| 30 |
); |
| 31 |
}); |
| 32 |
}, |
| 33 |
function() { }, |
| 34 |
function() { } |
| 35 |
); |
| 36 |
|
| 37 |
if(window.location.href.indexOf('#wp_insert_adstxt_adsense_auto_update') > -1) { |
| 38 |
wp_insert_adstxt_adsense_auto_update(); |
| 39 |
} |
| 40 |
}); |
| 41 |
|
| 42 |
function wp_insert_adstxt_adsense_auto_update() { |
| 43 |
jQuery.post( |
| 44 |
jQuery('#wp_insert_adstxt_adsense_admin_notice_ajax').val(), { |
| 45 |
'action': 'wp_insert_adstxt_adsense_auto_update', |
| 46 |
'wp_insert_adstxt_adsense_admin_notice_nonce': jQuery('#wp_insert_adstxt_adsense_admin_notice_nonce').val(), |
| 47 |
}, function(response) { |
| 48 |
if(response != '###SUCCESS###') { |
| 49 |
jQuery(response).dialog({ |
| 50 |
'modal': true, |
| 51 |
'resizable': false, |
| 52 |
'title': 'Ads.txt Auto Updation Failed', |
| 53 |
'width': jQuery("body").width() * 0.5, |
| 54 |
'maxWidth': jQuery("body").width() * 0.5, |
| 55 |
'maxHeight': jQuery("body").height() * 0.9, |
| 56 |
position: { my: 'center', at: 'center', of: window }, |
| 57 |
open: function (event, ui) { |
| 58 |
jQuery('.ui-dialog').css({'z-index': 999999, 'max-width': '90%'}); |
| 59 |
jQuery('.ui-widget-overlay').css({'z-index': 999998, 'opacity': 0.8, 'background': '#000000'}); |
| 60 |
}, |
| 61 |
buttons : { |
| 62 |
'Cancel': function() { |
| 63 |
jQuery(this).dialog("close"); |
| 64 |
} |
| 65 |
}, |
| 66 |
close: function() { |
| 67 |
jQuery(this).dialog('destroy'); |
| 68 |
} |
| 69 |
}); |
| 70 |
} else { |
| 71 |
jQuery('.wp_insert_adstxt_adsense_notice').hide(); |
| 72 |
} |
| 73 |
} |
| 74 |
); |
| 75 |
} |
| 76 |
|
| 77 |
function wp_insert_adstxt_add_entry() { |
| 78 |
var wp_insert_adstxt_new_entry_domain = jQuery("#wp_insert_adstxt_new_entry_domain").val(); |
| 79 |
var wp_insert_adstxt_new_entry_pid = jQuery("#wp_insert_adstxt_new_entry_pid").val(); |
| 80 |
var wp_insert_adstxt_new_entry_type = jQuery("#wp_insert_adstxt_new_entry_type").val(); |
| 81 |
var wp_insert_adstxt_new_entry_certauthority = jQuery("#wp_insert_adstxt_new_entry_certauthority").val(); |
| 82 |
var wp_insert_adstxt_content = jQuery("#wp_insert_adstxt_content").val(); |
| 83 |
var defaultBorderColor = jQuery("#wp_insert_adstxt_new_entry_domain").css("border-color"); |
| 84 |
var defaultLabelColor = jQuery("#wp_insert_adstxt_new_entry_domain").parent().find("small").css("color"); |
| 85 |
|
| 86 |
var isValidated = true; |
| 87 |
jQuery("#wp_insert_adstxt_new_entry_domain").css({"border-color": defaultBorderColor}).parent().find("small").css({"color": defaultLabelColor}); |
| 88 |
jQuery("#wp_insert_adstxt_new_entry_pid").css({"border-color": defaultBorderColor}).parent().find("small").css({"color": defaultLabelColor}); |
| 89 |
|
| 90 |
|
| 91 |
if(wp_insert_adstxt_new_entry_domain == '') { |
| 92 |
jQuery("#wp_insert_adstxt_new_entry_domain").css({"border-color": "#B20303"}).parent().find("small").css({"color": "#B20303"}); |
| 93 |
isValidated = false; |
| 94 |
} |
| 95 |
if(wp_insert_adstxt_new_entry_pid == '') { |
| 96 |
jQuery("#wp_insert_adstxt_new_entry_pid").css({"border-color": "#B20303"}).parent().find("small").css({"color": "#B20303"}); |
| 97 |
isValidated = false; |
| 98 |
} |
| 99 |
|
| 100 |
if(isValidated) { |
| 101 |
if((wp_insert_adstxt_content != '') && (jQuery.inArray((wp_insert_adstxt_content[wp_insert_adstxt_content.length -1]), ["\r", "\n"]) == -1)) { |
| 102 |
wp_insert_adstxt_content += '\r\n'; |
| 103 |
} |
| 104 |
wp_insert_adstxt_content += wp_insert_adstxt_new_entry_domain + ', ' + wp_insert_adstxt_new_entry_pid + ', ' + wp_insert_adstxt_new_entry_type; |
| 105 |
if(wp_insert_adstxt_new_entry_certauthority != '') { |
| 106 |
wp_insert_adstxt_content += ', ' + wp_insert_adstxt_new_entry_certauthority; |
| 107 |
} |
| 108 |
jQuery("#wp_insert_adstxt_content").val(wp_insert_adstxt_content); |
| 109 |
|
| 110 |
jQuery("#wp_insert_adstxt_new_entry_domain").val(''); |
| 111 |
jQuery("#wp_insert_adstxt_new_entry_pid").val(''); |
| 112 |
jQuery("#wp_insert_adstxt_new_entry_type").val('DIRECT'); |
| 113 |
jQuery("#wp_insert_adstxt_new_entry_certauthority").val(''); |
| 114 |
|
| 115 |
jQuery("#wp_insert_adstxt_accordion").accordion({active: 0}); |
| 116 |
jQuery("#wp_insert_adstxt_content").focus(); |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
function wp_insert_adstxt_content_download() { |
| 121 |
var blob = new Blob([jQuery("#wp_insert_adstxt_content").val()], {type: 'text/csv'}); |
| 122 |
if(window.navigator.msSaveOrOpenBlob) { |
| 123 |
window.navigator.msSaveBlob(blob, 'ads.txt'); |
| 124 |
} |
| 125 |
else{ |
| 126 |
var elem = window.document.createElement('a'); |
| 127 |
elem.href = window.URL.createObjectURL(blob); |
| 128 |
elem.download = 'ads.txt'; |
| 129 |
document.body.appendChild(elem); |
| 130 |
elem.click(); |
| 131 |
document.body.removeChild(elem); |
| 132 |
} |
| 133 |
} |