!function(a){a.ui.WPLinkPreview=a.ui.Control.extend({url:"#",renderHtml:function(){return'
"},setURL:function(b){var c,d;this.url!==b&&(this.url=b,b=window.decodeURIComponent(b),b=b.replace(/^(?:https?:)?\/\/(?:www\.)?/,""),-1!==(c=b.indexOf("?"))&&(b=b.slice(0,c)),-1!==(c=b.indexOf("#"))&&(b=b.slice(0,c)),b=b.replace(/(?:index)?\.html$/,""),"/"===b.charAt(b.length-1)&&(b=b.slice(0,-1)),b.length>40&&-1!==(c=b.indexOf("/"))&&-1!==(d=b.lastIndexOf("/"))&&d!==c&&(c+b.length-d<40&&(d=-(40-(c+1))),b=b.slice(0,c+1)+"\u2026"+b.slice(d)),a.$(this.getEl().firstChild).attr("href",this.url).text(b))}}),a.ui.WPLinkInput=a.ui.Control.extend({renderHtml:function(){return''},setURL:function(a){this.getEl().firstChild.value=a}}),a.PluginManager.add("wplink",function(b){var c,d,e,f,g,h=window.jQuery;b.on("preinit",function(){b.wp&&b.wp._createToolbar&&(d=b.wp._createToolbar(["wp_link_preview","wp_link_edit","wp_link_remove"],!0),e=b.wp._createToolbar(["wp_link_input","wp_link_apply","wp_link_advanced"],!0),e.on("show",function(){var a=e.find("toolbar")[0];a&&a.focus(!0),c=b.dom.getParent(b.selection.getNode(),"a")}),e.on("hide",function(){e.scrolling||b.execCommand("wp_link_cancel")}))}),b.addCommand("WP_Link",function(){var a=b.dom.getParent(b.selection.getNode(),"a");a?b.dom.setAttribs(a,{"data-wp-edit":!0}):b.execCommand("mceInsertLink",!1,{href:"_wp_link_placeholder"}),b.nodeChanged()}),b.addCommand("wp_link_apply",function(){if(!e.scrolling){var d=a.trim(g.getEl().firstChild.value);if(d&&!/^(?:[a-z]+:|#|\?|\.|\/)/.test(d)&&(d="http://"+d),!d)return void b.dom.remove(c,!0);c&&b.dom.setAttribs(c,{href:d,"data-wp-edit":null}),c=!1,b.nodeChanged(),b.focus()}}),b.addCommand("wp_link_cancel",function(){c&&("_wp_link_placeholder"===b.$(c).attr("href")?b.dom.remove(c,!0):b.dom.setAttribs(c,{"data-wp-edit":null})),c=!1,b.nodeChanged(),b.focus()}),b.addShortcut("access+a","","WP_Link"),b.addShortcut("meta+k","","WP_Link"),b.addButton("link",{icon:"link",tooltip:"Insert/edit link",cmd:"WP_Link",stateSelector:"a[href]"}),b.addButton("unlink",{icon:"unlink",tooltip:"Remove link",cmd:"unlink"}),b.addMenuItem("link",{icon:"link",text:"Insert/edit link",cmd:"WP_Link",stateSelector:"a[href]",context:"insert",prependToContext:!0}),b.on("pastepreprocess",function(c){var d=c.content,e=/^(?:https?:)?\/\/\S+$/i;b.selection.isCollapsed()||e.test(b.selection.getContent())||(d=d.replace(/<[^>]+>/g,""),d=a.trim(d),e.test(d)&&(b.execCommand("mceInsertLink",!1,{href:b.dom.decode(d)}),c.preventDefault()))}),b.addButton("wp_link_preview",{type:"WPLinkPreview",onPostRender:function(){f=this}}),b.addButton("wp_link_input",{type:"WPLinkInput",onPostRender:function(){var c,d,f=this.getEl().firstChild;g=this,h&&(h(f).on("keydown",function(){h(f).removeAttr("aria-activedescendant")}).autocomplete({source:function(a,b){return d===a.term?void b(c):/^https?:/.test(a.term)||-1!==a.term.indexOf(".")?b():(h.post(window.ajaxurl,{action:"wp-link-ajax",page:1,search:a.term,_ajax_linking_nonce:h("#_ajax_linking_nonce").val()},function(a){c=a,b(a)},"json"),void(d=a.term))},focus:function(a,b){h(f).attr("aria-activedescendant","mce-wp-autocomplete-"+b.item.ID)},select:function(a,b){return h(f).val(b.item.permalink),!1},open:function(){h(f).attr("aria-expanded","true"),e.blockHide=!0},close:function(){h(f).attr("aria-expanded","false"),e.blockHide=!1},minLength:2,position:{my:"left top+5"}}).autocomplete("instance")._renderItem=function(a,b){return h('