diff --git a/wp-includes/js/tinymce/plugins/wplink/plugin.js b/wp-includes/js/tinymce/plugins/wplink/plugin.js index 2314d835a9..890ebe86c2 100644 --- a/wp-includes/js/tinymce/plugins/wplink/plugin.js +++ b/wp-includes/js/tinymce/plugins/wplink/plugin.js @@ -226,15 +226,15 @@ linkNode = getSelectedLink(); editToolbar.tempHide = false; - if ( linkNode ) { - editor.dom.setAttribs( linkNode, { 'data-wplink-edit': true } ); - } else { + if ( ! linkNode ) { removePlaceholders(); editor.execCommand( 'mceInsertLink', false, { href: '_wp_link_placeholder' } ); linkNode = editor.$( 'a[href="_wp_link_placeholder"]' )[0]; editor.nodeChanged(); } + + editor.dom.setAttribs( linkNode, { 'data-wplink-edit': true } ); } ); editor.addCommand( 'wp_link_apply', function() { @@ -284,8 +284,9 @@ } ); editor.addCommand( 'wp_link_cancel', function() { + inputInstance.reset(); + if ( ! editToolbar.tempHide ) { - inputInstance.reset(); removePlaceholders(); } } ); @@ -583,24 +584,10 @@ var url = inputInstance.getURL() || null, text = inputInstance.getLinkText() || null; - /* - * Accessibility note: moving focus back to the editor confuses - * screen readers. They will announce again the Editor ARIA role - * `application` and the iframe `title` attribute. - * - * Unfortunately IE looses the selection when the editor iframe - * looses focus, so without returning focus to the editor, the code - * in the modal will not be able to get the selection, place the caret - * at the same location, etc. - */ - if ( tinymce.Env.ie ) { - editor.focus(); // Needed for IE - } + window.wpLink.open( editor.id, url, text ); editToolbar.tempHide = true; - window.wpLink.open( editor.id, url, text, linkNode ); - - inputInstance.reset(); + editToolbar.hide(); } } } ); diff --git a/wp-includes/js/tinymce/plugins/wplink/plugin.min.js b/wp-includes/js/tinymce/plugins/wplink/plugin.min.js index bcf2cce439..629f27fbf1 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.Factory.add("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\.)?/,""),(c=b.indexOf("?"))!==-1&&(b=b.slice(0,c)),(c=b.indexOf("#"))!==-1&&(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&&(c=b.indexOf("/"))!==-1&&(d=b.lastIndexOf("/"))!==-1&&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.Factory.add("WPLinkInput",a.ui.Control.extend({renderHtml:function(){return''},setURL:function(a){this.getEl().firstChild.value=a},getURL:function(){return a.trim(this.getEl().firstChild.value)},getLinkText:function(){var b=this.getEl().firstChild.nextSibling.value;return a.trim(b)?b.replace(/[\r\n\t ]+/g," "):""},reset:function(){var a=this.getEl().firstChild;a.value="",a.nextSibling.value=""}})),a.PluginManager.add("wplink",function(b){function c(){var a,c,d=b.selection.getStart(),e=b.dom.getParent(d,"a[href]");return e||(c=b.selection.getContent({format:"raw"}),c&&c.indexOf("")!==-1&&(a=c.match(/href="([^">]+)"/),a&&a[1]&&(e=b.$('a[href="'+a[1]+'"]',d)[0]),e&&b.selection.select(e))),e}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-wplink-edit")&&d.attr("data-wplink-edit",null)})}function e(a,b){return a.replace(/(]+>)([\s\S]*?)<\/a>/g,function(a,c,d){return c.indexOf(' href="_wp_link_placeholder"')>-1?d:(b&&(c=c.replace(/ data-wplink-edit="true"/g,"")),c=c.replace(/ data-wplink-url-error="true"/g,""),c+d+"")})}function f(a){var c=b.$(a),d=c.attr("href");d&&"undefined"!=typeof n&&(s=!1,!/^http/i.test(d)||p.test(d)&&q.test(d)?c.removeAttr("data-wplink-url-error"):(s=!0,c.attr("data-wplink-url-error","true"),r(b.translate("Warning: the link has been inserted but may have errors. Please test it."),"assertive")))}var g,h,i,j,k,l,m,n=window.jQuery,o=/^(mailto:)?[a-z0-9._%+-]+@[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}$/i,p=/^https?:\/\/([^\s\/?.#-][^\s\/?.#]*\.?)+(\/[^\s"]*)?$/i,q=/^https?:\/\/[^\/]+\.[^\/]+($|\/)/i,r="undefined"!=typeof window.wp&&window.wp.a11y&&window.wp.a11y.speak?window.wp.a11y.speak:function(){},s=!1;return b.on("preinit",function(){if(b.wp&&b.wp._createToolbar){g=b.wp._createToolbar(["wp_link_preview","wp_link_edit","wp_link_remove"],!0);var a=["wp_link_input","wp_link_apply"];"undefined"!=typeof window.wpLink&&a.push("wp_link_advanced"),h=b.wp._createToolbar(a,!0),h.on("show",function(){"undefined"!=typeof window.wpLink&&window.wpLink.modalOpen||window.setTimeout(function(){var a=h.$el.find("input.ui-autocomplete-input")[0],b=k&&(k.textContent||k.innerText);a&&(!a.value&&b&&"undefined"!=typeof window.wpLink&&(a.value=window.wpLink.getUrlFromSelection(b)),l||(a.focus(),a.select()))})}),h.on("hide",function(){h.scrolling||b.execCommand("wp_link_cancel")})}}),b.addCommand("WP_Link",function(){return a.Env.ie&&a.Env.ie<10&&"undefined"!=typeof window.wpLink?void window.wpLink.open(b.id):(k=c(),h.tempHide=!1,void(k?b.dom.setAttribs(k,{"data-wplink-edit":!0}):(d(),b.execCommand("mceInsertLink",!1,{href:"_wp_link_placeholder"}),k=b.$('a[href="_wp_link_placeholder"]')[0],b.nodeChanged())))}),b.addCommand("wp_link_apply",function(){if(!h.scrolling){var c,d;if(k){c=j.getURL(),d=j.getLinkText(),b.focus();var e=document.createElement("a");if(e.href=c,"javascript:"!==e.protocol&&"data:"!==e.protocol||(c=""),!c)return void b.dom.remove(k,!0);/^(?:[a-z]+:|#|\?|\.|\/)/.test(c)||o.test(c)||(c="http://"+c),b.dom.setAttribs(k,{href:c,"data-wplink-edit":null}),a.trim(k.innerHTML)||b.$(k).text(d||c),f(k)}j.reset(),b.nodeChanged(),"undefined"==typeof window.wpLinkL10n||s||r(window.wpLinkL10n.linkInserted)}}),b.addCommand("wp_link_cancel",function(){h.tempHide||(j.reset(),d())}),b.addCommand("wp_unlink",function(){b.execCommand("unlink"),h.tempHide=!1,b.execCommand("wp_link_cancel")}),b.addShortcut("access+a","","WP_Link"),b.addShortcut("access+s","","wp_unlink"),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.lastLevel&&a.lastLevel.content&&a.level.content&&a.lastLevel.content===e(a.level.content)&&a.preventDefault()}),b.on("keydown",function(c){27===c.keyCode&&b.execCommand("wp_link_cancel"),c.altKey||a.Env.mac&&(!c.metaKey||c.ctrlKey)||!a.Env.mac&&!c.ctrlKey||89!==c.keyCode&&90!==c.keyCode||(l=!0,window.clearTimeout(m),m=window.setTimeout(function(){l=!1},500))}),b.addButton("wp_link_preview",{type:"WPLinkPreview",onPostRender:function(){i=this}}),b.addButton("wp_link_input",{type:"WPLinkInput",onPostRender:function(){var c,d,e,f=this.getEl(),g=f.firstChild;j=this,n&&n.ui&&n.ui.autocomplete&&(c=n(g),c.on("keydown",function(){c.removeAttr("aria-activedescendant")}).autocomplete({source:function(a,b){return e===a.term?void b(d):/^https?:/.test(a.term)||a.term.indexOf(".")!==-1?b():(n.post(window.ajaxurl,{action:"wp-link-ajax",page:1,search:a.term,_ajax_linking_nonce:n("#_ajax_linking_nonce").val()},function(a){d=a,b(a)},"json"),void(e=a.term))},focus:function(a,b){c.attr("aria-activedescendant","mce-wp-autocomplete-"+b.item.ID),a.preventDefault()},select:function(a,b){return c.val(b.item.permalink),n(f.firstChild.nextSibling).val(b.item.title),9===a.keyCode&&"undefined"!=typeof window.wpLinkL10n&&r(window.wpLinkL10n.linkSelected),!1},open:function(){c.attr("aria-expanded","true"),h.blockHide=!0},close:function(){c.attr("aria-expanded","false"),h.blockHide=!1},minLength:2,position:{my:"left top+2"},messages:{noResults:"undefined"!=typeof window.uiAutocompleteL10n?window.uiAutocompleteL10n.noResults:"",results:function(a){if("undefined"!=typeof window.uiAutocompleteL10n)return a>1?window.uiAutocompleteL10n.manyResults.replace("%d",a):window.uiAutocompleteL10n.oneResult}}}).autocomplete("instance")._renderItem=function(a,b){var c="undefined"!=typeof window.wpLinkL10n?window.wpLinkL10n.noTitle:"",d=b.title?b.title:c;return n('
  • ').append(""+d+' '+b.info+"").appendTo(a)},c.attr({role:"combobox","aria-autocomplete":"list","aria-expanded":"false","aria-owns":c.autocomplete("widget").attr("id")}).on("focus",function(){var a=c.val();a&&!/^https?:/.test(a)&&c.autocomplete("search")}).autocomplete("widget").addClass("wplink-autocomplete").attr("role","listbox").removeAttr("tabindex").on("menufocus",function(a,b){b.item.attr("aria-selected","true")}).on("menublur",function(){n(this).find('[aria-selected="true"]').removeAttr("aria-selected")})),a.$(g).on("keydown",function(a){13===a.keyCode&&(b.execCommand("wp_link_apply"),a.preventDefault())})}}),b.on("wptoolbar",function(a){var c,d,e,f=b.dom.getParent(a.element,"a");return"undefined"!=typeof window.wpLink&&window.wpLink.modalOpen?void(h.tempHide=!0):(h.tempHide=!1,void(f?(c=b.$(f),d=c.attr("href"),e=c.attr("data-wplink-edit"),"_wp_link_placeholder"===d||e?("_wp_link_placeholder"===d||j.getURL()||j.setURL(d),a.element=f,a.toolbar=h):d&&!c.find("img").length&&(i.setURL(d),a.element=f,a.toolbar=g,"true"===c.attr("data-wplink-url-error")?g.$el.find(".wp-link-preview a").addClass("wplink-url-error"):(g.$el.find(".wp-link-preview a").removeClass("wplink-url-error"),s=!1))):h.visible()&&b.execCommand("wp_link_cancel")))}),b.addButton("wp_link_edit",{tooltip:"Edit|button",icon:"dashicon dashicons-edit",cmd:"WP_Link"}),b.addButton("wp_link_remove",{tooltip:"Remove link",icon:"dashicon dashicons-editor-unlink",cmd:"wp_unlink"}),b.addButton("wp_link_advanced",{tooltip:"Link options",icon:"dashicon dashicons-admin-generic",onclick:function(){if("undefined"!=typeof window.wpLink){var c=j.getURL()||null,d=j.getLinkText()||null;a.Env.ie&&b.focus(),h.tempHide=!0,window.wpLink.open(b.id,c,d,k),j.reset()}}}),b.addButton("wp_link_apply",{tooltip:"Apply",icon:"dashicon dashicons-editor-break",cmd:"wp_link_apply",classes:"widget btn primary"}),{close:function(){h.tempHide=!1,b.execCommand("wp_link_cancel")},checkLink:f}})}(window.tinymce); \ No newline at end of file +!function(a){a.ui.Factory.add("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\.)?/,""),(c=b.indexOf("?"))!==-1&&(b=b.slice(0,c)),(c=b.indexOf("#"))!==-1&&(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&&(c=b.indexOf("/"))!==-1&&(d=b.lastIndexOf("/"))!==-1&&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.Factory.add("WPLinkInput",a.ui.Control.extend({renderHtml:function(){return''},setURL:function(a){this.getEl().firstChild.value=a},getURL:function(){return a.trim(this.getEl().firstChild.value)},getLinkText:function(){var b=this.getEl().firstChild.nextSibling.value;return a.trim(b)?b.replace(/[\r\n\t ]+/g," "):""},reset:function(){var a=this.getEl().firstChild;a.value="",a.nextSibling.value=""}})),a.PluginManager.add("wplink",function(b){function c(){var a,c,d=b.selection.getStart(),e=b.dom.getParent(d,"a[href]");return e||(c=b.selection.getContent({format:"raw"}),c&&c.indexOf("")!==-1&&(a=c.match(/href="([^">]+)"/),a&&a[1]&&(e=b.$('a[href="'+a[1]+'"]',d)[0]),e&&b.selection.select(e))),e}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-wplink-edit")&&d.attr("data-wplink-edit",null)})}function e(a,b){return a.replace(/(]+>)([\s\S]*?)<\/a>/g,function(a,c,d){return c.indexOf(' href="_wp_link_placeholder"')>-1?d:(b&&(c=c.replace(/ data-wplink-edit="true"/g,"")),c=c.replace(/ data-wplink-url-error="true"/g,""),c+d+"")})}function f(a){var c=b.$(a),d=c.attr("href");d&&"undefined"!=typeof n&&(s=!1,!/^http/i.test(d)||p.test(d)&&q.test(d)?c.removeAttr("data-wplink-url-error"):(s=!0,c.attr("data-wplink-url-error","true"),r(b.translate("Warning: the link has been inserted but may have errors. Please test it."),"assertive")))}var g,h,i,j,k,l,m,n=window.jQuery,o=/^(mailto:)?[a-z0-9._%+-]+@[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}$/i,p=/^https?:\/\/([^\s\/?.#-][^\s\/?.#]*\.?)+(\/[^\s"]*)?$/i,q=/^https?:\/\/[^\/]+\.[^\/]+($|\/)/i,r="undefined"!=typeof window.wp&&window.wp.a11y&&window.wp.a11y.speak?window.wp.a11y.speak:function(){},s=!1;return b.on("preinit",function(){if(b.wp&&b.wp._createToolbar){g=b.wp._createToolbar(["wp_link_preview","wp_link_edit","wp_link_remove"],!0);var a=["wp_link_input","wp_link_apply"];"undefined"!=typeof window.wpLink&&a.push("wp_link_advanced"),h=b.wp._createToolbar(a,!0),h.on("show",function(){"undefined"!=typeof window.wpLink&&window.wpLink.modalOpen||window.setTimeout(function(){var a=h.$el.find("input.ui-autocomplete-input")[0],b=k&&(k.textContent||k.innerText);a&&(!a.value&&b&&"undefined"!=typeof window.wpLink&&(a.value=window.wpLink.getUrlFromSelection(b)),l||(a.focus(),a.select()))})}),h.on("hide",function(){h.scrolling||b.execCommand("wp_link_cancel")})}}),b.addCommand("WP_Link",function(){return a.Env.ie&&a.Env.ie<10&&"undefined"!=typeof window.wpLink?void window.wpLink.open(b.id):(k=c(),h.tempHide=!1,k||(d(),b.execCommand("mceInsertLink",!1,{href:"_wp_link_placeholder"}),k=b.$('a[href="_wp_link_placeholder"]')[0],b.nodeChanged()),void b.dom.setAttribs(k,{"data-wplink-edit":!0}))}),b.addCommand("wp_link_apply",function(){if(!h.scrolling){var c,d;if(k){c=j.getURL(),d=j.getLinkText(),b.focus();var e=document.createElement("a");if(e.href=c,"javascript:"!==e.protocol&&"data:"!==e.protocol||(c=""),!c)return void b.dom.remove(k,!0);/^(?:[a-z]+:|#|\?|\.|\/)/.test(c)||o.test(c)||(c="http://"+c),b.dom.setAttribs(k,{href:c,"data-wplink-edit":null}),a.trim(k.innerHTML)||b.$(k).text(d||c),f(k)}j.reset(),b.nodeChanged(),"undefined"==typeof window.wpLinkL10n||s||r(window.wpLinkL10n.linkInserted)}}),b.addCommand("wp_link_cancel",function(){j.reset(),h.tempHide||d()}),b.addCommand("wp_unlink",function(){b.execCommand("unlink"),h.tempHide=!1,b.execCommand("wp_link_cancel")}),b.addShortcut("access+a","","WP_Link"),b.addShortcut("access+s","","wp_unlink"),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.lastLevel&&a.lastLevel.content&&a.level.content&&a.lastLevel.content===e(a.level.content)&&a.preventDefault()}),b.on("keydown",function(c){27===c.keyCode&&b.execCommand("wp_link_cancel"),c.altKey||a.Env.mac&&(!c.metaKey||c.ctrlKey)||!a.Env.mac&&!c.ctrlKey||89!==c.keyCode&&90!==c.keyCode||(l=!0,window.clearTimeout(m),m=window.setTimeout(function(){l=!1},500))}),b.addButton("wp_link_preview",{type:"WPLinkPreview",onPostRender:function(){i=this}}),b.addButton("wp_link_input",{type:"WPLinkInput",onPostRender:function(){var c,d,e,f=this.getEl(),g=f.firstChild;j=this,n&&n.ui&&n.ui.autocomplete&&(c=n(g),c.on("keydown",function(){c.removeAttr("aria-activedescendant")}).autocomplete({source:function(a,b){return e===a.term?void b(d):/^https?:/.test(a.term)||a.term.indexOf(".")!==-1?b():(n.post(window.ajaxurl,{action:"wp-link-ajax",page:1,search:a.term,_ajax_linking_nonce:n("#_ajax_linking_nonce").val()},function(a){d=a,b(a)},"json"),void(e=a.term))},focus:function(a,b){c.attr("aria-activedescendant","mce-wp-autocomplete-"+b.item.ID),a.preventDefault()},select:function(a,b){return c.val(b.item.permalink),n(f.firstChild.nextSibling).val(b.item.title),9===a.keyCode&&"undefined"!=typeof window.wpLinkL10n&&r(window.wpLinkL10n.linkSelected),!1},open:function(){c.attr("aria-expanded","true"),h.blockHide=!0},close:function(){c.attr("aria-expanded","false"),h.blockHide=!1},minLength:2,position:{my:"left top+2"},messages:{noResults:"undefined"!=typeof window.uiAutocompleteL10n?window.uiAutocompleteL10n.noResults:"",results:function(a){if("undefined"!=typeof window.uiAutocompleteL10n)return a>1?window.uiAutocompleteL10n.manyResults.replace("%d",a):window.uiAutocompleteL10n.oneResult}}}).autocomplete("instance")._renderItem=function(a,b){var c="undefined"!=typeof window.wpLinkL10n?window.wpLinkL10n.noTitle:"",d=b.title?b.title:c;return n('
  • ').append(""+d+' '+b.info+"").appendTo(a)},c.attr({role:"combobox","aria-autocomplete":"list","aria-expanded":"false","aria-owns":c.autocomplete("widget").attr("id")}).on("focus",function(){var a=c.val();a&&!/^https?:/.test(a)&&c.autocomplete("search")}).autocomplete("widget").addClass("wplink-autocomplete").attr("role","listbox").removeAttr("tabindex").on("menufocus",function(a,b){b.item.attr("aria-selected","true")}).on("menublur",function(){n(this).find('[aria-selected="true"]').removeAttr("aria-selected")})),a.$(g).on("keydown",function(a){13===a.keyCode&&(b.execCommand("wp_link_apply"),a.preventDefault())})}}),b.on("wptoolbar",function(a){var c,d,e,f=b.dom.getParent(a.element,"a");return"undefined"!=typeof window.wpLink&&window.wpLink.modalOpen?void(h.tempHide=!0):(h.tempHide=!1,void(f?(c=b.$(f),d=c.attr("href"),e=c.attr("data-wplink-edit"),"_wp_link_placeholder"===d||e?("_wp_link_placeholder"===d||j.getURL()||j.setURL(d),a.element=f,a.toolbar=h):d&&!c.find("img").length&&(i.setURL(d),a.element=f,a.toolbar=g,"true"===c.attr("data-wplink-url-error")?g.$el.find(".wp-link-preview a").addClass("wplink-url-error"):(g.$el.find(".wp-link-preview a").removeClass("wplink-url-error"),s=!1))):h.visible()&&b.execCommand("wp_link_cancel")))}),b.addButton("wp_link_edit",{tooltip:"Edit|button",icon:"dashicon dashicons-edit",cmd:"WP_Link"}),b.addButton("wp_link_remove",{tooltip:"Remove link",icon:"dashicon dashicons-editor-unlink",cmd:"wp_unlink"}),b.addButton("wp_link_advanced",{tooltip:"Link options",icon:"dashicon dashicons-admin-generic",onclick:function(){if("undefined"!=typeof window.wpLink){var a=j.getURL()||null,c=j.getLinkText()||null;window.wpLink.open(b.id,a,c),h.tempHide=!0,h.hide()}}}),b.addButton("wp_link_apply",{tooltip:"Apply",icon:"dashicon dashicons-editor-break",cmd:"wp_link_apply",classes:"widget btn primary"}),{close:function(){h.tempHide=!1,b.execCommand("wp_link_cancel")},checkLink:f}})}(window.tinymce); \ No newline at end of file diff --git a/wp-includes/js/tinymce/wp-tinymce.js b/wp-includes/js/tinymce/wp-tinymce.js index 14b7bcc814..9915b30745 100644 --- a/wp-includes/js/tinymce/wp-tinymce.js +++ b/wp-includes/js/tinymce/wp-tinymce.js @@ -42,7 +42,7 @@ tinymce.PluginManager.add("wpeditimage",function(a){function b(b){return!(!a.dom // Source: wp-includes/js/tinymce/plugins/wpgallery/plugin.min.js tinymce.PluginManager.add("wpgallery",function(a){function b(a){return a.replace(/\[gallery([^\]]*)\]/g,function(a){return c("wp-gallery",a)})}function c(a,b){return b=window.encodeURIComponent(b),''}function d(a){function b(a,b){return b=new RegExp(b+'="([^"]+)"').exec(a),b?window.decodeURIComponent(b[1]):""}return a.replace(/(?:]+)?>)*(]+>)(?:<\/p>)*/g,function(a,c){var d=b(c,"data-wp-media");return d?"

    "+d+"

    ":a})}function e(b){var c,d,e;"IMG"===b.nodeName&&"undefined"!=typeof wp&&wp.media&&(e=window.decodeURIComponent(a.dom.getAttrib(b,"data-wp-media")),a.dom.hasClass(b,"wp-gallery")&&wp.media.gallery&&(c=wp.media.gallery,d=c.edit(e),d.state("gallery-edit").on("update",function(e){var f=c.shortcode(e).string();a.dom.setAttrib(b,"data-wp-media",window.encodeURIComponent(f)),d.detach()})))}a.addCommand("WP_Gallery",function(){e(a.selection.getNode())}),a.on("mouseup",function(b){function c(){d.removeClass(d.select("img.wp-media-selected"),"wp-media-selected")}var d=a.dom,f=b.target;"IMG"===f.nodeName&&d.getAttrib(f,"data-wp-media")?2!==b.button&&(d.hasClass(f,"wp-media-selected")?e(f):(c(),d.addClass(f,"wp-media-selected"))):c()}),a.on("ResolveName",function(b){var c=a.dom,d=b.target;"IMG"===d.nodeName&&c.getAttrib(d,"data-wp-media")&&c.hasClass(d,"wp-gallery")&&(b.name="gallery")}),a.on("BeforeSetContent",function(c){a.plugins.wpview&&"undefined"!=typeof wp&&wp.mce||(c.content=b(c.content))}),a.on("PostProcess",function(a){a.get&&(a.content=d(a.content))})}); // Source: wp-includes/js/tinymce/plugins/wplink/plugin.min.js -!function(a){a.ui.Factory.add("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\.)?/,""),(c=b.indexOf("?"))!==-1&&(b=b.slice(0,c)),(c=b.indexOf("#"))!==-1&&(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&&(c=b.indexOf("/"))!==-1&&(d=b.lastIndexOf("/"))!==-1&&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.Factory.add("WPLinkInput",a.ui.Control.extend({renderHtml:function(){return''},setURL:function(a){this.getEl().firstChild.value=a},getURL:function(){return a.trim(this.getEl().firstChild.value)},getLinkText:function(){var b=this.getEl().firstChild.nextSibling.value;return a.trim(b)?b.replace(/[\r\n\t ]+/g," "):""},reset:function(){var a=this.getEl().firstChild;a.value="",a.nextSibling.value=""}})),a.PluginManager.add("wplink",function(b){function c(){var a,c,d=b.selection.getStart(),e=b.dom.getParent(d,"a[href]");return e||(c=b.selection.getContent({format:"raw"}),c&&c.indexOf("")!==-1&&(a=c.match(/href="([^">]+)"/),a&&a[1]&&(e=b.$('a[href="'+a[1]+'"]',d)[0]),e&&b.selection.select(e))),e}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-wplink-edit")&&d.attr("data-wplink-edit",null)})}function e(a,b){return a.replace(/(]+>)([\s\S]*?)<\/a>/g,function(a,c,d){return c.indexOf(' href="_wp_link_placeholder"')>-1?d:(b&&(c=c.replace(/ data-wplink-edit="true"/g,"")),c=c.replace(/ data-wplink-url-error="true"/g,""),c+d+"")})}function f(a){var c=b.$(a),d=c.attr("href");d&&"undefined"!=typeof n&&(s=!1,!/^http/i.test(d)||p.test(d)&&q.test(d)?c.removeAttr("data-wplink-url-error"):(s=!0,c.attr("data-wplink-url-error","true"),r(b.translate("Warning: the link has been inserted but may have errors. Please test it."),"assertive")))}var g,h,i,j,k,l,m,n=window.jQuery,o=/^(mailto:)?[a-z0-9._%+-]+@[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}$/i,p=/^https?:\/\/([^\s\/?.#-][^\s\/?.#]*\.?)+(\/[^\s"]*)?$/i,q=/^https?:\/\/[^\/]+\.[^\/]+($|\/)/i,r="undefined"!=typeof window.wp&&window.wp.a11y&&window.wp.a11y.speak?window.wp.a11y.speak:function(){},s=!1;return b.on("preinit",function(){if(b.wp&&b.wp._createToolbar){g=b.wp._createToolbar(["wp_link_preview","wp_link_edit","wp_link_remove"],!0);var a=["wp_link_input","wp_link_apply"];"undefined"!=typeof window.wpLink&&a.push("wp_link_advanced"),h=b.wp._createToolbar(a,!0),h.on("show",function(){"undefined"!=typeof window.wpLink&&window.wpLink.modalOpen||window.setTimeout(function(){var a=h.$el.find("input.ui-autocomplete-input")[0],b=k&&(k.textContent||k.innerText);a&&(!a.value&&b&&"undefined"!=typeof window.wpLink&&(a.value=window.wpLink.getUrlFromSelection(b)),l||(a.focus(),a.select()))})}),h.on("hide",function(){h.scrolling||b.execCommand("wp_link_cancel")})}}),b.addCommand("WP_Link",function(){return a.Env.ie&&a.Env.ie<10&&"undefined"!=typeof window.wpLink?void window.wpLink.open(b.id):(k=c(),h.tempHide=!1,void(k?b.dom.setAttribs(k,{"data-wplink-edit":!0}):(d(),b.execCommand("mceInsertLink",!1,{href:"_wp_link_placeholder"}),k=b.$('a[href="_wp_link_placeholder"]')[0],b.nodeChanged())))}),b.addCommand("wp_link_apply",function(){if(!h.scrolling){var c,d;if(k){c=j.getURL(),d=j.getLinkText(),b.focus();var e=document.createElement("a");if(e.href=c,"javascript:"!==e.protocol&&"data:"!==e.protocol||(c=""),!c)return void b.dom.remove(k,!0);/^(?:[a-z]+:|#|\?|\.|\/)/.test(c)||o.test(c)||(c="http://"+c),b.dom.setAttribs(k,{href:c,"data-wplink-edit":null}),a.trim(k.innerHTML)||b.$(k).text(d||c),f(k)}j.reset(),b.nodeChanged(),"undefined"==typeof window.wpLinkL10n||s||r(window.wpLinkL10n.linkInserted)}}),b.addCommand("wp_link_cancel",function(){h.tempHide||(j.reset(),d())}),b.addCommand("wp_unlink",function(){b.execCommand("unlink"),h.tempHide=!1,b.execCommand("wp_link_cancel")}),b.addShortcut("access+a","","WP_Link"),b.addShortcut("access+s","","wp_unlink"),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.lastLevel&&a.lastLevel.content&&a.level.content&&a.lastLevel.content===e(a.level.content)&&a.preventDefault()}),b.on("keydown",function(c){27===c.keyCode&&b.execCommand("wp_link_cancel"),c.altKey||a.Env.mac&&(!c.metaKey||c.ctrlKey)||!a.Env.mac&&!c.ctrlKey||89!==c.keyCode&&90!==c.keyCode||(l=!0,window.clearTimeout(m),m=window.setTimeout(function(){l=!1},500))}),b.addButton("wp_link_preview",{type:"WPLinkPreview",onPostRender:function(){i=this}}),b.addButton("wp_link_input",{type:"WPLinkInput",onPostRender:function(){var c,d,e,f=this.getEl(),g=f.firstChild;j=this,n&&n.ui&&n.ui.autocomplete&&(c=n(g),c.on("keydown",function(){c.removeAttr("aria-activedescendant")}).autocomplete({source:function(a,b){return e===a.term?void b(d):/^https?:/.test(a.term)||a.term.indexOf(".")!==-1?b():(n.post(window.ajaxurl,{action:"wp-link-ajax",page:1,search:a.term,_ajax_linking_nonce:n("#_ajax_linking_nonce").val()},function(a){d=a,b(a)},"json"),void(e=a.term))},focus:function(a,b){c.attr("aria-activedescendant","mce-wp-autocomplete-"+b.item.ID),a.preventDefault()},select:function(a,b){return c.val(b.item.permalink),n(f.firstChild.nextSibling).val(b.item.title),9===a.keyCode&&"undefined"!=typeof window.wpLinkL10n&&r(window.wpLinkL10n.linkSelected),!1},open:function(){c.attr("aria-expanded","true"),h.blockHide=!0},close:function(){c.attr("aria-expanded","false"),h.blockHide=!1},minLength:2,position:{my:"left top+2"},messages:{noResults:"undefined"!=typeof window.uiAutocompleteL10n?window.uiAutocompleteL10n.noResults:"",results:function(a){if("undefined"!=typeof window.uiAutocompleteL10n)return a>1?window.uiAutocompleteL10n.manyResults.replace("%d",a):window.uiAutocompleteL10n.oneResult}}}).autocomplete("instance")._renderItem=function(a,b){var c="undefined"!=typeof window.wpLinkL10n?window.wpLinkL10n.noTitle:"",d=b.title?b.title:c;return n('
  • ').append(""+d+' '+b.info+"").appendTo(a)},c.attr({role:"combobox","aria-autocomplete":"list","aria-expanded":"false","aria-owns":c.autocomplete("widget").attr("id")}).on("focus",function(){var a=c.val();a&&!/^https?:/.test(a)&&c.autocomplete("search")}).autocomplete("widget").addClass("wplink-autocomplete").attr("role","listbox").removeAttr("tabindex").on("menufocus",function(a,b){b.item.attr("aria-selected","true")}).on("menublur",function(){n(this).find('[aria-selected="true"]').removeAttr("aria-selected")})),a.$(g).on("keydown",function(a){13===a.keyCode&&(b.execCommand("wp_link_apply"),a.preventDefault())})}}),b.on("wptoolbar",function(a){var c,d,e,f=b.dom.getParent(a.element,"a");return"undefined"!=typeof window.wpLink&&window.wpLink.modalOpen?void(h.tempHide=!0):(h.tempHide=!1,void(f?(c=b.$(f),d=c.attr("href"),e=c.attr("data-wplink-edit"),"_wp_link_placeholder"===d||e?("_wp_link_placeholder"===d||j.getURL()||j.setURL(d),a.element=f,a.toolbar=h):d&&!c.find("img").length&&(i.setURL(d),a.element=f,a.toolbar=g,"true"===c.attr("data-wplink-url-error")?g.$el.find(".wp-link-preview a").addClass("wplink-url-error"):(g.$el.find(".wp-link-preview a").removeClass("wplink-url-error"),s=!1))):h.visible()&&b.execCommand("wp_link_cancel")))}),b.addButton("wp_link_edit",{tooltip:"Edit|button",icon:"dashicon dashicons-edit",cmd:"WP_Link"}),b.addButton("wp_link_remove",{tooltip:"Remove link",icon:"dashicon dashicons-editor-unlink",cmd:"wp_unlink"}),b.addButton("wp_link_advanced",{tooltip:"Link options",icon:"dashicon dashicons-admin-generic",onclick:function(){if("undefined"!=typeof window.wpLink){var c=j.getURL()||null,d=j.getLinkText()||null;a.Env.ie&&b.focus(),h.tempHide=!0,window.wpLink.open(b.id,c,d,k),j.reset()}}}),b.addButton("wp_link_apply",{tooltip:"Apply",icon:"dashicon dashicons-editor-break",cmd:"wp_link_apply",classes:"widget btn primary"}),{close:function(){h.tempHide=!1,b.execCommand("wp_link_cancel")},checkLink:f}})}(window.tinymce); +!function(a){a.ui.Factory.add("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\.)?/,""),(c=b.indexOf("?"))!==-1&&(b=b.slice(0,c)),(c=b.indexOf("#"))!==-1&&(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&&(c=b.indexOf("/"))!==-1&&(d=b.lastIndexOf("/"))!==-1&&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.Factory.add("WPLinkInput",a.ui.Control.extend({renderHtml:function(){return''},setURL:function(a){this.getEl().firstChild.value=a},getURL:function(){return a.trim(this.getEl().firstChild.value)},getLinkText:function(){var b=this.getEl().firstChild.nextSibling.value;return a.trim(b)?b.replace(/[\r\n\t ]+/g," "):""},reset:function(){var a=this.getEl().firstChild;a.value="",a.nextSibling.value=""}})),a.PluginManager.add("wplink",function(b){function c(){var a,c,d=b.selection.getStart(),e=b.dom.getParent(d,"a[href]");return e||(c=b.selection.getContent({format:"raw"}),c&&c.indexOf("")!==-1&&(a=c.match(/href="([^">]+)"/),a&&a[1]&&(e=b.$('a[href="'+a[1]+'"]',d)[0]),e&&b.selection.select(e))),e}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-wplink-edit")&&d.attr("data-wplink-edit",null)})}function e(a,b){return a.replace(/(]+>)([\s\S]*?)<\/a>/g,function(a,c,d){return c.indexOf(' href="_wp_link_placeholder"')>-1?d:(b&&(c=c.replace(/ data-wplink-edit="true"/g,"")),c=c.replace(/ data-wplink-url-error="true"/g,""),c+d+"")})}function f(a){var c=b.$(a),d=c.attr("href");d&&"undefined"!=typeof n&&(s=!1,!/^http/i.test(d)||p.test(d)&&q.test(d)?c.removeAttr("data-wplink-url-error"):(s=!0,c.attr("data-wplink-url-error","true"),r(b.translate("Warning: the link has been inserted but may have errors. Please test it."),"assertive")))}var g,h,i,j,k,l,m,n=window.jQuery,o=/^(mailto:)?[a-z0-9._%+-]+@[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}$/i,p=/^https?:\/\/([^\s\/?.#-][^\s\/?.#]*\.?)+(\/[^\s"]*)?$/i,q=/^https?:\/\/[^\/]+\.[^\/]+($|\/)/i,r="undefined"!=typeof window.wp&&window.wp.a11y&&window.wp.a11y.speak?window.wp.a11y.speak:function(){},s=!1;return b.on("preinit",function(){if(b.wp&&b.wp._createToolbar){g=b.wp._createToolbar(["wp_link_preview","wp_link_edit","wp_link_remove"],!0);var a=["wp_link_input","wp_link_apply"];"undefined"!=typeof window.wpLink&&a.push("wp_link_advanced"),h=b.wp._createToolbar(a,!0),h.on("show",function(){"undefined"!=typeof window.wpLink&&window.wpLink.modalOpen||window.setTimeout(function(){var a=h.$el.find("input.ui-autocomplete-input")[0],b=k&&(k.textContent||k.innerText);a&&(!a.value&&b&&"undefined"!=typeof window.wpLink&&(a.value=window.wpLink.getUrlFromSelection(b)),l||(a.focus(),a.select()))})}),h.on("hide",function(){h.scrolling||b.execCommand("wp_link_cancel")})}}),b.addCommand("WP_Link",function(){return a.Env.ie&&a.Env.ie<10&&"undefined"!=typeof window.wpLink?void window.wpLink.open(b.id):(k=c(),h.tempHide=!1,k||(d(),b.execCommand("mceInsertLink",!1,{href:"_wp_link_placeholder"}),k=b.$('a[href="_wp_link_placeholder"]')[0],b.nodeChanged()),void b.dom.setAttribs(k,{"data-wplink-edit":!0}))}),b.addCommand("wp_link_apply",function(){if(!h.scrolling){var c,d;if(k){c=j.getURL(),d=j.getLinkText(),b.focus();var e=document.createElement("a");if(e.href=c,"javascript:"!==e.protocol&&"data:"!==e.protocol||(c=""),!c)return void b.dom.remove(k,!0);/^(?:[a-z]+:|#|\?|\.|\/)/.test(c)||o.test(c)||(c="http://"+c),b.dom.setAttribs(k,{href:c,"data-wplink-edit":null}),a.trim(k.innerHTML)||b.$(k).text(d||c),f(k)}j.reset(),b.nodeChanged(),"undefined"==typeof window.wpLinkL10n||s||r(window.wpLinkL10n.linkInserted)}}),b.addCommand("wp_link_cancel",function(){j.reset(),h.tempHide||d()}),b.addCommand("wp_unlink",function(){b.execCommand("unlink"),h.tempHide=!1,b.execCommand("wp_link_cancel")}),b.addShortcut("access+a","","WP_Link"),b.addShortcut("access+s","","wp_unlink"),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.lastLevel&&a.lastLevel.content&&a.level.content&&a.lastLevel.content===e(a.level.content)&&a.preventDefault()}),b.on("keydown",function(c){27===c.keyCode&&b.execCommand("wp_link_cancel"),c.altKey||a.Env.mac&&(!c.metaKey||c.ctrlKey)||!a.Env.mac&&!c.ctrlKey||89!==c.keyCode&&90!==c.keyCode||(l=!0,window.clearTimeout(m),m=window.setTimeout(function(){l=!1},500))}),b.addButton("wp_link_preview",{type:"WPLinkPreview",onPostRender:function(){i=this}}),b.addButton("wp_link_input",{type:"WPLinkInput",onPostRender:function(){var c,d,e,f=this.getEl(),g=f.firstChild;j=this,n&&n.ui&&n.ui.autocomplete&&(c=n(g),c.on("keydown",function(){c.removeAttr("aria-activedescendant")}).autocomplete({source:function(a,b){return e===a.term?void b(d):/^https?:/.test(a.term)||a.term.indexOf(".")!==-1?b():(n.post(window.ajaxurl,{action:"wp-link-ajax",page:1,search:a.term,_ajax_linking_nonce:n("#_ajax_linking_nonce").val()},function(a){d=a,b(a)},"json"),void(e=a.term))},focus:function(a,b){c.attr("aria-activedescendant","mce-wp-autocomplete-"+b.item.ID),a.preventDefault()},select:function(a,b){return c.val(b.item.permalink),n(f.firstChild.nextSibling).val(b.item.title),9===a.keyCode&&"undefined"!=typeof window.wpLinkL10n&&r(window.wpLinkL10n.linkSelected),!1},open:function(){c.attr("aria-expanded","true"),h.blockHide=!0},close:function(){c.attr("aria-expanded","false"),h.blockHide=!1},minLength:2,position:{my:"left top+2"},messages:{noResults:"undefined"!=typeof window.uiAutocompleteL10n?window.uiAutocompleteL10n.noResults:"",results:function(a){if("undefined"!=typeof window.uiAutocompleteL10n)return a>1?window.uiAutocompleteL10n.manyResults.replace("%d",a):window.uiAutocompleteL10n.oneResult}}}).autocomplete("instance")._renderItem=function(a,b){var c="undefined"!=typeof window.wpLinkL10n?window.wpLinkL10n.noTitle:"",d=b.title?b.title:c;return n('
  • ').append(""+d+' '+b.info+"").appendTo(a)},c.attr({role:"combobox","aria-autocomplete":"list","aria-expanded":"false","aria-owns":c.autocomplete("widget").attr("id")}).on("focus",function(){var a=c.val();a&&!/^https?:/.test(a)&&c.autocomplete("search")}).autocomplete("widget").addClass("wplink-autocomplete").attr("role","listbox").removeAttr("tabindex").on("menufocus",function(a,b){b.item.attr("aria-selected","true")}).on("menublur",function(){n(this).find('[aria-selected="true"]').removeAttr("aria-selected")})),a.$(g).on("keydown",function(a){13===a.keyCode&&(b.execCommand("wp_link_apply"),a.preventDefault())})}}),b.on("wptoolbar",function(a){var c,d,e,f=b.dom.getParent(a.element,"a");return"undefined"!=typeof window.wpLink&&window.wpLink.modalOpen?void(h.tempHide=!0):(h.tempHide=!1,void(f?(c=b.$(f),d=c.attr("href"),e=c.attr("data-wplink-edit"),"_wp_link_placeholder"===d||e?("_wp_link_placeholder"===d||j.getURL()||j.setURL(d),a.element=f,a.toolbar=h):d&&!c.find("img").length&&(i.setURL(d),a.element=f,a.toolbar=g,"true"===c.attr("data-wplink-url-error")?g.$el.find(".wp-link-preview a").addClass("wplink-url-error"):(g.$el.find(".wp-link-preview a").removeClass("wplink-url-error"),s=!1))):h.visible()&&b.execCommand("wp_link_cancel")))}),b.addButton("wp_link_edit",{tooltip:"Edit|button",icon:"dashicon dashicons-edit",cmd:"WP_Link"}),b.addButton("wp_link_remove",{tooltip:"Remove link",icon:"dashicon dashicons-editor-unlink",cmd:"wp_unlink"}),b.addButton("wp_link_advanced",{tooltip:"Link options",icon:"dashicon dashicons-admin-generic",onclick:function(){if("undefined"!=typeof window.wpLink){var a=j.getURL()||null,c=j.getLinkText()||null;window.wpLink.open(b.id,a,c),h.tempHide=!0,h.hide()}}}),b.addButton("wp_link_apply",{tooltip:"Apply",icon:"dashicon dashicons-editor-break",cmd:"wp_link_apply",classes:"widget btn primary"}),{close:function(){h.tempHide=!1,b.execCommand("wp_link_cancel")},checkLink:f}})}(window.tinymce); // Source: wp-includes/js/tinymce/plugins/wptextpattern/plugin.min.js !function(a,b){function c(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}a.Env.ie&&a.Env.ie<9||a.PluginManager.add("wptextpattern",function(d){function e(){var e,f,g,h,i,k=d.selection.getRng(),l=k.startContainer,m=k.startOffset;if(l&&3===l.nodeType&&l.data.length&&m){var n=l.data.slice(0,m),p=l.data.charAt(m-1);a.each(o,function(a){if(p===a.delimiter.slice(-1)){var b=c(a.delimiter),d=a.delimiter.charAt(0),h=new RegExp("(.*)"+b+".+"+b+"$"),i=n.match(h);if(i){e=i[1].length,f=m-a.delimiter.length;var j=n.charAt(e-1),k=n.charAt(e+a.delimiter.length);if(!(e&&/\S/.test(j)&&(/\s/.test(k)||j===d)||new RegExp("^[\\s"+c(d)+"]+$").test(n.slice(e,f))))return g=a,!1}}}),g&&(h=d.formatter.get(g.format),h&&h[0].inline&&(d.undoManager.add(),d.undoManager.transact(function(){l.insertData(m,"\ufeff"),l=l.splitText(e),i=l.splitText(m-e),l.deleteData(0,g.delimiter.length),l.deleteData(l.data.length-g.delimiter.length,g.delimiter.length),d.formatter.apply(g.format,{},l),d.selection.setCursorLocation(i,1)}),b(function(){j="space",d.once("selectionchange",function(){var a;i&&(a=i.data.indexOf("\ufeff"),a!==-1&&i.deleteData(a,a+1))})})))}}function f(a){var b,c=d.dom.getParent(a,"p");if(c){for(;(b=c.firstChild)&&3!==b.nodeType;)c=b;if(b)return b.data||(b=b.nextSibling&&3===b.nextSibling.nodeType?b.nextSibling:null),b}}function g(){var c,e,g=d.selection.getRng(),h=g.startContainer;h&&f(h)===h&&(c=h.parentNode,e=h.data,a.each(m,function(a){var f=e.match(a.regExp);if(f&&g.startOffset===f[0].length)return d.undoManager.add(),d.undoManager.transact(function(){h.deleteData(0,f[0].length),c.innerHTML||c.appendChild(document.createElement("br")),d.selection.setCursorLocation(c),d.execCommand(a.cmd)}),b(function(){j="space"}),!1}))}function h(){var c,e,g,h=d.selection.getRng(),k=h.startContainer,l=f(k),m=n.length;if(l){for(c=l.data;m--;)if(n[m].start){if(0===c.indexOf(n[m].start)){e=n[m];break}}else if(n[m].regExp&&n[m].regExp.test(c)){e=n[m];break}e&&(l===k&&a.trim(c)===e.start||d.once("keyup",function(){d.undoManager.add(),d.undoManager.transact(function(){e.format?(d.formatter.apply(e.format,{},l),l.replaceData(0,l.data.length,i(l.data.slice(e.start.length)))):e.element&&(g=l.parentNode&&l.parentNode.parentNode,g&&g.replaceChild(document.createElement(e.element),l.parentNode))}),b(function(){j="enter"})}))}}function i(a){return a?a.replace(/^\s+/,""):""}var j,k=a.util.VK,l=d.settings.wptextpattern||{},m=l.space||[{regExp:/^[*-]\s/,cmd:"InsertUnorderedList"},{regExp:/^1[.)]\s/,cmd:"InsertOrderedList"}],n=l.enter||[{start:"##",format:"h2"},{start:"###",format:"h3"},{start:"####",format:"h4"},{start:"#####",format:"h5"},{start:"######",format:"h6"},{start:">",format:"blockquote"},{regExp:/^(-){3,}$/,element:"hr"}],o=l.inline||[{delimiter:"`",format:"code"}];d.on("selectionchange",function(){j=null}),d.on("keydown",function(a){(j&&27===a.keyCode||"space"===j&&a.keyCode===k.BACKSPACE)&&(d.undoManager.undo(),a.preventDefault(),a.stopImmediatePropagation()),k.metaKeyPressed(a)||(a.keyCode===k.ENTER?h():a.keyCode===k.SPACEBAR?b(g):a.keyCode>47&&!(a.keyCode>=91&&a.keyCode<=93)&&b(e))},!0)})}(window.tinymce,window.setTimeout); // Source: wp-includes/js/tinymce/plugins/wpview/plugin.min.js diff --git a/wp-includes/js/wplink.js b/wp-includes/js/wplink.js index ff9b3c441d..8b6a93795a 100644 --- a/wp-includes/js/wplink.js +++ b/wp-includes/js/wplink.js @@ -5,7 +5,7 @@ /* global wpLink */ ( function( $, wpLinkL10n, wp ) { - var editor, searchTimer, River, Query, correctedURL, linkNode, + var editor, searchTimer, River, Query, correctedURL, emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,63}$/i, urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,63}[^ "]*$/i, inputs = {}, @@ -13,7 +13,11 @@ isTouch = ( 'ontouchend' in document ); function getLink() { - return linkNode || editor.dom.getParent( editor.selection.getNode(), 'a[href]' ); + if ( editor ) { + return editor.$( 'a[data-wplink-edit="true"]' ); + } + + return null; } window.wpLink = { @@ -97,13 +101,12 @@ } }, - open: function( editorId, url, text, node ) { + open: function( editorId, url, text ) { var ed, $body = $( document.body ); $body.addClass( 'modal-open' ); wpLink.modalOpen = true; - linkNode = node; wpLink.range = null; @@ -205,10 +208,10 @@ return false; } - if ( linkNode ) { - nodes = linkNode.childNodes; + if ( linkNode.length ) { + nodes = linkNode[0].childNodes; - if ( nodes.length === 0 ) { + if ( ! nodes || ! nodes.length ) { return false; } @@ -229,9 +232,9 @@ linkNode = getLink(), onlyText = this.hasSelectedText( linkNode ); - if ( linkNode ) { - linkText = linkNode.textContent || linkNode.innerText; - href = editor.dom.getAttrib( linkNode, 'href' ); + if ( linkNode.length ) { + linkText = linkNode.text(); + href = linkNode.attr( 'href' ); if ( ! $.trim( linkText ) ) { linkText = text || ''; @@ -243,7 +246,7 @@ if ( href !== '_wp_link_placeholder' ) { inputs.url.val( href ); - inputs.openInNewTab.prop( 'checked', '_blank' === editor.dom.getAttrib( linkNode, 'target' ) ); + inputs.openInNewTab.prop( 'checked', '_blank' === linkNode.attr( 'target' ) ); inputs.submit.val( wpLinkL10n.update ); } else { this.setDefaultValues( linkText ); @@ -414,7 +417,7 @@ return; } - $link = editor.$( getLink() ); + $link = getLink(); editor.undoManager.transact( function() { if ( ! $link.length ) { @@ -437,7 +440,7 @@ } attrs['data-wplink-edit'] = null; - attrs['data-mce-href'] = null; // attrs.href + attrs['data-mce-href'] = attrs.href; $link.attr( attrs ); } } ); @@ -446,14 +449,7 @@ editor.focus(); if ( $link.length ) { - $mceCaret = $link.parent( '#_mce_caret' ); - - if ( $mceCaret.length ) { - $mceCaret.before( $link.removeAttr( 'data-mce-bogus' ) ); - } - editor.selection.select( $link[0] ); - editor.selection.collapse(); if ( editor.plugins.wplink ) { editor.plugins.wplink.checkLink( $link[0] ); @@ -468,6 +464,10 @@ updateFields: function( e, li ) { inputs.url.val( li.children( '.item-permalink' ).val() ); + + if ( inputs.wrap.hasClass( 'has-text-field' ) && ! inputs.text.val() ) { + inputs.text.val( li.children( '.item-title' ).text() ); + } }, getUrlFromSelection: function( selection ) { diff --git a/wp-includes/js/wplink.min.js b/wp-includes/js/wplink.min.js index 35693fac48..6196649ce0 100644 --- a/wp-includes/js/wplink.min.js +++ b/wp-includes/js/wplink.min.js @@ -1 +1 @@ -!function(a,b,c){function d(){return j||e.dom.getParent(e.selection.getNode(),"a[href]")}var e,f,g,h,i,j,k=/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,63}$/i,l=/^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,63}[^ "]*$/i,m={},n={},o="ontouchend"in document;window.wpLink={timeToTriggerRiver:150,minRiverAJAXDuration:200,riverBottomThreshold:5,keySensitivity:100,lastSearch:"",textarea:"",modalOpen:!1,init:function(){m.wrap=a("#wp-link-wrap"),m.dialog=a("#wp-link"),m.backdrop=a("#wp-link-backdrop"),m.submit=a("#wp-link-submit"),m.close=a("#wp-link-close"),m.text=a("#wp-link-text"),m.url=a("#wp-link-url"),m.nonce=a("#_ajax_linking_nonce"),m.openInNewTab=a("#wp-link-target"),m.search=a("#wp-link-search"),n.search=new g(a("#search-results")),n.recent=new g(a("#most-recent-results")),n.elements=m.dialog.find(".query-results"),m.queryNotice=a("#query-notice-message"),m.queryNoticeTextDefault=m.queryNotice.find(".query-notice-default"),m.queryNoticeTextHint=m.queryNotice.find(".query-notice-hint"),m.dialog.keydown(wpLink.keydown),m.dialog.keyup(wpLink.keyup),m.submit.click(function(a){a.preventDefault(),wpLink.update()}),m.close.add(m.backdrop).add("#wp-link-cancel button").click(function(a){a.preventDefault(),wpLink.close()}),n.elements.on("river-select",wpLink.updateFields),m.search.on("focus.wplink",function(){m.queryNoticeTextDefault.hide(),m.queryNoticeTextHint.removeClass("screen-reader-text").show()}).on("blur.wplink",function(){m.queryNoticeTextDefault.show(),m.queryNoticeTextHint.addClass("screen-reader-text").hide()}),m.search.on("keyup input",function(){window.clearTimeout(f),f=window.setTimeout(function(){wpLink.searchInternalLinks()},500)}),m.url.on("paste",function(){setTimeout(wpLink.correctURL,0)}),m.url.on("blur",wpLink.correctURL)},correctURL:function(){var b=a.trim(m.url.val());b&&i!==b&&!/^(?:[a-z]+:|#|\?|\.|\/)/.test(b)&&(m.url.val("http://"+b),i=b)},open:function(b,c,d,f){var g,h=a(document.body);h.addClass("modal-open"),wpLink.modalOpen=!0,j=f,wpLink.range=null,b&&(window.wpActiveEditor=b),window.wpActiveEditor&&(this.textarea=a("#"+window.wpActiveEditor).get(0),"undefined"!=typeof window.tinymce&&(h.append(m.backdrop,m.wrap),g=window.tinymce.get(window.wpActiveEditor),e=g&&!g.isHidden()?g:null),!wpLink.isMCE()&&document.selection&&(this.textarea.focus(),this.range=document.selection.createRange()),m.wrap.show(),m.backdrop.show(),wpLink.refresh(c,d),a(document).trigger("wplink-open",m.wrap))},isMCE:function(){return e&&!e.isHidden()},refresh:function(a,b){var c="";n.search.refresh(),n.recent.refresh(),wpLink.isMCE()?wpLink.mceRefresh(a,b):(m.wrap.hasClass("has-text-field")||m.wrap.addClass("has-text-field"),document.selection?c=document.selection.createRange().text||b||"":"undefined"!=typeof this.textarea.selectionStart&&this.textarea.selectionStart!==this.textarea.selectionEnd&&(b=this.textarea.value.substring(this.textarea.selectionStart,this.textarea.selectionEnd)||b||""),m.text.val(b),wpLink.setDefaultValues()),o?m.url.focus().blur():window.setTimeout(function(){m.url[0].select(),m.url.focus()}),n.recent.ul.children().length||n.recent.ajax(),i=m.url.val().replace(/^http:\/\//,"")},hasSelectedText:function(a){var b,c,d,f=e.selection.getContent();if(/]+>[^<]+<\/a>$/.test(f)||f.indexOf("href=")===-1))return!1;if(a){if(c=a.childNodes,0===c.length)return!1;for(d=c.length-1;d>=0;d--)if(b=c[d],3!=b.nodeType&&!window.tinymce.dom.BookmarkManager.isBookmarkNode(b))return!1}return!0},mceRefresh:function(c,f){var g,h,i=d(),j=this.hasSelectedText(i);i?(g=i.textContent||i.innerText,h=e.dom.getAttrib(i,"href"),a.trim(g)||(g=f||""),c&&(l.test(c)||k.test(c))&&(h=c),"_wp_link_placeholder"!==h?(m.url.val(h),m.openInNewTab.prop("checked","_blank"===e.dom.getAttrib(i,"target")),m.submit.val(b.update)):this.setDefaultValues(g),c&&c!==h?m.search.val(c):m.search.val(""),window.setTimeout(function(){wpLink.searchInternalLinks()})):(g=e.selection.getContent({format:"text"})||f||"",this.setDefaultValues(g)),j?(m.text.val(g),m.wrap.addClass("has-text-field")):(m.text.val(""),m.wrap.removeClass("has-text-field"))},close:function(b){a(document.body).removeClass("modal-open"),wpLink.modalOpen=!1,"noReset"!==b&&(wpLink.isMCE()?(e.plugins.wplink&&e.plugins.wplink.close(),e.focus()):(wpLink.textarea.focus(),wpLink.range&&(wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select()))),m.backdrop.hide(),m.wrap.hide(),i=!1,a(document).trigger("wplink-close",m.wrap)},getAttrs:function(){return wpLink.correctURL(),{href:a.trim(m.url.val()),target:m.openInNewTab.prop("checked")?"_blank":null}},buildHtml:function(a){var b='"},update:function(){wpLink.isMCE()?wpLink.mceUpdate():wpLink.htmlUpdate()},htmlUpdate:function(){var d,e,f,g,h,i,j,k=wpLink.textarea;if(k){d=wpLink.getAttrs(),e=m.text.val();var l=document.createElement("a");l.href=d.href,"javascript:"!==l.protocol&&"data:"!==l.protocol||(d.href=""),d.href&&(f=wpLink.buildHtml(d),document.selection&&wpLink.range?(k.focus(),wpLink.range.text=f+(e||wpLink.range.text)+"",wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select(),wpLink.range=null):"undefined"!=typeof k.selectionStart&&(g=k.selectionStart,h=k.selectionEnd,j=e||k.value.substring(g,h),f=f+j+"",i=g+f.length,g!==h||j||(i-=4),k.value=k.value.substring(0,g)+f+k.value.substring(h,k.value.length),k.selectionStart=k.selectionEnd=i),wpLink.close(),k.focus(),a(k).trigger("change"),c.a11y.speak(b.linkInserted))}},mceUpdate:function(){var f,g,h,i,j=wpLink.getAttrs(),k=document.createElement("a");return k.href=j.href,"javascript:"!==k.protocol&&"data:"!==k.protocol||(j.href=""),j.href?(f=e.$(d()),e.undoManager.transact(function(){f.length||(e.execCommand("mceInsertLink",!1,{href:"_wp_link_placeholder","data-wp-temp-link":1}),f=e.$('a[data-wp-temp-link="1"]').removeAttr("data-wp-temp-link"),h=a.trim(f.text())),f.length?(m.wrap.hasClass("has-text-field")&&(g=m.text.val(),g?f.text(g):h||f.text(j.href)),j["data-wplink-edit"]=null,j["data-mce-href"]=null,f.attr(j)):e.execCommand("unlink")}),wpLink.close("noReset"),e.focus(),f.length&&(i=f.parent("#_mce_caret"),i.length&&i.before(f.removeAttr("data-mce-bogus")),e.selection.select(f[0]),e.selection.collapse(),e.plugins.wplink&&e.plugins.wplink.checkLink(f[0])),e.nodeChanged(),void c.a11y.speak(b.linkInserted)):(e.execCommand("unlink"),void wpLink.close())},updateFields:function(a,b){m.url.val(b.children(".item-permalink").val())},getUrlFromSelection:function(b){return b||(this.isMCE()?b=e.selection.getContent({format:"text"}):document.selection&&wpLink.range?b=wpLink.range.text:"undefined"!=typeof this.textarea.selectionStart&&(b=this.textarea.value.substring(this.textarea.selectionStart,this.textarea.selectionEnd))),b=a.trim(b),b&&k.test(b)?"mailto:"+b:b&&l.test(b)?b.replace(/&|�?38;/gi,"&"):""},setDefaultValues:function(a){m.url.val(this.getUrlFromSelection(a)),m.search.val(""),wpLink.searchInternalLinks(),m.submit.val(b.save)},searchInternalLinks:function(){var a,b=m.search.val()||"";if(b.length>2){if(n.recent.hide(),n.search.show(),wpLink.lastSearch==b)return;wpLink.lastSearch=b,a=m.search.parent().find(".spinner").addClass("is-active"),n.search.change(b),n.search.ajax(function(){a.removeClass("is-active")})}else n.search.hide(),n.recent.show()},next:function(){n.search.next(),n.recent.next()},prev:function(){n.search.prev(),n.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&&(m.submit.focus(),a.preventDefault()):(m.close.focus(),a.preventDefault())),a.shiftKey||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}},g=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(g.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(),e<0?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 h(a),this.element.scrollTop(0))},process:function(c,d){var e="",f=!0,g="",h=1==d.page;c?a.each(c,function(){g=f?"alternate":"",g+=this.title?"":" no-title",e+=g?'
  • ':"
  • ",e+='',e+='',e+=this.title?this.title:b.noTitle,e+=''+this.info+"
  • ",f=!f}):h&&(e+='
  • '+b.noMatchesFound+"
  • "),this.ul[h?"html":"append"](e)},maybeLoad:function(){var a=this,b=this.element,c=b.scrollTop()+b.height();!this.query.ready()||c]+>[^<]+<\/a>$/.test(f)||f.indexOf("href=")===-1))return!1;if(a.length){if(c=a[0].childNodes,!c||!c.length)return!1;for(d=c.length-1;d>=0;d--)if(b=c[d],3!=b.nodeType&&!window.tinymce.dom.BookmarkManager.isBookmarkNode(b))return!1}return!0},mceRefresh:function(c,f){var g,h,i=d(),m=this.hasSelectedText(i);i.length?(g=i.text(),h=i.attr("href"),a.trim(g)||(g=f||""),c&&(k.test(c)||j.test(c))&&(h=c),"_wp_link_placeholder"!==h?(l.url.val(h),l.openInNewTab.prop("checked","_blank"===i.attr("target")),l.submit.val(b.update)):this.setDefaultValues(g),c&&c!==h?l.search.val(c):l.search.val(""),window.setTimeout(function(){wpLink.searchInternalLinks()})):(g=e.selection.getContent({format:"text"})||f||"",this.setDefaultValues(g)),m?(l.text.val(g),l.wrap.addClass("has-text-field")):(l.text.val(""),l.wrap.removeClass("has-text-field"))},close:function(b){a(document.body).removeClass("modal-open"),wpLink.modalOpen=!1,"noReset"!==b&&(wpLink.isMCE()?(e.plugins.wplink&&e.plugins.wplink.close(),e.focus()):(wpLink.textarea.focus(),wpLink.range&&(wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select()))),l.backdrop.hide(),l.wrap.hide(),i=!1,a(document).trigger("wplink-close",l.wrap)},getAttrs:function(){return wpLink.correctURL(),{href:a.trim(l.url.val()),target:l.openInNewTab.prop("checked")?"_blank":null}},buildHtml:function(a){var b='"},update:function(){wpLink.isMCE()?wpLink.mceUpdate():wpLink.htmlUpdate()},htmlUpdate:function(){var d,e,f,g,h,i,j,k=wpLink.textarea;if(k){d=wpLink.getAttrs(),e=l.text.val();var m=document.createElement("a");m.href=d.href,"javascript:"!==m.protocol&&"data:"!==m.protocol||(d.href=""),d.href&&(f=wpLink.buildHtml(d),document.selection&&wpLink.range?(k.focus(),wpLink.range.text=f+(e||wpLink.range.text)+"",wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select(),wpLink.range=null):"undefined"!=typeof k.selectionStart&&(g=k.selectionStart,h=k.selectionEnd,j=e||k.value.substring(g,h),f=f+j+"",i=g+f.length,g!==h||j||(i-=4),k.value=k.value.substring(0,g)+f+k.value.substring(h,k.value.length),k.selectionStart=k.selectionEnd=i),wpLink.close(),k.focus(),a(k).trigger("change"),c.a11y.speak(b.linkInserted))}},mceUpdate:function(){var f,g,h,i=wpLink.getAttrs(),j=document.createElement("a");return j.href=i.href,"javascript:"!==j.protocol&&"data:"!==j.protocol||(i.href=""),i.href?(f=d(),e.undoManager.transact(function(){f.length||(e.execCommand("mceInsertLink",!1,{href:"_wp_link_placeholder","data-wp-temp-link":1}),f=e.$('a[data-wp-temp-link="1"]').removeAttr("data-wp-temp-link"),h=a.trim(f.text())),f.length?(l.wrap.hasClass("has-text-field")&&(g=l.text.val(),g?f.text(g):h||f.text(i.href)),i["data-wplink-edit"]=null,i["data-mce-href"]=i.href,f.attr(i)):e.execCommand("unlink")}),wpLink.close("noReset"),e.focus(),f.length&&(e.selection.select(f[0]),e.plugins.wplink&&e.plugins.wplink.checkLink(f[0])),e.nodeChanged(),void c.a11y.speak(b.linkInserted)):(e.execCommand("unlink"),void wpLink.close())},updateFields:function(a,b){l.url.val(b.children(".item-permalink").val()),l.wrap.hasClass("has-text-field")&&!l.text.val()&&l.text.val(b.children(".item-title").text())},getUrlFromSelection:function(b){return b||(this.isMCE()?b=e.selection.getContent({format:"text"}):document.selection&&wpLink.range?b=wpLink.range.text:"undefined"!=typeof this.textarea.selectionStart&&(b=this.textarea.value.substring(this.textarea.selectionStart,this.textarea.selectionEnd))),b=a.trim(b),b&&j.test(b)?"mailto:"+b:b&&k.test(b)?b.replace(/&|�?38;/gi,"&"):""},setDefaultValues:function(a){l.url.val(this.getUrlFromSelection(a)),l.search.val(""),wpLink.searchInternalLinks(),l.submit.val(b.save)},searchInternalLinks:function(){var a,b=l.search.val()||"";if(b.length>2){if(m.recent.hide(),m.search.show(),wpLink.lastSearch==b)return;wpLink.lastSearch=b,a=l.search.parent().find(".spinner").addClass("is-active"),m.search.change(b),m.search.ajax(function(){a.removeClass("is-active")})}else m.search.hide(),m.recent.show()},next:function(){m.search.next(),m.recent.next()},prev:function(){m.search.prev(),m.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&&(l.submit.focus(),a.preventDefault()):(l.close.focus(),a.preventDefault())),a.shiftKey||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}},g=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(g.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(),e<0?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 h(a),this.element.scrollTop(0))},process:function(c,d){var e="",f=!0,g="",h=1==d.page;c?a.each(c,function(){g=f?"alternate":"",g+=this.title?"":" no-title",e+=g?'
  • ':"
  • ",e+='',e+='',e+=this.title?this.title:b.noTitle,e+=''+this.info+"
  • ",f=!f}):h&&(e+='
  • '+b.noMatchesFound+"
  • "),this.ul[h?"html":"append"](e)},maybeLoad:function(){var a=this,b=this.element,c=b.scrollTop()+b.height();!this.query.ready()||c