WordPress/wp-includes/js/wplink.min.js

1 line
10 KiB
JavaScript
Raw Normal View History

var wpLink;!function(r){var a,t,e,n,i,s={},l={},o="ontouchend"in document;wpLink={timeToTriggerRiver:150,minRiverAJAXDuration:200,riverBottomThreshold:5,keySensitivity:100,lastSearch:"",textarea:"",init:function(){s.wrap=r("#wp-link-wrap"),s.dialog=r("#wp-link"),s.backdrop=r("#wp-link-backdrop"),s.submit=r("#wp-link-submit"),s.close=r("#wp-link-close"),s.text=r("#wp-link-text"),s.url=r("#wp-link-url"),s.nonce=r("#_ajax_linking_nonce"),s.openInNewTab=r("#wp-link-target"),s.search=r("#wp-link-search"),l.search=new e(r("#search-results")),l.recent=new e(r("#most-recent-results")),l.elements=s.dialog.find(".query-results"),s.queryNotice=r("#query-notice-message"),s.queryNoticeTextDefault=s.queryNotice.find(".query-notice-default"),s.queryNoticeTextHint=s.queryNotice.find(".query-notice-hint"),s.dialog.keydown(wpLink.keydown),s.dialog.keyup(wpLink.keyup),s.submit.click(function(e){e.preventDefault(),wpLink.update()}),s.close.add(s.backdrop).add("#wp-link-cancel a").click(function(e){e.preventDefault(),wpLink.close()}),r("#wp-link-search-toggle").on("click",wpLink.toggleInternalLinking),l.elements.on("river-select",wpLink.updateFields),s.search.on("focus.wplink",function(){s.queryNoticeTextDefault.hide(),s.queryNoticeTextHint.removeClass("screen-reader-text").show()}).on("blur.wplink",function(){s.queryNoticeTextDefault.show(),s.queryNoticeTextHint.addClass("screen-reader-text").hide()}),s.search.on("keyup input",function(){var e=this;window.clearTimeout(t),t=window.setTimeout(function(){wpLink.searchInternalLinks.call(e)},500)}),s.url.on("paste",function(){setTimeout(wpLink.correctURL,0)}),s.url.on("blur",wpLink.correctURL)},correctURL:function(){var e=r.trim(s.url.val());e&&i!==e&&!/^(?:[a-z]+:|#|\?|\.|\/)/.test(e)&&(s.url.val("http://"+e),i=e)},open:function(e){var t=r(document.body);t.addClass("modal-open"),wpLink.range=null,e&&(window.wpActiveEditor=e),window.wpActiveEditor&&(this.textarea=r("#"+window.wpActiveEditor).get(0),"undefined"!=typeof tinymce&&(t.append(s.backdrop,s.wrap),t=tinymce.get(wpActiveEditor),(a=t&&!t.isHidden()?t:null)&&tinymce.isIE&&(a.windowManager.bookmark=a.selection.getBookmark())),!wpLink.isMCE()&&document.selection&&(this.textarea.focus(),this.range=document.selection.createRange()),s.wrap.show(),s.backdrop.show(),wpLink.refresh(),r(document).trigger("wplink-open",s.wrap))},isMCE:function(){return a&&!a.isHidden()},refresh:function(){var e="";l.search.refresh(),l.recent.refresh(),wpLink.isMCE()?wpLink.mceRefresh():(s.wrap.hasClass("has-text-field")||s.wrap.addClass("has-text-field"),document.selection?e=document.selection.createRange().text||"":void 0!==this.textarea.selectionStart&&this.textarea.selectionStart!==this.textarea.selectionEnd&&(e=this.textarea.value.substring(this.textarea.selectionStart,this.textarea.selectionEnd)||""),s.text.val(e),wpLink.setDefaultValues()),o?s.url.focus().blur():s.url.focus()[0].select(),l.recent.ul.children().length||l.recent.ajax(),i=s.url.val().replace(/^http:\/\//,"")},hasSelectedText:function(e){var t=a.selection.getContent();if(/</.test(t)&&(!/^<a [^>]+>[^<]+<\/a>$/.test(t)||-1===t.indexOf("href=")))return!1;if(e){var n,i=e.childNodes;if(0===i.length)return!1;for(n=i.length-1;0<=n;n--)if(3!=i[n].nodeType)return!1}return!0},mceRefresh:function(){var e,t=a.selection.getNode(),n=a.dom.getParent(t,"a[href]"),t=this.hasSelectedText(n);n?(e=n.innerText||n.textContent,s.url.val(a.dom.getAttrib(n,"href")),s.openInNewTab.prop("checked","_blank"===a.dom.getAttrib(n,"target")),s.submit.val(wpLinkL10n.update)):(e=a.selection.getContent({format:"text"}),this.setDefaultValues()),t?(s.text.val(e||""),s.wrap.addClass("has-text-field")):(s.text.val(""),s.wrap.removeClass("has-text-field"))},close:function(){r(document.body).removeClass("modal-open"),wpLink.isMCE()?a.focus():(wpLink.textarea.focus(),wpLink.range&&(wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select())),s.backdrop.hide(),s.wrap.hide(),i=!1,r(document).trigger("wplink-close",s.wrap)},getAttrs:function(){return wpLink.correctURL(),{href:r.trim(s.url.val()),target:s.openInNewTab.prop("