var wpLink;!function(s){var a,t,i,n,r,l={},o={},c="ontouchend"in document;wpLink={timeToTriggerRiver:150,minRiverAJAXDuration:200,riverBottomThreshold:5,keySensitivity:100,lastSearch:"",textarea:"",init:function(){function e(){var e=s.trim(l.url.val());e&&r!==e&&!/^(?:[a-z]+:|#|\?|\.|\/)/.test(e)&&(l.url.val("http://"+e),r=e)}l.wrap=s("#wp-link-wrap"),l.dialog=s("#wp-link"),l.backdrop=s("#wp-link-backdrop"),l.submit=s("#wp-link-submit"),l.close=s("#wp-link-close"),l.text=s("#wp-link-text"),l.url=s("#wp-link-url"),l.nonce=s("#_ajax_linking_nonce"),l.openInNewTab=s("#wp-link-target"),l.search=s("#wp-link-search"),o.search=new i(s("#search-results")),o.recent=new i(s("#most-recent-results")),o.elements=l.dialog.find(".query-results"),l.queryNotice=s("#query-notice-message"),l.queryNoticeTextDefault=l.queryNotice.find(".query-notice-default"),l.queryNoticeTextHint=l.queryNotice.find(".query-notice-hint"),l.dialog.keydown(wpLink.keydown),l.dialog.keyup(wpLink.keyup),l.submit.click(function(e){e.preventDefault(),wpLink.update()}),l.close.add(l.backdrop).add("#wp-link-cancel a").click(function(e){e.preventDefault(),wpLink.close()}),s("#wp-link-search-toggle").on("click",wpLink.toggleInternalLinking),o.elements.on("river-select",wpLink.updateFields),l.search.on("focus.wplink",function(){l.queryNoticeTextDefault.hide(),l.queryNoticeTextHint.removeClass("screen-reader-text").show()}).on("blur.wplink",function(){l.queryNoticeTextDefault.show(),l.queryNoticeTextHint.addClass("screen-reader-text").hide()}),l.search.keyup(function(){var e=this;window.clearTimeout(t),t=window.setTimeout(function(){wpLink.searchInternalLinks.call(e)},500)}),l.url.on("paste",function(){setTimeout(e,0)}),l.url.on("blur",e)},open:function(e){s(document.body).addClass("modal-open"),wpLink.range=null,e&&(window.wpActiveEditor=e),window.wpActiveEditor&&(this.textarea=s("#"+window.wpActiveEditor).get(0),"undefined"!=typeof tinymce&&(e=tinymce.get(wpActiveEditor),(a=e&&!e.isHidden()?e:null)&&tinymce.isIE&&(a.windowManager.bookmark=a.selection.getBookmark())),!wpLink.isMCE()&&document.selection&&(this.textarea.focus(),this.range=document.selection.createRange()),l.wrap.show(),l.backdrop.show(),wpLink.refresh(),s(document).trigger("wplink-open",l.wrap))},isMCE:function(){return a&&!a.isHidden()},refresh:function(){var e="";o.search.refresh(),o.recent.refresh(),wpLink.isMCE()?wpLink.mceRefresh():(l.wrap.hasClass("has-text-field")||l.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)||""),l.text.val(e),wpLink.setDefaultValues()),c?l.url.focus().blur():l.url.focus()[0].select(),o.recent.ul.children().length||o.recent.ajax(),r=l.url.val().replace(/^http:\/\//,"")},hasSelectedText:function(e){var t=a.selection.getContent();if(/]+>[^<]+<\/a>$/.test(t)||-1===t.indexOf("href=")))return!1;if(e){var i,n=e.childNodes;if(0===n.length)return!1;for(i=n.length-1;0<=i;i--)if(3!=n[i].nodeType)return!1}return!0},mceRefresh:function(){var e,t=a.selection.getNode(),i=a.dom.getParent(t,"a[href]"),t=this.hasSelectedText(i);i?(e=i.innerText||i.textContent,l.url.val(a.dom.getAttrib(i,"href")),l.openInNewTab.prop("checked","_blank"===a.dom.getAttrib(i,"target")),l.submit.val(wpLinkL10n.update)):(e=a.selection.getContent({format:"text"}),this.setDefaultValues()),t?(l.text.val(e||""),l.wrap.addClass("has-text-field")):(l.text.val(""),l.wrap.removeClass("has-text-field"))},close:function(){s(document.body).removeClass("modal-open"),wpLink.isMCE()?a.focus():(wpLink.textarea.focus(),wpLink.range&&(wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select())),l.backdrop.hide(),l.wrap.hide(),r=!1,s(document).trigger("wplink-close",l.wrap)},getAttrs:function(){return{href:s.trim(l.url.val()),target:l.openInNewTab.prop("checked")?"_blank":""}},update:function(){wpLink.isMCE()?wpLink.mceUpdate():wpLink.htmlUpdate()},htmlUpdate:function(){var e,t,i,n,a,s=wpLink.textarea;s&&(n=wpLink.getAttrs(),i=l.text.val(),(a=document.createElement("a")).href=n.href,"javascript:"!==a.protocol&&"data:"!==a.protocol||(n.href=""),n.href?(e='",document.selection&&wpLink.range?(s.focus(),wpLink.range.text=e+(i||wpLink.range.text)+"",wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select(),wpLink.range=null):void 0!==s.selectionStart&&(t=s.selectionStart,a=s.selectionEnd,i=t+(e=e+(n=i||s.value.substring(t,a))+"").length,t!==a||n||(i-=4),s.value=s.value.substring(0,t)+e+s.value.substring(a,s.value.length),s.selectionStart=s.selectionEnd=i),wpLink.close(),s.focus()):wpLink.close())},mceUpdate:function(){var e,t=wpLink.getAttrs();wpLink.close(),a.focus(),tinymce.isIE&&a.selection.moveToBookmark(a.windowManager.bookmark);var i=document.createElement("a");i.href=t.href,"javascript:"!==i.protocol&&"data:"!==i.protocol||(t.href=""),t.href?(e=a.dom.getParent(a.selection.getNode(),"a"),i=l.text.val(),e?(i&&("innerText"in e?e.innerText=i:e.textContent=i),a.dom.setAttribs(e,t)):i?a.selection.setNode(a.dom.create("a",t,i)):a.execCommand("mceInsertLink",!1,t)):a.execCommand("unlink")},updateFields:function(e,t){l.url.val(t.children(".item-permalink").val())},setDefaultValues:function(){var e;this.isMCE()?e=a.selection.getContent():document.selection&&wpLink.range?e=wpLink.range.text:void 0!==this.textarea.selectionStart&&(e=this.textarea.value.substring(this.textarea.selectionStart,this.textarea.selectionEnd)),e&&/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(e)?l.url.val("mailto:"+e):e&&/^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i.test(e)?l.url.val(e.replace(/&|?38;/gi,"&")):l.url.val(""),l.submit.val(wpLinkL10n.save)},searchInternalLinks:function(){var e,t=s(this),i=t.val();2':"",n+='',n+='',n+=this.title||wpLinkL10n.noTitle,n+=''+this.info+"",a=!a}):t&&(n+=''+wpLinkL10n.noMatchesFound+""),this.ul[t?"html":"append"](n)},maybeLoad:function(){var i=this,n=this.element,e=n.scrollTop()+n.height();!this.query.ready()||e