2019-01-24 12:21:50 +01:00
|
|
|
!function(a,b,c){function d(){return e?e.$('a[data-wplink-edit="true"]'):null}var e,f,g,h,i,j=/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,63}$/i,k=/^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,63}[^ "]*$/i,l={},m={},n="ontouchend"in document;window.wpLink={timeToTriggerRiver:150,minRiverAJAXDuration:200,riverBottomThreshold:5,keySensitivity:100,lastSearch:"",textarea:"",modalOpen:!1,init:function(){l.wrap=a("#wp-link-wrap"),l.dialog=a("#wp-link"),l.backdrop=a("#wp-link-backdrop"),l.submit=a("#wp-link-submit"),l.close=a("#wp-link-close"),l.text=a("#wp-link-text"),l.url=a("#wp-link-url"),l.nonce=a("#_ajax_linking_nonce"),l.openInNewTab=a("#wp-link-target"),l.search=a("#wp-link-search"),m.search=new g(a("#search-results")),m.recent=new g(a("#most-recent-results")),m.elements=l.dialog.find(".query-results"),l.queryNotice=a("#query-notice-message"),l.queryNoticeTextDefault=l.queryNotice.find(".query-notice-default"),l.queryNoticeTextHint=l.queryNotice.find(".query-notice-hint"),l.dialog.keydown(wpLink.keydown),l.dialog.keyup(wpLink.keyup),l.submit.click(function(a){a.preventDefault(),wpLink.update()}),l.close.add(l.backdrop).add("#wp-link-cancel button").click(function(a){a.preventDefault(),wpLink.close()}),m.elements.on("river-select",wpLink.updateFields),l.search.on("focus.wplink",function(){l.queryNoticeTextDefault.hide(),l.queryNoticeTextHint.removeClass("screen-reader-text").show()}).on("blur.wplink",function(){l.queryNoticeTextDefault.show(),l.queryNoticeTextHint.addClass("screen-reader-text").hide()}),l.search.on("keyup input",function(){window.clearTimeout(f),f=window.setTimeout(function(){wpLink.searchInternalLinks()},500)}),l.url.on("paste",function(){setTimeout(wpLink.correctURL,0)}),l.url.on("blur",wpLink.correctURL)},correctURL:function(){var b=a.trim(l.url.val());b&&i!==b&&!/^(?:[a-z]+:|#|\?|\.|\/)/.test(b)&&(l.url.val("http://"+b),i=b)},open:function(b,c,d){var f,g=a(document.body);g.addClass("modal-open"),wpLink.modalOpen=!0,wpLink.range=null,b&&(window.wpActiveEditor=b),window.wpActiveEditor&&(this.textarea=a("#"+window.wpActiveEditor).get(0),"undefined"!=typeof window.tinymce&&(g.append(l.backdrop,l.wrap),f=window.tinymce.get(window.wpActiveEditor),e=f&&!f.isHidden()?f:null),!wpLink.isMCE()&&document.selection&&(this.textarea.focus(),this.range=document.selection.createRange()),l.wrap.show(),l.backdrop.show(),wpLink.refresh(c,d),a(document).trigger("wplink-open",l.wrap))},isMCE:function(){return e&&!e.isHidden()},refresh:function(a,b){var c="";m.search.refresh(),m.recent.refresh(),wpLink.isMCE()?wpLink.mceRefresh(a,b):(l.wrap.hasClass("has-text-field")||l.wrap.addClass("has-text-field"),document.selection?c=document.selection.createRange().text||b||"":"undefined"!=typeof this.textarea.selectionStart&&this.textarea.selectionStart!==this.textarea.selectionEnd&&(b=this.textarea.value.substring(this.textarea.selectionStart,this.textarea.selectionEnd)||b||""),l.text.val(b),wpLink.setDefaultValues()),n?l.url.focus().blur():window.setTimeout(function(){l.url[0].select(),l.url.focus()}),m.recent.ul.children().length||m.recent.ajax(),i=l.url.val().replace(/^http:\/\//,"")},hasSelectedText:function(a){var b,c,d,f=e.selection.getContent();if(/</.test(f)&&(!/^<a [^>]+>[^<]+<\/a>$/.test(f)||f.indexOf("href=")===-1))return!1;if(a.length){if(c=a[0].childNodes,!c||!c.length)return!1;for(d=c.length-1;d>=0;d--)if(b=c[d],3!=b.nodeType&&!window.tinymce.dom.BookmarkManager.isBookmarkNode(b))return!1}return!0},mceRefresh:function(c,f){var g,h,i=d(),m=this.hasSelectedText(i);i.length?(g=i.text(),h=i.attr("href"),a.trim(g)||(g=f||""),c&&(k.test(c)||j.test(c))&&(h=c),"_wp_link_placeholder"!==h?(l.url.val(h),l.openInNewTab.prop("checked","_blank"===i.attr("target")),l.submit.val(b.update)):this.setDefaultValues(g),c&&c!==h?l.search.val(c):l.search.val(""),window.setTimeout(function(){wpLink.searchInternalLinks()})):(g=e.selection.getContent({format:"text"})||f||"",this.setDefaultValues(g)),m?(l.text.val(g),l.wrap.addClass("has-text-field")):(l.text.val(""),l.wrap.removeClass("has-text-field"))},close:function(b){a(document.body).removeClass("mo
|