| 1 |
function insertAtCaret(e,t,n){let i=e.val(),s=i.substring(0,n)+t+i.substring(n);return s=s.replace(/ +(?= )/g,""),e.val(s),!0}!function(e){"use strict";let t=!1;function n(n){let i=e("#publishing-action .spinner"),a={};return i.addClass("is-active"),a.validateData=function(e){for(var t={},n=e.find("select, textarea, input").serializeArray(),i=0;i<n.length;i++)o(t,n[i].name,n[i].value);return t}(n),wp.ajax.post("wpc-validate-seo-rules",a).always(function(){i.removeClass("is-active")}).done(function(e){t=!0,n.submit()}).fail(function(t){let n=[];void 0!==t.errors&&(e.each(t.errors,function(e,t){n.push(t.message)}),n.length<1&&n.push("Error: Set was not saved."),function(t){let n=e("form#post"),i="";e.each(t,function(e,t){i+="<p>"+t+"</p>"});let s='<div id="message" class="wpc-error notice notice-error is-dismissible">'+i+'<button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button></div>';void 0!==n&&(e("#message").length>0&&e("#message").remove(),n.before(s))}(n),s())}),!1}function i(e){e.fadeTo(100,0,function(){e.slideUp(100,function(){e.remove()})})}function s(){e(".wpc-error.is-dismissible").each(function(){var t=e(this),n=t.find(".notice-dismiss");n.on("click",function(e){e.preventDefault(),t.fadeTo(100,0,function(){t.slideUp(100,function(){t.remove()})})}),t.append(n)})}function o(e,t,n){var i=(t=t.replace("[]","[%%index%%]")).match(/([^\[\]])+/g);if(i)for(var s,o=i.length,r=e,c=0;c<o;c++){var l=String(i[c]);c==o-1?"%%index%%"===l?r.push(n):r[l]=n:("%%index%%"===i[c+1]?(s=r[l],Array.isArray(s)||(r[l]=[])):a(r[l])||(r[l]={}),r=r[l])}}function a(e){return"object"==typeof e}e.fn.getCursorPosition=function(){var e=this.get(0);if(e){if("selectionStart"in e)return e.selectionStart;if(document.selection){e.focus();var t=document.selection.createRange(),n=document.selection.createRange().text.length;return t.moveStart("character",-e.value.length),t.text.length-n}}},e.fn.createSeoVarsList=function(t){let n='<ul class="wpc-seo-vars-list">';return Object.keys(t).length>0?e.each(t,function(e,t){n+='<li data-seovar="{'+e+'}">'+t+"</li>"}):n+="<li>"+wpcSeoVars.noSeoVarsMsg+"</li>",n+="</ul>",e(this).replaceWith(n),!0},e(document).mouseup(function(t){let n=e(".wpc-vars-container");n.length>0&&(n.is(t.target)||0!==n.has(t.target).length||n.hide())}),e(document).ready(function(){e("form#post").on("submit",function(s){i(e(".wpc-field-notice")),i(e("#message")),t||(s.preventDefault(),n(e(this)))}),e(".wpc-seo-vars-list").createSeoVarsList(wpcSeoVars.seovars),e("body").on("click",".wpc-open-container",function(t){t.preventDefault();let n=e(this).data("field"),i=e("#wpc-vars-container-"+n);e("#wpc_seo_rules-"+n).focus(),i.toggle()}),e("body").on("focus keypress blur",".wpc-vars-insertable",function(t){let n=e(this).getCursorPosition();e(this).data("caret",n)}),e("body").on("click",".wpc-seo-vars-list li",function(){let t=e(this).data("seovar"),n=e(this).parents(".wpc-vars-container");if(void 0!==t){let i=e("#wpc_seo_rules-"+n.data("container")),s=i.data("caret");""===s&&(s=i.val().length),0===s?t+=" ":t=s===i.val().length?" "+t:" "+t+" ",insertAtCaret(i,t,s)}n.hide()}),e("body").on("change","#wpc_seo_rules-rule_post_type",function(){i(e(".wpc-field-notice"));let t=e(this).val(),n=e(".wpc-intersection-fields-wrapper").children(".spinner");n.addClass("is-active");let s={};s._wpnonce=e("#wpc_seo_rule_nonce").val(),s.postType=t,s.postId=e("#post_ID").val(),wp.ajax.post("wpc-get-indexed-filters",s).always(function(){n.removeClass("is-active")}).done(function(t){e("#wpc-intersections-table").replaceWith(t.html),e(".wpc-seo-vars-list").createSeoVarsList(t.seovars)}).fail(function(t){void 0!==t&&function(t,n){let i=e("#"+t),s='<div class="wpc-field-notice wpc-field-notice-error"><p>'+n+"</p></div>";void 0!==i&&i.before(s)}("wpc-intersection-fields-container",t.message)})}),s()})}(jQuery); |