| 1 |
!function(n){"use strict";function e(n){n.removeClass("is-editing is-saving"),n.find(".thinkrank-focus-keyword-input").remove(),n.find(".thinkrank-focus-keyword-loading").hide()}function t(t,i,a){const r=i.val().trim(),d=a.data("keyword")||"",c=t.data("post-id");r!==d?(t.addClass("is-saving"),t.find(".thinkrank-focus-keyword-loading").show(),i.prop("disabled",!0),n.ajax({url:thinkrankFocusKeyword.ajaxUrl,type:"POST",data:{action:thinkrankFocusKeyword.action,nonce:thinkrankFocusKeyword.nonce,post_id:c,focus_keyword:r},success:function(n){n.success?(function(n,t,o){t.data("keyword",o.focus_keyword),t.text(o.display_value),o.has_keyword?t.removeClass("thinkrank-not-set").addClass("thinkrank-set"):t.removeClass("thinkrank-set").addClass("thinkrank-not-set"),e(n)}(t,a,n.data),o(t,"success")):(s(t,n.data.message||thinkrankFocusKeyword.i18n.error),i.prop("disabled",!1).focus())},error:function(n,e,o){s(t,thinkrankFocusKeyword.i18n.error),i.prop("disabled",!1).focus()},complete:function(){t.removeClass("is-saving"),t.find(".thinkrank-focus-keyword-loading").hide()}})):e(t)}function o(n,e){const t=n.find(".thinkrank-focus-keyword-display");t.addClass("thinkrank-feedback-"+e),setTimeout(function(){t.removeClass("thinkrank-feedback-"+e)},1e3)}function s(e,t){const s=n("<div>",{class:"thinkrank-inline-error",text:t});e.after(s),setTimeout(function(){s.fadeOut(function(){s.remove()})},3e3),o(e,"error")}n(document).ready(function(){"undefined"!=typeof thinkrankFocusKeyword&&n(document).on("click",".thinkrank-focus-keyword-display",function(o){o.preventDefault(),o.stopPropagation();const s=n(this),i=s.closest(".thinkrank-focus-keyword-item");i.hasClass("is-editing")||function(o,s){const i=s.data("keyword")||"",a=(o.data("post-id"),n("<input>",{type:"text",class:"thinkrank-focus-keyword-input",value:i,placeholder:thinkrankFocusKeyword.i18n.notSet,title:thinkrankFocusKeyword.i18n.pressEnter}));o.addClass("is-editing"),s.after(a),a.focus().select(),a.on("keydown",function(n){"Enter"===n.key?(n.preventDefault(),t(o,a,s)):"Escape"===n.key&&(n.preventDefault(),e(o))}),a.on("blur",function(){setTimeout(function(){o.hasClass("is-editing")&&!o.hasClass("is-saving")&&t(o,a,s)},200)})}(i,s)})})}(jQuery); |