var wpLink;!function(e,t,i){function n(){return c||s.dom.getParent(s.selection.getNode(),"a[href]")}var s,l,a,r,o,c,u=/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,d=/^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i,p={},h={},k="ontouchend"in document;wpLink={timeToTriggerRiver:150,minRiverAJAXDuration:200,riverBottomThreshold:5,keySensitivity:100,lastSearch:"",textarea:"",init:function(){var i=50;if("enabled"==awl_title){var n='';jQuery(n).insertAfter("#link-options .wp-link-text-field"),i+=27}if(awl_linkstyles.length>=1){var s='';jQuery(s).insertAfter("#link-options .link-target"),jQuery.each(awl_linkstyles,function(e,t){jQuery("#wp-link select#customstyles").append('")}),i+=27}if("enabled"==awl_rel){var n='';jQuery(n).insertAfter("#link-options .link-target"),i+=23}var r=jQuery(".query-results").css("top");jQuery(".query-results").css("top",parseInt(r)+i),p.wrap=e("#wp-link-wrap"),p.dialog=e("#wp-link"),p.backdrop=e("#wp-link-backdrop"),p.submit=e("#wp-link-submit"),p.close=e("#wp-link-close"),p.text=e("#wp-link-text"),p.url=e("#wp-link-url"),p.nonce=e("#_ajax_linking_nonce"),p.openInNewTab=e("#wp-link-target"),p.search=e("#wp-link-search"),p.fsRelNofollow=e("#rel-nofollow-checkbox"),p.fsCustomStyles=e("select#customstyles"),p.fsLinkTitle=e("input#link-title"),h.search=new a(e("#search-results")),h.recent=new a(e("#most-recent-results")),h.elements=p.dialog.find(".query-results"),p.queryNotice=e("#query-notice-message"),p.queryNoticeTextDefault=p.queryNotice.find(".query-notice-default"),p.queryNoticeTextHint=p.queryNotice.find(".query-notice-hint"),p.dialog.keydown(wpLink.keydown),p.dialog.keyup(wpLink.keyup),p.submit.click(function(e){e.preventDefault(),wpLink.update()}),p.close.add(p.backdrop).add("#wp-link-cancel button").click(function(e){e.preventDefault(),wpLink.close()}),h.elements.on("river-select",wpLink.updateFields),p.search.on("focus.wplink",function(){p.queryNoticeTextDefault.hide(),p.queryNoticeTextHint.removeClass("screen-reader-text").show()}).on("blur.wplink",function(){p.queryNoticeTextDefault.show(),p.queryNoticeTextHint.addClass("screen-reader-text").hide()}),p.search.on("keyup input",function(){window.clearTimeout(l),l=window.setTimeout(function(){wpLink.searchInternalLinks()},500)}),p.url.on("paste",function(){setTimeout(wpLink.correctURL,0)}),p.url.on("blur",wpLink.correctURL)},correctURL:function(){var t=e.trim(p.url.val());t&&o!==t&&!/^(?:[a-z]+:|#|\?|\.|\/)/.test(t)&&(p.url.val("http://"+t),o=t)},open:function(t,i,n,l){var a,r=e(document.body);r.addClass("modal-open"),c=l,wpLink.range=null,t&&(window.wpActiveEditor=t),window.wpActiveEditor&&(this.textarea=e("#"+window.wpActiveEditor).get(0),"undefined"!=typeof window.tinymce&&(r.append(p.backdrop,p.wrap),a=window.tinymce.get(window.wpActiveEditor),s=a&&!a.isHidden()?a:null,s&&window.tinymce.isIE&&(s.windowManager.wplinkBookmark=s.selection.getBookmark())),!wpLink.isMCE()&&document.selection&&(this.textarea.focus(),this.range=document.selection.createRange()),p.wrap.show(),p.backdrop.show(),wpLink.refresh(i,n),e(document).trigger("wplink-open",p.wrap))},isMCE:function(){return s&&!s.isHidden()},refresh:function(e,t){var i="";h.search.refresh(),h.recent.refresh(),wpLink.isMCE()?wpLink.mceRefresh(e,t):(p.wrap.hasClass("has-text-field")||p.wrap.addClass("has-text-field"),document.selection?i=document.selection.createRange().text||t||"":"undefined"!=typeof this.textarea.selectionStart&&this.textarea.selectionStart!==this.textarea.selectionEnd&&(t=this.textarea.value.substring(this.textarea.selectionStart,this.textarea.selectionEnd)||t||""),p.text.val(t),wpLink.setDefaultValues()),k?p.url.focus().blur():window.setTimeout(function(){p.url[0].select(),p.url.focus()}),h.recent.ul.children().length||h.recent.ajax(),o=p.url.val().replace(/^http:\/\//,"")},hasSelectedText:function(e){var t,i,n,l=s.selection.getContent();if(/]+>[^<]+<\/a>$/.test(l)||-1===l.indexOf("href=")))return!1;if(e){if(i=e.childNodes,0===i.length)return!1;for(n=i.length-1;n>=0;n--)if(t=i[n],3!=t.nodeType&&!window.tinymce.dom.BookmarkManager.isBookmarkNode(t))return!1}return!0},mceRefresh:function(i,l){var a,r,o=n(),c=this.hasSelectedText(o);o?(a=o.innerText||o.textContent,r=s.dom.getAttrib(o,"href"),e.trim(a)||(a=l||""),i&&(d.test(i)||u.test(i))&&(r=i),"_wp_link_placeholder"!==r?(p.url.val(r),p.openInNewTab.prop("checked","_blank"===s.dom.getAttrib(o,"target")),p.fsRelNofollow.prop("checked","nofollow"===s.dom.getAttrib(o,"rel")),p.fsCustomStyles.find('option[value="'+s.dom.getAttrib(o,"class")+'"]').attr("selected","selected"),p.fsLinkTitle.val(s.dom.getAttrib(o,"title")),p.submit.val(t.update)):this.setDefaultValues(a),i&&i!==r?p.search.val(i):p.search.val(""),window.setTimeout(function(){wpLink.searchInternalLinks()})):(a=s.selection.getContent({format:"text"})||l||"",this.setDefaultValues(a)),c?(p.text.val(a),p.wrap.addClass("has-text-field")):(p.text.val(""),p.wrap.removeClass("has-text-field"))},close:function(t){e(document.body).removeClass("modal-open"),"noReset"!==t&&(wpLink.isMCE()?(s.plugins.wplink&&s.plugins.wplink.close(),s.focus()):(wpLink.textarea.focus(),wpLink.range&&(wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select()))),p.backdrop.hide(),p.wrap.hide(),o=!1,e(document).trigger("wplink-close",p.wrap)},getAttrs:function(){wpLink.correctURL();var t={href:e.trim(p.url.val()),target:p.openInNewTab.prop("checked")?"_blank":"",rel:p.fsRelNofollow.prop("checked")?"nofollow":"","class":p.fsCustomStyles.val(),title:p.fsLinkTitle.val()};return t},buildHtml:function(e){var t='"},update:function(){wpLink.isMCE()?wpLink.mceUpdate():wpLink.htmlUpdate()},htmlUpdate:function(){var e,n,s,l,a,r,o,c=wpLink.textarea;c&&(e=wpLink.getAttrs(),n=p.text.val(),e.href&&(s=wpLink.buildHtml(e),document.selection&&wpLink.range?(c.focus(),wpLink.range.text=s+(n||wpLink.range.text)+"",wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select(),wpLink.range=null):"undefined"!=typeof c.selectionStart&&(l=c.selectionStart,a=c.selectionEnd,o=n||c.value.substring(l,a),s=s+o+"",r=l+s.length,l!==a||o||(r-=4),c.value=c.value.substring(0,l)+s+c.value.substring(a,c.value.length),c.selectionStart=c.selectionEnd=r),wpLink.close(),c.focus(),i.a11y.speak(t.linkInserted)))},mceUpdate:function(){var e,l,a=wpLink.getAttrs();return window.tinymce.isIE&&s.windowManager.wplinkBookmark&&(s.selection.moveToBookmark(s.windowManager.wplinkBookmark),s.windowManager.wplinkBookmark=null),a.href?(e=n(),p.wrap.hasClass("has-text-field")&&(l=p.text.val()||a.href),e?(l&&("innerText"in e?e.innerText=l:e.textContent=l),a["data-wplink-edit"]=null,s.dom.setAttribs(e,a)):l?s.selection.setNode(s.dom.create("a",a,s.dom.encode(l))):s.execCommand("mceInsertLink",!1,a),wpLink.close("noReset"),s.focus(),s.nodeChanged(),void i.a11y.speak(t.linkInserted)):(s.execCommand("unlink"),void wpLink.close())},updateFields:function(e,t){p.url.val(t.children(".item-permalink").val())},getUrlFromSelection:function(t){return t||(this.isMCE()?t=s.selection.getContent({format:"text"}):document.selection&&wpLink.range?t=wpLink.range.text:"undefined"!=typeof this.textarea.selectionStart&&(t=this.textarea.value.substring(this.textarea.selectionStart,this.textarea.selectionEnd))),t=e.trim(t),t&&u.test(t)?"mailto:"+t:t&&d.test(t)?t.replace(/&|�?38;/gi,"&"):""},setDefaultValues:function(e){p.url.val(this.getUrlFromSelection(e)),p.search.val(""),wpLink.searchInternalLinks(),p.submit.val(t.save)},searchInternalLinks:function(){var e,t=p.search.val()||"";if(t.length>2){if(h.recent.hide(),h.search.show(),wpLink.lastSearch==t)return;wpLink.lastSearch=t,e=p.search.parent().find(".spinner").addClass("is-active"),h.search.change(t),h.search.ajax(function(){e.removeClass("is-active")})}else h.search.hide(),h.recent.show()},next:function(){h.search.next(),h.recent.next()},prev:function(){h.search.prev(),h.recent.prev()},keydown:function(e){var t,i;27===e.keyCode?(wpLink.close(),e.stopImmediatePropagation()):9===e.keyCode&&(i=e.target.id,"wp-link-submit"!==i||e.shiftKey?"wp-link-close"===i&&e.shiftKey&&(p.submit.focus(),e.preventDefault()):(p.close.focus(),e.preventDefault())),38!==e.keyCode&&40!==e.keyCode||(!document.activeElement||"link-title-field"!==document.activeElement.id&&"url-field"!==document.activeElement.id)&&(t=38===e.keyCode?"prev":"next",clearInterval(wpLink.keyInterval),wpLink[t](),wpLink.keyInterval=setInterval(wpLink[t],wpLink.keySensitivity),e.preventDefault())},keyup:function(e){38!==e.keyCode&&40!==e.keyCode||(clearInterval(wpLink.keyInterval),e.preventDefault())},delayedCallback:function(e,t){var i,n,s,l;return t?(setTimeout(function(){return n?e.apply(l,s):void(i=!0)},t),function(){return i?e.apply(this,arguments):(s=arguments,l=this,void(n=!0))}):e}},a=function(t,i){var n=this;this.element=t,this.ul=t.children("ul"),this.contentHeight=t.children("#link-selector-height"),this.waiting=t.find(".river-waiting"),this.change(i),this.refresh(),e("#wp-link .query-results, #wp-link #link-selector").scroll(function(){n.maybeLoad()}),t.on("click","li",function(t){n.select(e(this),t)})},e.extend(a.prototype,{refresh:function(){this.deselect(),this.visible=this.element.is(":visible")},show:function(){this.visible||(this.deselect(),this.element.show(),this.visible=!0)},hide:function(){this.element.hide(),this.visible=!1},select:function(e,t){var i,n,s,l;e.hasClass("unselectable")||e==this.selected||(this.deselect(),this.selected=e.addClass("selected"),i=e.outerHeight(),n=this.element.height(),s=e.position().top,l=this.element.scrollTop(),0>s?this.element.scrollTop(l+s):s+i>n&&this.element.scrollTop(l+s-n+i),this.element.trigger("river-select",[e,t,this]))},deselect:function(){this.selected&&this.selected.removeClass("selected"),this.selected=!1},prev:function(){if(this.visible){var e;this.selected&&(e=this.selected.prev("li"),e.length&&this.select(e))}},next:function(){if(this.visible){var t=this.selected?this.selected.next("li"):e("li:not(.unselectable):first",this.element);t.length&&this.select(t)}},ajax:function(e){var t=this,i=1==this.query.page?0:wpLink.minRiverAJAXDuration,n=wpLink.delayedCallback(function(i,n){t.process(i,n),e&&e(i,n)},i);this.query.ajax(n)},change:function(e){this.query&&this._search==e||(this._search=e,this.query=new r(e),this.element.scrollTop(0))},process:function(i,n){var s="",l=!0,a="",r=1==n.page;i?e.each(i,function(){a=l?"alternate":"",a+=this.title?"":" no-title",s+=a?'
  • ':"
  • ",s+='',s+='',s+=this.title?this.title:t.noTitle,s+=''+this.info+"
  • ",l=!l}):r&&(s+='
  • '+t.noMatchesFound+"
  • "),this.ul[r?"html":"append"](s)},maybeLoad:function(){var e=this,t=this.element,i=t.scrollTop()+t.height();!this.query.ready()||i