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

1 line
6.6 KiB
JavaScript
Raw Normal View History

var wpLink;!function(a){function b(){return e||c.dom.getParent(c.selection.getNode(),"a[href]")}var c,d,e,f={},g="ontouchend"in document;wpLink={textarea:"",init:function(){f.wrap=a("#wp-link-wrap"),f.dialog=a("#wp-link"),f.backdrop=a("#wp-link-backdrop"),f.submit=a("#wp-link-submit"),f.close=a("#wp-link-close"),f.text=a("#wp-link-text"),f.url=a("#wp-link-url"),f.openInNewTab=a("#wp-link-target"),a.ui&&a.ui.autocomplete&&wpLink.setAutocomplete(),f.dialog.on("keydown",wpLink.keydown),f.submit.on("click",function(a){a.preventDefault(),wpLink.update()}),f.close.add(f.backdrop).add("#wp-link-cancel a").click(function(a){a.preventDefault(),wpLink.close()}),f.url.on("paste",function(){setTimeout(wpLink.correctURL,0)})},setAutocomplete:function(){var b,c,d=f.url;d.on("keydown",function(){d.removeAttr("aria-activedescendant")}).autocomplete({source:function(d,e){return c===d.term?void e(b):/^https?:/.test(d.term)||-1!==d.term.indexOf(".")?e():(a.post(window.ajaxurl,{action:"wp-link-ajax",page:1,search:d.term,_ajax_linking_nonce:a("#_ajax_linking_nonce").val()},function(a){b=a,e(a)},"json"),void(c=d.term))},focus:function(a,b){d.attr("aria-activedescendant","mce-wp-autocomplete-"+b.item.ID)},select:function(a,b){return d.val(b.item.permalink),f.wrap.hasClass("has-text-field")&&""===tinymce.trim(f.text.val())&&f.text.val(b.item.title),!1},open:function(){d.attr("aria-expanded","true")},close:function(){d.attr("aria-expanded","false")},minLength:2,position:{my:"left top+2"}}).autocomplete("instance")._renderItem=function(b,c){return a('<li role="option" id="mce-wp-autocomplete-'+c.ID+'">').append('<span class="item-title">'+c.title+'</span>&nbsp;<span class="item-date alignright">'+c.info+"</span>").appendTo(b)},d.attr({"aria-owns":d.autocomplete("widget").attr("id")}).on("focus",function(){d.autocomplete("search")}).autocomplete("widget").addClass("wplink-autocomplete").attr("role","listbox")},correctURL:function(){var b=a.trim(f.url.val());b&&d!==b&&!/^(?:[a-z]+:|#|\?|\.|\/)/.test(b)&&(f.url.val("http://"+b),d=b)},open:function(b,d,g,h){var i,j=a(document.body);j.addClass("modal-open"),e=h,wpLink.range=null,b&&(window.wpActiveEditor=b),window.wpActiveEditor&&(this.textarea=a("#"+window.wpActiveEditor).get(0),"undefined"!=typeof tinymce&&(j.append(f.backdrop,f.wrap),i=tinymce.get(wpActiveEditor),c=i&&!i.isHidden()?i:null,c&&tinymce.isIE&&!c.windowManager.wplinkBookmark&&(c.windowManager.wplinkBookmark=c.selection.getBookmark())),!wpLink.isMCE()&&document.selection&&(this.textarea.focus(),this.range=document.selection.createRange()),f.wrap.show(),f.backdrop.show(),wpLink.refresh(d,g),a(document).trigger("wplink-open",f.wrap))},isMCE:function(){return c&&!c.isHidden()},refresh:function(a,b){var c="";wpLink.isMCE()?wpLink.mceRefresh(a,b):(f.wrap.hasClass("has-text-field")||f.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||""),f.text.val(b),wpLink.setDefaultValues()),g?f.url.focus().blur():window.setTimeout(function(){f.url.focus()[0].select()}),d=f.url.val().replace(/^http:\/\//,"")},hasSelectedText:function(a){var b,d,e,f=c.selection.getContent();if(/</.test(f)&&(!/^<a [^>]+>[^<]+<\/a>$/.test(f)||-1===f.indexOf("href=")))return!1;if(a){if(d=a.childNodes,0===d.length)return!1;for(e=d.length-1;e>=0;e--)if(b=d[e],3!=b.nodeType&&!tinymce.dom.BookmarkManager.isBookmarkNode(b))return!1}return!0},mceRefresh:function(a,d){var e,g=b(),h=this.hasSelectedText(g);g?(e=g.innerText||g.textContent,tinymce.trim(e)||(e=d||""),a=a||c.dom.getAttrib(g,"href"),"_wp_link_placeholder"!==a?(f.url.val(a),f.openInNewTab.prop("checked","_blank"===c.dom.getAttrib(g,"target")),f.submit.val(wpLinkL10n.update)):this.setDefaultValues(e)):(e=c.selection.getContent({format:"text"})||d||"",this.setDefaultValues(e)),h?(f.text.val(e),f.wrap.addClass("has-text-field")):(f.text.val(""),f.wrap.removeClass("has-text-field")