1 line
1.8 KiB
JavaScript
1 line
1.8 KiB
JavaScript
|
var wp_optimize=window.wp_optimize||{};wp_optimize.send_command=function(e,o,i,t,r){t="undefined"==typeof t||t,o||(o={}),o.hasOwnProperty("include_ui_elements")||(o.include_ui_elements=!0);var n={action:"wp_optimize_ajax",subaction:e,nonce:wp_optimize_send_command_data.nonce,data:o},s={type:"post",data:n,success:function(e){if(t){try{var o=wpo_parse_json(e)}catch(r){return console.log(r),console.log(e),void alert(wpoptimize.error_unexpected_response)}if(!o.result&&o.hasOwnProperty("error_code")&&o.error_code)return void wp_optimize.notices.show_notice(o.error_code,o.error_message);"function"==typeof i&&i(o)}else{if(!e.result&&e.hasOwnProperty("error_code")&&e.error_code)return void wp_optimize.notices.show_notice(e.error_code,e.error_message);"function"==typeof i&&i(e)}}};return"object"==typeof r&&(r.hasOwnProperty("timeout")&&(s.timeout=r.timeout),r.hasOwnProperty("error")&&"function"==typeof r.error&&(s.error=r.error)),jQuery.ajax(ajaxurl,s)},wp_optimize.notices={errors:[],show_notice:function(e,o){jQuery("#wp-optimize-wrap").length?(this.notice||this.add_notice(),this.notice.show(),this.errors[e]||(this.errors[e]=jQuery("<p/>").html(o).appendTo(this.notice).data("error_code",e))):window.wp&&wp.hasOwnProperty("data")?wp.data.dispatch("core/notices").createNotice("error","WP-Optimize: "+o,{isDismissible:!0}):alert("WP-Optimize: "+o)},add_notice:function(){this.notice_container=jQuery('<div class="wpo-main-error-notice"></div>').prependTo("#wp-optimize-wrap"),this.notice=jQuery('<div class="notice notice-error wpo-notice is-dismissible"><button type="button" class="notice-dismiss"><span class="screen-reader-text">'+commonL10n.dismiss+"</span></button></div>"),this.notice.appendTo(this.notice_container),this.notice.on("click",".notice-dismiss",function(e){this.notice.hide().find("p").remove(),this.errors=[]}.bind(this))}};
|