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

1 line
9.1 KiB
JavaScript
Raw Normal View History

var wpLink;!function(a){var b,c,d,e,f,g={},h={},i="ontouchend"in document;wpLink={timeToTriggerRiver:150,minRiverAJAXDuration:200,riverBottomThreshold:5,keySensitivity:100,lastSearch:"",textarea:"",init:function(){function b(){var b=a.trim(g.url.val());b&&f!==b&&!/^(?:[a-z]+:|#|\?|\.|\/)/.test(b)&&(g.url.val("http://"+b),f=b)}g.wrap=a("#wp-link-wrap"),g.dialog=a("#wp-link"),g.backdrop=a("#wp-link-backdrop"),g.submit=a("#wp-link-submit"),g.close=a("#wp-link-close"),g.url=a("#url-field"),g.nonce=a("#_ajax_linking_nonce"),g.title=a("#link-title-field"),g.openInNewTab=a("#link-target-checkbox"),g.search=a("#search-field"),h.search=new d(a("#search-results")),h.recent=new d(a("#most-recent-results")),h.elements=g.dialog.find(".query-results"),g.queryNotice=a("#query-notice-message"),g.queryNoticeTextDefault=g.queryNotice.find(".query-notice-default"),g.queryNoticeTextHint=g.queryNotice.find(".query-notice-hint"),g.dialog.keydown(wpLink.keydown),g.dialog.keyup(wpLink.keyup),g.submit.click(function(a){a.preventDefault(),wpLink.update()}),g.close.add(g.backdrop).add("#wp-link-cancel a").click(function(a){a.preventDefault(),wpLink.close()}),a("#wp-link-search-toggle").on("click",wpLink.toggleInternalLinking),h.elements.on("river-select",wpLink.updateFields),g.search.on("focus.wplink",function(){g.queryNoticeTextDefault.hide(),g.queryNoticeTextHint.removeClass("screen-reader-text").show()}).on("blur.wplink",function(){g.queryNoticeTextDefault.show(),g.queryNoticeTextHint.addClass("screen-reader-text").hide()}),g.search.keyup(function(){var a=this;window.clearTimeout(c),c=window.setTimeout(function(){wpLink.searchInternalLinks.call(a)},500)}),g.url.on("paste",function(){setTimeout(b,0)}),g.url.on("blur",b)},open:function(c){var d;a(document.body).addClass("modal-open"),wpLink.range=null,c&&(window.wpActiveEditor=c),window.wpActiveEditor&&(this.textarea=a("#"+window.wpActiveEditor).get(0),"undefined"!=typeof tinymce&&(d=tinymce.get(wpActiveEditor),b=d&&!d.isHidden()?d:null,b&&tinymce.isIE&&(b.windowManager.bookmark=b.selection.getBookmark())),!wpLink.isMCE()&&document.selection&&(this.textarea.focus(),this.range=document.selection.createRange()),g.wrap.show(),g.backdrop.show(),wpLink.refresh(),a(document).trigger("wplink-open",g.wrap))},isMCE:function(){return b&&!b.isHidden()},refresh:function(){h.search.refresh(),h.recent.refresh(),wpLink.isMCE()?wpLink.mceRefresh():wpLink.setDefaultValues(),i?g.url.focus().blur():g.url.focus()[0].select(),h.recent.ul.children().length||h.recent.ajax(),f=g.url.val().replace(/^http:\/\//,"")},mceRefresh:function(){var a;(a=b.dom.getParent(b.selection.getNode(),"A"))?(g.url.val(b.dom.getAttrib(a,"href")),g.title.val(b.dom.getAttrib(a,"title")),g.openInNewTab.prop("checked","_blank"===b.dom.getAttrib(a,"target")),g.submit.val(wpLinkL10n.update)):wpLink.setDefaultValues()},close:function(){a(document.body).removeClass("modal-open"),wpLink.isMCE()?b.focus():(wpLink.textarea.focus(),wpLink.range&&(wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select())),g.backdrop.hide(),g.wrap.hide(),f=!1,a(document).trigger("wplink-close",g.wrap)},getAttrs:function(){return{href:a.trim(g.url.val()),title:a.trim(g.title.val()),target:g.openInNewTab.prop("checked")?"_blank":""}},update:function(){wpLink.isMCE()?wpLink.mceUpdate():wpLink.htmlUpdate()},htmlUpdate:function(){var a,b,c,d,e,f,g,h=wpLink.textarea;h&&(a=wpLink.getAttrs(),a.href&&(b='<a href="'+a.href+'"',a.title&&(f=a.title.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),b+=' title="'+f+'"'),a.target&&(b+=' target="'+a.target+'"'),b+=">",document.selection&&wpLink.range?(h.focus(),wpLink.range.text=b+wpLink.range.text+"</a>",wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select(),wpLink.range=null):"undefined"!=typeof h.selectionStart&&(c=h.selectionStart,d=h.selectionEnd,g=h.value.substring(c,d),b=b+g+"</a>",e=c+b.length,c==d&&(e-="</a>".length),h.value=h.value.substring(0,c)+b+h.value.substring(d,h.value.length),h.selectionStart=h.selectionEnd=e),wpLink.close(),h.focus()))},mceUpdate:function(){v