diff --git a/wp-includes/js/tinymce/plugins/wplink/plugin.js b/wp-includes/js/tinymce/plugins/wplink/plugin.js index b1769a51c7..4ffd5dc109 100644 --- a/wp-includes/js/tinymce/plugins/wplink/plugin.js +++ b/wp-includes/js/tinymce/plugins/wplink/plugin.js @@ -41,7 +41,7 @@ if ( url.length > 40 && ( index = url.indexOf( '/' ) ) !== -1 && ( lastIndex = url.lastIndexOf( '/' ) ) !== -1 && lastIndex !== index ) { // If the beginning + ending are shorter that 40 chars, show more of the ending if ( index + url.length - lastIndex < 40 ) { - lastIndex = -( 40 - ( index + 1 ) ); + lastIndex = -( 40 - ( index + 1 ) ); } url = url.slice( 0, index + 1 ) + '\u2026' + url.slice( lastIndex ); @@ -74,26 +74,49 @@ var $ = window.jQuery; function getSelectedLink() { - var href, - selectedNode = editor.selection.getNode(), - selectedText = editor.selection.getContent(), - link = editor.dom.getParent( selectedNode, 'a[href]' ); + var href, html + node = editor.selection.getNode(); + link = editor.dom.getParent( node, 'a[href]' ); - if ( ! link && selectedText.indexOf( '' ) !== -1 ) { - href = selectedText.match( /href="([^">]+)"/ ); + if ( ! link ) { + html = editor.selection.getContent({ format: 'raw' }); - if ( href && href[1] ) { - link = editor.$( 'a[href="' + href[1] + '"]', selectedNode )[0]; - } + if ( html && html.indexOf( '' ) !== -1 ) { + href = html.match( /href="([^">]+)"/ ); - if ( link ) { - editor.selection.select( link ); - editor.nodeChanged(); + if ( href && href[1] ) { + link = editor.$( 'a[href="' + href[1] + '"]', node )[0]; + } + + if ( link ) { + editor.selection.select( link ); + editor.nodeChanged(); + } } } return link; } + + function removePlaceholders() { + editor.$( 'a' ).each( function( i, element ) { + var $element = editor.$( element ); + + if ( $element.attr( 'href' ) === '_wp_link_placeholder' ) { + editor.dom.remove( element, true ); + } else if ( $element.attr( 'data-wp-link-edit' ) ) { + $element.attr( 'data-wp-link-edit', null ); + } + }); + } + + function removePlaceholderStrings( content, dataAttr ) { + if ( dataAttr ) { + content = content.replace( / data-wp-link-edit="true"/g, '' ); + } + + return content.replace( /]*?href="_wp_link_placeholder"[^>]*>([\s\S]+)<\/a>/g, '$1' ); + } editor.on( 'preinit', function() { if ( editor.wp && editor.wp._createToolbar ) { @@ -126,9 +149,12 @@ var link = getSelectedLink(); if ( link ) { - editor.dom.setAttribs( link, { 'data-wp-edit': true } ); + editor.dom.setAttribs( link, { 'data-wp-link-edit': true } ); } else { + removePlaceholders(); + editor.execCommand( 'mceInsertLink', false, { href: '_wp_link_placeholder' } ); + editor.selection.select( editor.$( 'a[href="_wp_link_placeholder"]' )[0] ); editor.nodeChanged(); } } ); @@ -150,7 +176,7 @@ } if ( a ) { - editor.dom.setAttribs( a, { href: href, 'data-wp-edit': null } ); + editor.dom.setAttribs( a, { href: href, 'data-wp-link-edit': null } ); } a = false; @@ -160,16 +186,8 @@ } ); editor.addCommand( 'wp_link_cancel', function() { - if ( a ) { - if ( editor.$( a ).attr( 'href' ) === '_wp_link_placeholder' ) { - editor.dom.remove( a, true ); - } else { - editor.dom.setAttribs( a, { 'data-wp-edit': null } ); - } - } - + removePlaceholders(); a = false; - editor.nodeChanged(); editor.focus(); } ); @@ -218,6 +236,18 @@ } } } ); + + // Remove any remaining placeholders on saving. + editor.on( 'savecontent', function( event ) { + event.content = removePlaceholderStrings( event.content, true ); + }); + + // Prevent adding undo levels on inserting link placeholder. + editor.on( 'BeforeAddUndo', function( event ) { + if ( event.level.content ) { + event.level.content = removePlaceholderStrings( event.level.content ); + } + }); editor.addButton( 'wp_link_preview', { type: 'WPLinkPreview', @@ -235,7 +265,7 @@ inputInstance = this; - if ( $ ) { + if ( $ && $.ui && $.ui.autocomplete ) { $( input ) .on( 'keydown', function() { $( input ).removeAttr( 'aria-activedescendant' ); @@ -311,13 +341,12 @@ editor.on( 'wptoolbar', function( event ) { var anchor = editor.dom.getParent( event.element, 'a' ), - $anchor, - href, edit; + $anchor, href, edit; if ( anchor ) { $anchor = editor.$( anchor ); href = $anchor.attr( 'href' ); - edit = $anchor.attr( 'data-wp-edit' ); + edit = $anchor.attr( 'data-wp-link-edit' ); if ( href === '_wp_link_placeholder' || edit ) { inputInstance.setURL( edit ? href : '' ); @@ -348,8 +377,13 @@ tooltip: 'Advanced', icon: 'dashicon dashicons-admin-generic', onclick: function() { - editor.execCommand( 'wp_link_apply' ); - window.wpLink && window.wpLink.open( editor.id ); + if ( typeof window.wpLink !== 'undefined' ) { + if ( inputInstance.getEl().firstChild.value ) { + editor.execCommand( 'wp_link_apply' ); + } + + window.wpLink.open( editor.id ); + } } } ); diff --git a/wp-includes/js/tinymce/plugins/wplink/plugin.min.js b/wp-includes/js/tinymce/plugins/wplink/plugin.min.js index 9468c37e75..28b00dcb8c 100644 --- a/wp-includes/js/tinymce/plugins/wplink/plugin.min.js +++ b/wp-includes/js/tinymce/plugins/wplink/plugin.min.js @@ -1 +1 @@ -!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&&(b=this.url),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){function c(){var a,c=b.selection.getNode(),d=b.selection.getContent(),e=b.dom.getParent(c,"a[href]");return e||-1===d.indexOf("")||(a=d.match(/href="([^">]+)"/),a&&a[1]&&(e=b.$('a[href="'+a[1]+'"]',c)[0]),e&&(b.selection.select(e),b.nodeChanged())),e}var d,e,f,g,h,i=window.jQuery;b.on("preinit",function(){b.wp&&b.wp._createToolbar&&(e=b.wp._createToolbar(["wp_link_preview","wp_link_edit","wp_link_remove"],!0),f=b.wp._createToolbar(["wp_link_input","wp_link_apply","wp_link_advanced"],!0),f.on("show",function(){var a=f.find("toolbar")[0];a&&a.focus(!0),d=c()}),f.on("hide",function(){f.scrolling||b.execCommand("wp_link_cancel")}))}),b.addCommand("WP_Link",function(){var a=c();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(!f.scrolling){var c=a.trim(h.getEl().firstChild.value);if(c&&!/^(?:[a-z]+:|#|\?|\.|\/)/.test(c)&&(c="http://"+c),!c)return void b.dom.remove(d,!0);d&&b.dom.setAttribs(d,{href:c,"data-wp-edit":null}),d=!1,b.nodeChanged(),b.focus()}}),b.addCommand("wp_link_cancel",function(){d&&("_wp_link_placeholder"===b.$(d).attr("href")?b.dom.remove(d,!0):b.dom.setAttribs(d,{"data-wp-edit":null})),d=!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(){g=this}}),b.addButton("wp_link_input",{type:"WPLinkInput",onPostRender:function(){var c,d,e=this.getEl().firstChild;h=this,i&&(i(e).on("keydown",function(){i(e).removeAttr("aria-activedescendant")}).autocomplete({source:function(a,b){return d===a.term?void b(c):/^https?:/.test(a.term)||-1!==a.term.indexOf(".")?b():(i.post(window.ajaxurl,{action:"wp-link-ajax",page:1,search:a.term,_ajax_linking_nonce:i("#_ajax_linking_nonce").val()},function(a){c=a,b(a)},"json"),void(d=a.term))},focus:function(a,b){i(e).attr("aria-activedescendant","mce-wp-autocomplete-"+b.item.ID)},select:function(a,b){return i(e).val(b.item.permalink),!1},open:function(){i(e).attr("aria-expanded","true"),f.blockHide=!0},close:function(){i(e).attr("aria-expanded","false"),f.blockHide=!1},minLength:2,position:{my:"left top+5"}}).autocomplete("instance")._renderItem=function(a,b){return i('
  • ').append(""+b.title+' '+b.info+"").appendTo(a)},i(e).attr({role:"combobox","aria-autocomplete":"list","aria-expanded":"false","aria-owns":i(e).autocomplete("widget").attr("id")}).on("focus",function(){i(e).autocomplete("search")}).autocomplete("widget").addClass("mce-wp-autocomplete").attr("role","listbox")),a.$(e).on("keydown",function(a){13===a.keyCode&&b.execCommand("wp_link_apply")})}}),b.on("wptoolbar",function(a){var c,d,i,j=b.dom.getParent(a.element,"a");j&&(c=b.$(j),d=c.attr("href"),i=c.attr("data-wp-edit"),"_wp_link_placeholder"===d||i?(h.setURL(i?d:""),a.element=j,a.toolbar=f):d&&!c.find("img").length&&(g.setURL(d),a.element=j,a.toolbar=e))}),b.addButton("wp_link_edit",{tooltip:"Edit ",icon:"dashicon dashicons-edit",cmd:"WP_Link"}),b.addButton("wp_link_remove",{tooltip:"Remove",icon:"dashicon dashicons-no",cmd:"unlink"}),b.addButton("wp_link_advanced",{tooltip:"Advanced",icon:"dashicon dashicons-admin-generic",onclick:function(){b.execCommand("wp_link_apply"),window.wpLink&&window.wpLink.open(b.id)}}),b.addButton("wp_link_apply",{tooltip:"Apply",icon:"dashicon dashicons-editor-break",cmd:"wp_link_apply",classes:"widget btn primary"})})}(window.tinymce); \ No newline at end of file +!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&&(b=this.url),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){function c(){var a,c;return node=b.selection.getNode(),link=b.dom.getParent(node,"a[href]"),link||(c=b.selection.getContent({format:"raw"}),c&&-1!==c.indexOf("")&&(a=c.match(/href="([^">]+)"/),a&&a[1]&&(link=b.$('a[href="'+a[1]+'"]',node)[0]),link&&(b.selection.select(link),b.nodeChanged()))),link}function d(){b.$("a").each(function(a,c){var d=b.$(c);"_wp_link_placeholder"===d.attr("href")?b.dom.remove(c,!0):d.attr("data-wp-link-edit")&&d.attr("data-wp-link-edit",null)})}function e(a,b){return b&&(a=a.replace(/ data-wp-link-edit="true"/g,"")),a.replace(/]*?href="_wp_link_placeholder"[^>]*>([\s\S]+)<\/a>/g,"$1")}var f,g,h,i,j,k=window.jQuery;b.on("preinit",function(){b.wp&&b.wp._createToolbar&&(g=b.wp._createToolbar(["wp_link_preview","wp_link_edit","wp_link_remove"],!0),h=b.wp._createToolbar(["wp_link_input","wp_link_apply","wp_link_advanced"],!0),h.on("show",function(){var a=h.find("toolbar")[0];a&&a.focus(!0),f=c()}),h.on("hide",function(){h.scrolling||b.execCommand("wp_link_cancel")}))}),b.addCommand("WP_Link",function(){var a=c();a?b.dom.setAttribs(a,{"data-wp-link-edit":!0}):(d(),b.execCommand("mceInsertLink",!1,{href:"_wp_link_placeholder"}),b.selection.select(b.$('a[href="_wp_link_placeholder"]')[0]),b.nodeChanged())}),b.addCommand("wp_link_apply",function(){if(!h.scrolling){var c=a.trim(j.getEl().firstChild.value);if(c&&!/^(?:[a-z]+:|#|\?|\.|\/)/.test(c)&&(c="http://"+c),!c)return void b.dom.remove(f,!0);f&&b.dom.setAttribs(f,{href:c,"data-wp-link-edit":null}),f=!1,b.nodeChanged(),b.focus()}}),b.addCommand("wp_link_cancel",function(){d(),f=!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.on("savecontent",function(a){a.content=e(a.content,!0)}),b.on("BeforeAddUndo",function(a){a.level.content&&(a.level.content=e(a.level.content))}),b.addButton("wp_link_preview",{type:"WPLinkPreview",onPostRender:function(){i=this}}),b.addButton("wp_link_input",{type:"WPLinkInput",onPostRender:function(){var c,d,e=this.getEl().firstChild;j=this,k&&k.ui&&k.ui.autocomplete&&(k(e).on("keydown",function(){k(e).removeAttr("aria-activedescendant")}).autocomplete({source:function(a,b){return d===a.term?void b(c):/^https?:/.test(a.term)||-1!==a.term.indexOf(".")?b():(k.post(window.ajaxurl,{action:"wp-link-ajax",page:1,search:a.term,_ajax_linking_nonce:k("#_ajax_linking_nonce").val()},function(a){c=a,b(a)},"json"),void(d=a.term))},focus:function(a,b){k(e).attr("aria-activedescendant","mce-wp-autocomplete-"+b.item.ID)},select:function(a,b){return k(e).val(b.item.permalink),!1},open:function(){k(e).attr("aria-expanded","true"),h.blockHide=!0},close:function(){k(e).attr("aria-expanded","false"),h.blockHide=!1},minLength:2,position:{my:"left top+5"}}).autocomplete("instance")._renderItem=function(a,b){return k('
  • ').append(""+b.title+' '+b.info+"").appendTo(a)},k(e).attr({role:"combobox","aria-autocomplete":"list","aria-expanded":"false","aria-owns":k(e).autocomplete("widget").attr("id")}).on("focus",function(){k(e).autocomplete("search")}).autocomplete("widget").addClass("mce-wp-autocomplete").attr("role","listbox")),a.$(e).on("keydown",function(a){13===a.keyCode&&b.execCommand("wp_link_apply")})}}),b.on("wptoolbar",function(a){var c,d,e,f=b.dom.getParent(a.element,"a");f&&(c=b.$(f),d=c.attr("href"),e=c.attr("data-wp-link-edit"),"_wp_link_placeholder"===d||e?(j.setURL(e?d:""),a.element=f,a.toolbar=h):d&&!c.find("img").length&&(i.setURL(d),a.element=f,a.toolbar=g))}),b.addButton("wp_link_edit",{tooltip:"Edit ",icon:"dashicon dashicons-edit",cmd:"WP_Link"}),b.addButton("wp_link_remove",{tooltip:"Remove",icon:"dashicon dashicons-no",cmd:"unlink"}),b.addButton("wp_link_advanced",{tooltip:"Advanced",icon:"dashicon dashicons-admin-generic",onclick:function(){"undefined"!=typeof window.wpLink&&(j.getEl().firstChild.value&&b.execCommand("wp_link_apply"),window.wpLink.open(b.id))}}),b.addButton("wp_link_apply",{tooltip:"Apply",icon:"dashicon dashicons-editor-break",cmd:"wp_link_apply",classes:"widget btn primary"})})}(window.tinymce); \ No newline at end of file diff --git a/wp-includes/js/tinymce/wp-tinymce.js.gz b/wp-includes/js/tinymce/wp-tinymce.js.gz index 59a6f000bf..f1ff3f77a9 100644 Binary files a/wp-includes/js/tinymce/wp-tinymce.js.gz and b/wp-includes/js/tinymce/wp-tinymce.js.gz differ diff --git a/wp-includes/js/wplink.js b/wp-includes/js/wplink.js index b5a84aecb7..eba50fc70d 100644 --- a/wp-includes/js/wplink.js +++ b/wp-includes/js/wplink.js @@ -219,14 +219,20 @@ var wpLink; }, mceRefresh: function() { - var text, + var text, url, selectedNode = editor.selection.getNode(), linkNode = editor.dom.getParent( selectedNode, 'a[href]' ), onlyText = this.hasSelectedText( linkNode ); if ( linkNode ) { text = linkNode.innerText || linkNode.textContent; - inputs.url.val( editor.dom.getAttrib( linkNode, 'href' ) ); + url = editor.dom.getAttrib( linkNode, 'href' ); + + if ( url === '_wp_link_placeholder' ) { + url = ''; + } + + inputs.url.val( url ); inputs.openInNewTab.prop( 'checked', '_blank' === editor.dom.getAttrib( linkNode, 'target' ) ); inputs.submit.val( wpLinkL10n.update ); } else { @@ -244,6 +250,8 @@ var wpLink; }, close: function() { + var linkNode; + $( document.body ).removeClass( 'modal-open' ); if ( ! wpLink.isMCE() ) { @@ -254,6 +262,12 @@ var wpLink; wpLink.range.select(); } } else { + linkNode = editor.dom.getParent( editor.selection.getNode(), 'a[href]' ); + + if ( linkNode && editor.dom.getAttrib( linkNode, 'href' ) === '_wp_link_placeholder' ) { + editor.dom.remove( linkNode, true ); + } + editor.focus(); } @@ -352,7 +366,6 @@ var wpLink; var attrs = wpLink.getAttrs(), link, text; - wpLink.close(); editor.focus(); if ( tinymce.isIE ) { @@ -388,6 +401,7 @@ var wpLink; } } + wpLink.close(); editor.nodeChanged(); }, diff --git a/wp-includes/js/wplink.min.js b/wp-includes/js/wplink.min.js index cb209184d4..eab9b90119 100644 --- a/wp-includes/js/wplink.min.js +++ b/wp-includes/js/wplink.min.js @@ -1 +1 @@ -var wpLink;!function(a){function b(){return c.dom.getParent(c.selection.getNode(),"a")}var c,d,e,f,g,h={},i={},j="ontouchend"in document;wpLink={timeToTriggerRiver:150,minRiverAJAXDuration:200,riverBottomThreshold:5,keySensitivity:100,lastSearch:"",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.nonce=a("#_ajax_linking_nonce"),h.openInNewTab=a("#wp-link-target"),h.search=a("#wp-link-search"),i.search=new e(a("#search-results")),i.recent=new e(a("#most-recent-results")),i.elements=h.dialog.find(".query-results"),h.queryNotice=a("#query-notice-message"),h.queryNoticeTextDefault=h.queryNotice.find(".query-notice-default"),h.queryNoticeTextHint=h.queryNotice.find(".query-notice-hint"),h.dialog.keydown(wpLink.keydown),h.dialog.keyup(wpLink.keyup),h.submit.click(function(a){a.preventDefault(),wpLink.update()}),h.close.add(h.backdrop).add("#wp-link-cancel a").click(function(a){a.preventDefault(),wpLink.close()}),a("#wp-link-search-toggle").on("click",wpLink.toggleInternalLinking),i.elements.on("river-select",wpLink.updateFields),h.search.on("focus.wplink",function(){h.queryNoticeTextDefault.hide(),h.queryNoticeTextHint.removeClass("screen-reader-text").show()}).on("blur.wplink",function(){h.queryNoticeTextDefault.show(),h.queryNoticeTextHint.addClass("screen-reader-text").hide()}),h.search.on("keyup input",function(){var a=this;window.clearTimeout(d),d=window.setTimeout(function(){wpLink.searchInternalLinks.call(a)},500)}),h.url.on("paste",function(){setTimeout(wpLink.correctURL,0)}),h.url.on("blur",wpLink.correctURL)},correctURL:function(){var b=a.trim(h.url.val());b&&g!==b&&!/^(?:[a-z]+:|#|\?|\.|\/)/.test(b)&&(h.url.val("http://"+b),g=b)},open:function(b){var d,e=a(document.body);e.addClass("modal-open"),wpLink.range=null,b&&(window.wpActiveEditor=b),window.wpActiveEditor&&(this.textarea=a("#"+window.wpActiveEditor).get(0),"undefined"!=typeof tinymce&&(e.append(h.backdrop,h.wrap),d=tinymce.get(wpActiveEditor),c=d&&!d.isHidden()?d:null,c&&tinymce.isIE&&(c.windowManager.bookmark=c.selection.getBookmark())),!wpLink.isMCE()&&document.selection&&(this.textarea.focus(),this.range=document.selection.createRange()),h.wrap.show(),h.backdrop.show(),wpLink.refresh(),a(document).trigger("wplink-open",h.wrap))},isMCE:function(){return c&&!c.isHidden()},refresh:function(){var a="";i.search.refresh(),i.recent.refresh(),wpLink.isMCE()?wpLink.mceRefresh():(h.wrap.hasClass("has-text-field")||h.wrap.addClass("has-text-field"),document.selection?a=document.selection.createRange().text||"":"undefined"!=typeof this.textarea.selectionStart&&this.textarea.selectionStart!==this.textarea.selectionEnd&&(a=this.textarea.value.substring(this.textarea.selectionStart,this.textarea.selectionEnd)||""),h.text.val(a),wpLink.setDefaultValues()),j?h.url.focus().blur():h.url.focus()[0].select(),i.recent.ul.children().length||i.recent.ajax(),g=h.url.val().replace(/^http:\/\//,"")},hasSelectedText:function(a){var b=c.selection.getContent();if(/]+>[^<]+<\/a>$/.test(b)||-1===b.indexOf("href=")))return!1;if(a){var d,e=a.childNodes;if(0===e.length)return!1;for(d=e.length-1;d>=0;d--)if(3!=e[d].nodeType)return!1}return!0},mceRefresh:function(){var a,b=c.selection.getNode(),d=c.dom.getParent(b,"a[href]"),e=this.hasSelectedText(d);d?(a=d.innerText||d.textContent,h.url.val(c.dom.getAttrib(d,"href")),h.openInNewTab.prop("checked","_blank"===c.dom.getAttrib(d,"target")),h.submit.val(wpLinkL10n.update)):(a=c.selection.getContent({format:"text"}),this.setDefaultValues()),e?(h.text.val(a||""),h.wrap.addClass("has-text-field")):(h.text.val(""),h.wrap.removeClass("has-text-field"))},close:function(){a(document.body).removeClass("modal-open"),wpLink.isMCE()?c.focus():(wpLink.textarea.focus(),wpLink.range&&(wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select())),h.backdrop.hide(),h.wrap.hide(),g=!1,a(document).trigger("wplink-close",h.wrap)},getAttrs:function(){return wpLink.correctURL(),{href:a.trim(h.url.val()),target:h.openInNewTab.prop("checked")?"_blank":""}},buildHtml:function(a){var b='"},update:function(){wpLink.isMCE()?wpLink.mceUpdate():wpLink.htmlUpdate()},htmlUpdate:function(){var a,b,c,d,e,f,g,i=wpLink.textarea;i&&(a=wpLink.getAttrs(),b=h.text.val(),a.href&&(c=wpLink.buildHtml(a),document.selection&&wpLink.range?(i.focus(),wpLink.range.text=c+(b||wpLink.range.text)+"",wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select(),wpLink.range=null):"undefined"!=typeof i.selectionStart&&(d=i.selectionStart,e=i.selectionEnd,g=b||i.value.substring(d,e),c=c+g+"",f=d+c.length,d!==e||g||(f-=4),i.value=i.value.substring(0,d)+c+i.value.substring(e,i.value.length),i.selectionStart=i.selectionEnd=f),wpLink.close(),i.focus()))},mceUpdate:function(){var a,d,e=wpLink.getAttrs();return wpLink.close(),c.focus(),tinymce.isIE&&c.selection.moveToBookmark(c.windowManager.bookmark),e.href?(a=b(),h.wrap.hasClass("has-text-field")&&(d=h.text.val()||e.href),a?(d&&("innerText"in a?a.innerText=d:a.textContent=d),c.dom.setAttribs(a,e)):d?c.selection.setNode(c.dom.create("a",e,c.dom.encode(d))):c.execCommand("mceInsertLink",!1,e),void c.nodeChanged()):void c.execCommand("unlink")},updateFields:function(a,b){h.url.val(b.children(".item-permalink").val())},setDefaultValues:function(){var a,b=/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,d=/^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i;this.isMCE()?a=c.selection.getContent():document.selection&&wpLink.range?a=wpLink.range.text:"undefined"!=typeof this.textarea.selectionStart&&(a=this.textarea.value.substring(this.textarea.selectionStart,this.textarea.selectionEnd)),a&&b.test(a)?h.url.val("mailto:"+a):a&&d.test(a)?h.url.val(a.replace(/&|�?38;/gi,"&")):h.url.val(""),h.submit.val(wpLinkL10n.save)},searchInternalLinks:function(){var b,c=a(this),d=c.val();if(d.length>2){if(i.recent.hide(),i.search.show(),wpLink.lastSearch==d)return;wpLink.lastSearch=d,b=c.parent().find(".spinner").addClass("is-active"),i.search.change(d),i.search.ajax(function(){b.removeClass("is-active")})}else i.search.hide(),i.recent.show()},next:function(){i.search.next(),i.recent.next()},prev:function(){i.search.prev(),i.recent.prev()},keydown:function(a){var b,c;27===a.keyCode?(wpLink.close(),a.stopImmediatePropagation()):9===a.keyCode&&(c=a.target.id,"wp-link-submit"!==c||a.shiftKey?"wp-link-close"===c&&a.shiftKey&&(h.submit.focus(),a.preventDefault()):(h.close.focus(),a.preventDefault())),(38===a.keyCode||40===a.keyCode)&&(!document.activeElement||"link-title-field"!==document.activeElement.id&&"url-field"!==document.activeElement.id)&&(b=38===a.keyCode?"prev":"next",clearInterval(wpLink.keyInterval),wpLink[b](),wpLink.keyInterval=setInterval(wpLink[b],wpLink.keySensitivity),a.preventDefault())},keyup:function(a){(38===a.keyCode||40===a.keyCode)&&(clearInterval(wpLink.keyInterval),a.preventDefault())},delayedCallback:function(a,b){var c,d,e,f;return b?(setTimeout(function(){return d?a.apply(f,e):void(c=!0)},b),function(){return c?a.apply(this,arguments):(e=arguments,f=this,void(d=!0))}):a},toggleInternalLinking:function(a){var b=h.wrap.hasClass("search-panel-visible");h.wrap.toggleClass("search-panel-visible",!b),setUserSetting("wplink",b?"0":"1"),h[b?"url":"search"].focus(),a.preventDefault()}},e=function(b,c){var d=this;this.element=b,this.ul=b.children("ul"),this.contentHeight=b.children("#link-selector-height"),this.waiting=b.find(".river-waiting"),this.change(c),this.refresh(),a("#wp-link .query-results, #wp-link #link-selector").scroll(function(){d.maybeLoad()}),b.on("click","li",function(b){d.select(a(this),b)})},a.extend(e.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(a,b){var c,d,e,f;a.hasClass("unselectable")||a==this.selected||(this.deselect(),this.selected=a.addClass("selected"),c=a.outerHeight(),d=this.element.height(),e=a.position().top,f=this.element.scrollTop(),0>e?this.element.scrollTop(f+e):e+c>d&&this.element.scrollTop(f+e-d+c),this.element.trigger("river-select",[a,b,this]))},deselect:function(){this.selected&&this.selected.removeClass("selected"),this.selected=!1},prev:function(){if(this.visible){var a;this.selected&&(a=this.selected.prev("li"),a.length&&this.select(a))}},next:function(){if(this.visible){var b=this.selected?this.selected.next("li"):a("li:not(.unselectable):first",this.element);b.length&&this.select(b)}},ajax:function(a){var b=this,c=1==this.query.page?0:wpLink.minRiverAJAXDuration,d=wpLink.delayedCallback(function(c,d){b.process(c,d),a&&a(c,d)},c);this.query.ajax(d)},change:function(a){this.query&&this._search==a||(this._search=a,this.query=new f(a),this.element.scrollTop(0))},process:function(b,c){var d="",e=!0,f="",g=1==c.page;b?a.each(b,function(){f=e?"alternate":"",f+=this.title?"":" no-title",d+=f?'
  • ':"
  • ",d+='',d+='',d+=this.title?this.title:wpLinkL10n.noTitle,d+=''+this.info+"
  • ",e=!e}):g&&(d+='
  • '+wpLinkL10n.noMatchesFound+"
  • "),this.ul[g?"html":"append"](d)},maybeLoad:function(){var a=this,b=this.element,c=b.scrollTop()+b.height();!this.query.ready()||c]+>[^<]+<\/a>$/.test(b)||-1===b.indexOf("href=")))return!1;if(a){var d,e=a.childNodes;if(0===e.length)return!1;for(d=e.length-1;d>=0;d--)if(3!=e[d].nodeType)return!1}return!0},mceRefresh:function(){var a,b,d=c.selection.getNode(),e=c.dom.getParent(d,"a[href]"),f=this.hasSelectedText(e);e?(a=e.innerText||e.textContent,b=c.dom.getAttrib(e,"href"),"_wp_link_placeholder"===b&&(b=""),h.url.val(b),h.openInNewTab.prop("checked","_blank"===c.dom.getAttrib(e,"target")),h.submit.val(wpLinkL10n.update)):(a=c.selection.getContent({format:"text"}),this.setDefaultValues()),f?(h.text.val(a||""),h.wrap.addClass("has-text-field")):(h.text.val(""),h.wrap.removeClass("has-text-field"))},close:function(){var b;a(document.body).removeClass("modal-open"),wpLink.isMCE()?(b=c.dom.getParent(c.selection.getNode(),"a[href]"),b&&"_wp_link_placeholder"===c.dom.getAttrib(b,"href")&&c.dom.remove(b,!0),c.focus()):(wpLink.textarea.focus(),wpLink.range&&(wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select())),h.backdrop.hide(),h.wrap.hide(),g=!1,a(document).trigger("wplink-close",h.wrap)},getAttrs:function(){return wpLink.correctURL(),{href:a.trim(h.url.val()),target:h.openInNewTab.prop("checked")?"_blank":""}},buildHtml:function(a){var b='"},update:function(){wpLink.isMCE()?wpLink.mceUpdate():wpLink.htmlUpdate()},htmlUpdate:function(){var a,b,c,d,e,f,g,i=wpLink.textarea;i&&(a=wpLink.getAttrs(),b=h.text.val(),a.href&&(c=wpLink.buildHtml(a),document.selection&&wpLink.range?(i.focus(),wpLink.range.text=c+(b||wpLink.range.text)+"",wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select(),wpLink.range=null):"undefined"!=typeof i.selectionStart&&(d=i.selectionStart,e=i.selectionEnd,g=b||i.value.substring(d,e),c=c+g+"",f=d+c.length,d!==e||g||(f-=4),i.value=i.value.substring(0,d)+c+i.value.substring(e,i.value.length),i.selectionStart=i.selectionEnd=f),wpLink.close(),i.focus()))},mceUpdate:function(){var a,d,e=wpLink.getAttrs();return c.focus(),tinymce.isIE&&c.selection.moveToBookmark(c.windowManager.bookmark),e.href?(a=b(),h.wrap.hasClass("has-text-field")&&(d=h.text.val()||e.href),a?(d&&("innerText"in a?a.innerText=d:a.textContent=d),c.dom.setAttribs(a,e)):d?c.selection.setNode(c.dom.create("a",e,c.dom.encode(d))):c.execCommand("mceInsertLink",!1,e),wpLink.close(),void c.nodeChanged()):void c.execCommand("unlink")},updateFields:function(a,b){h.url.val(b.children(".item-permalink").val())},setDefaultValues:function(){var a,b=/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,d=/^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i;this.isMCE()?a=c.selection.getContent():document.selection&&wpLink.range?a=wpLink.range.text:"undefined"!=typeof this.textarea.selectionStart&&(a=this.textarea.value.substring(this.textarea.selectionStart,this.textarea.selectionEnd)),a&&b.test(a)?h.url.val("mailto:"+a):a&&d.test(a)?h.url.val(a.replace(/&|�?38;/gi,"&")):h.url.val(""),h.submit.val(wpLinkL10n.save)},searchInternalLinks:function(){var b,c=a(this),d=c.val();if(d.length>2){if(i.recent.hide(),i.search.show(),wpLink.lastSearch==d)return;wpLink.lastSearch=d,b=c.parent().find(".spinner").addClass("is-active"),i.search.change(d),i.search.ajax(function(){b.removeClass("is-active")})}else i.search.hide(),i.recent.show()},next:function(){i.search.next(),i.recent.next()},prev:function(){i.search.prev(),i.recent.prev()},keydown:function(a){var b,c;27===a.keyCode?(wpLink.close(),a.stopImmediatePropagation()):9===a.keyCode&&(c=a.target.id,"wp-link-submit"!==c||a.shiftKey?"wp-link-close"===c&&a.shiftKey&&(h.submit.focus(),a.preventDefault()):(h.close.focus(),a.preventDefault())),(38===a.keyCode||40===a.keyCode)&&(!document.activeElement||"link-title-field"!==document.activeElement.id&&"url-field"!==document.activeElement.id)&&(b=38===a.keyCode?"prev":"next",clearInterval(wpLink.keyInterval),wpLink[b](),wpLink.keyInterval=setInterval(wpLink[b],wpLink.keySensitivity),a.preventDefault())},keyup:function(a){(38===a.keyCode||40===a.keyCode)&&(clearInterval(wpLink.keyInterval),a.preventDefault())},delayedCallback:function(a,b){var c,d,e,f;return b?(setTimeout(function(){return d?a.apply(f,e):void(c=!0)},b),function(){return c?a.apply(this,arguments):(e=arguments,f=this,void(d=!0))}):a},toggleInternalLinking:function(a){var b=h.wrap.hasClass("search-panel-visible");h.wrap.toggleClass("search-panel-visible",!b),setUserSetting("wplink",b?"0":"1"),h[b?"url":"search"].focus(),a.preventDefault()}},e=function(b,c){var d=this;this.element=b,this.ul=b.children("ul"),this.contentHeight=b.children("#link-selector-height"),this.waiting=b.find(".river-waiting"),this.change(c),this.refresh(),a("#wp-link .query-results, #wp-link #link-selector").scroll(function(){d.maybeLoad()}),b.on("click","li",function(b){d.select(a(this),b)})},a.extend(e.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(a,b){var c,d,e,f;a.hasClass("unselectable")||a==this.selected||(this.deselect(),this.selected=a.addClass("selected"),c=a.outerHeight(),d=this.element.height(),e=a.position().top,f=this.element.scrollTop(),0>e?this.element.scrollTop(f+e):e+c>d&&this.element.scrollTop(f+e-d+c),this.element.trigger("river-select",[a,b,this]))},deselect:function(){this.selected&&this.selected.removeClass("selected"),this.selected=!1},prev:function(){if(this.visible){var a;this.selected&&(a=this.selected.prev("li"),a.length&&this.select(a))}},next:function(){if(this.visible){var b=this.selected?this.selected.next("li"):a("li:not(.unselectable):first",this.element);b.length&&this.select(b)}},ajax:function(a){var b=this,c=1==this.query.page?0:wpLink.minRiverAJAXDuration,d=wpLink.delayedCallback(function(c,d){b.process(c,d),a&&a(c,d)},c);this.query.ajax(d)},change:function(a){this.query&&this._search==a||(this._search=a,this.query=new f(a),this.element.scrollTop(0))},process:function(b,c){var d="",e=!0,f="",g=1==c.page;b?a.each(b,function(){f=e?"alternate":"",f+=this.title?"":" no-title",d+=f?'
  • ':"
  • ",d+='',d+='',d+=this.title?this.title:wpLinkL10n.noTitle,d+=''+this.info+"
  • ",e=!e}):g&&(d+='
  • '+wpLinkL10n.noMatchesFound+"
  • "),this.ul[g?"html":"append"](d)},maybeLoad:function(){var a=this,b=this.element,c=b.scrollTop()+b.height();!this.query.ready()||c