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