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