var wpLink;!function(e,t,n){function i(){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,p=/^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i,d={},h={},w="ontouchend"in document;wpLink={timeToTriggerRiver:150,minRiverAJAXDuration:200,riverBottomThreshold:5,keySensitivity:100,lastSearch:"",textarea:"",init:function(){var t='';jQuery(t).insertAfter("#wp-link .link-target");var n='';jQuery(n).insertAfter("#wp-link .wp-link-text-field"),jQuery.each(awl_linkstyles,function(e,t){jQuery("#wp-link select#customstyles").append('")});var i=jQuery(".query-results").css("top");jQuery(".query-results").css("top",parseInt(i)+90),d.wrap=e("#wp-link-wrap"),d.dialog=e("#wp-link"),d.backdrop=e("#wp-link-backdrop"),d.submit=e("#wp-link-submit"),d.close=e("#wp-link-close"),d.text=e("#wp-link-text"),d.url=e("#wp-link-url"),d.nonce=e("#_ajax_linking_nonce"),d.openInNewTab=e("#wp-link-target"),d.search=e("#wp-link-search"),d.fsRelNofollow=e("#rel-nofollow-checkbox"),d.fsCustomStyles=e("select#customstyles"),h.search=new a(e("#search-results")),h.recent=new a(e("#most-recent-results")),h.elements=d.dialog.find(".query-results"),d.queryNotice=e("#query-notice-message"),d.queryNoticeTextDefault=d.queryNotice.find(".query-notice-default"),d.queryNoticeTextHint=d.queryNotice.find(".query-notice-hint"),d.dialog.keydown(wpLink.keydown),d.dialog.keyup(wpLink.keyup),d.submit.click(function(e){e.preventDefault(),wpLink.update()}),d.close.add(d.backdrop).add("#wp-link-cancel button").click(function(e){e.preventDefault(),wpLink.close()}),h.elements.on("river-select",wpLink.updateFields),d.search.on("focus.wplink",function(){d.queryNoticeTextDefault.hide(),d.queryNoticeTextHint.removeClass("screen-reader-text").show()}).on("blur.wplink",function(){d.queryNoticeTextDefault.show(),d.queryNoticeTextHint.addClass("screen-reader-text").hide()}),d.search.on("keyup input",function(){window.clearTimeout(l),l=window.setTimeout(function(){wpLink.searchInternalLinks()},500)}),d.url.on("paste",function(){setTimeout(wpLink.correctURL,0)}),d.url.on("blur",wpLink.correctURL)},correctURL:function(){var t=e.trim(d.url.val());t&&o!==t&&!/^(?:[a-z]+:|#|\?|\.|\/)/.test(t)&&(d.url.val("http://"+t),o=t)},open:function(t,n,i,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(d.backdrop,d.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()),d.wrap.show(),d.backdrop.show(),wpLink.refresh(n,i),e(document).trigger("wplink-open",d.wrap))},isMCE:function(){return s&&!s.isHidden()},refresh:function(e,t){var n="";h.search.refresh(),h.recent.refresh(),wpLink.isMCE()?wpLink.mceRefresh(e,t):(d.wrap.hasClass("has-text-field")||d.wrap.addClass("has-text-field"),document.selection?n=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||""),d.text.val(t),wpLink.setDefaultValues()),w?d.url.focus().blur():window.setTimeout(function(){d.url[0].select(),d.url.focus()}),h.recent.ul.children().length||h.recent.ajax(),o=d.url.val().replace(/^http:\/\//,"")},hasSelectedText:function(e){var t,n,i,l=s.selection.getContent();if(/]+>[^<]+<\/a>$/.test(l)||-1===l.indexOf("href=")))return!1;if(e){if(n=e.childNodes,0===n.length)return!1;for(i=n.length-1;i>=0;i--)if(t=n[i],3!=t.nodeType&&!window.tinymce.dom.BookmarkManager.isBookmarkNode(t))return!1}return!0},mceRefresh:function(n,l){var a,r,o=i(),c=this.hasSelectedText(o);o?(a=o.innerText||o.textContent,r=s.dom.getAttrib(o,"href"),e.trim(a)||(a=l||""),n&&(p.test(n)||u.test(n))&&(r=n),"_wp_link_placeholder"!==r?(d.url.val(r),d.openInNewTab.prop("checked","_blank"===s.dom.getAttrib(o,"target")),d.fsRelNofollow.prop("checked","nofollow"===s.dom.getAttrib(o,"rel")),d.fsCustomStyles.find('option[value="'+s.dom.getAttrib(o,"class")+'"]').attr("selected","selected"),d.submit.val(t.update)):this.setDefaultValues(a),n&&n!==r?d.search.val(n):d.search.val(""),window.setTimeout(function(){wpLink.searchInternalLinks()})):(a=s.selection.getContent({format:"text"})||l||"",this.setDefaultValues(a)),c?(d.text.val(a),d.wrap.addClass("has-text-field")):(d.text.val(""),d.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()))),d.backdrop.hide(),d.wrap.hide(),o=!1,e(document).trigger("wplink-close",d.wrap)},getAttrs:function(){return wpLink.correctURL(),{href:e.trim(d.url.val()),target:d.openInNewTab.prop("checked")?"_blank":"",rel:d.fsRelNofollow.prop("checked")?"nofollow":"","class":d.fsCustomStyles.val()}},buildHtml:function(e){var t='"},update:function(){wpLink.isMCE()?wpLink.mceUpdate():wpLink.htmlUpdate()},htmlUpdate:function(){var e,i,s,l,a,r,o,c=wpLink.textarea;c&&(e=wpLink.getAttrs(),i=d.text.val(),e.href&&(s=wpLink.buildHtml(e),document.selection&&wpLink.range?(c.focus(),wpLink.range.text=s+(i||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=i||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(),n.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=i(),d.wrap.hasClass("has-text-field")&&(l=d.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 n.a11y.speak(t.linkInserted)):(s.execCommand("unlink"),void wpLink.close())},updateFields:function(e,t){d.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&&p.test(t)?t.replace(/&|�?38;/gi,"&"):""},setDefaultValues:function(e){d.url.val(this.getUrlFromSelection(e)),d.search.val(""),wpLink.searchInternalLinks(),d.submit.val(t.save)},searchInternalLinks:function(){var e,t=d.search.val()||"";if(t.length>2){if(h.recent.hide(),h.search.show(),wpLink.lastSearch==t)return;wpLink.lastSearch=t,e=d.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,n;27===e.keyCode?(wpLink.close(),e.stopImmediatePropagation()):9===e.keyCode&&(n=e.target.id,"wp-link-submit"!==n||e.shiftKey?"wp-link-close"===n&&e.shiftKey&&(d.submit.focus(),e.preventDefault()):(d.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 n,i,s,l;return t?(setTimeout(function(){return i?e.apply(l,s):void(n=!0)},t),function(){return n?e.apply(this,arguments):(s=arguments,l=this,void(i=!0))}):e}},a=function(t,n){var i=this;this.element=t,this.ul=t.children("ul"),this.contentHeight=t.children("#link-selector-height"),this.waiting=t.find(".river-waiting"),this.change(n),this.refresh(),e("#wp-link .query-results, #wp-link #link-selector").scroll(function(){i.maybeLoad()}),t.on("click","li",function(t){i.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 n,i,s,l;e.hasClass("unselectable")||e==this.selected||(this.deselect(),this.selected=e.addClass("selected"),n=e.outerHeight(),i=this.element.height(),s=e.position().top,l=this.element.scrollTop(),0>s?this.element.scrollTop(l+s):s+n>i&&this.element.scrollTop(l+s-i+n),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,n=1==this.query.page?0:wpLink.minRiverAJAXDuration,i=wpLink.delayedCallback(function(n,i){t.process(n,i),e&&e(n,i)},n);this.query.ajax(i)},change:function(e){this.query&&this._search==e||(this._search=e,this.query=new r(e),this.element.scrollTop(0))},process:function(n,i){var s="",l=!0,a="",r=1==i.page;n?e.each(n,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,n=t.scrollTop()+t.height();!this.query.ready()||n