<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[31713] trunk/src/wp-includes: wpLink: replace the "Title" field with a "Text" field and populate it with the link text when editing an existing link or with the selected text if any.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/31713">31713</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/31713","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>azaozz</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-03-11 02:39:02 +0000 (Wed, 11 Mar 2015)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>wpLink: replace the "Title" field with a "Text" field and populate it with the link text when editing an existing link or with the selected text if any.
Props iseulde. See <a href="https://core.trac.wordpress.org/ticket/28206">#28206</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesclasswpeditorphp">trunk/src/wp-includes/class-wp-editor.php</a></li>
<li><a href="#trunksrcwpincludescsseditorcss">trunk/src/wp-includes/css/editor.css</a></li>
<li><a href="#trunksrcwpincludesjstinymcepluginswplinkpluginjs">trunk/src/wp-includes/js/tinymce/plugins/wplink/plugin.js</a></li>
<li><a href="#trunksrcwpincludesjswplinkjs">trunk/src/wp-includes/js/wplink.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesclasswpeditorphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-editor.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-editor.php 2015-03-11 02:06:32 UTC (rev 31712)
+++ trunk/src/wp-includes/class-wp-editor.php   2015-03-11 02:39:02 UTC (rev 31713)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1448,14 +1448,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">                <div id="link-selector">
</span><span class="cx" style="display: block; padding: 0 10px">                        <div id="link-options">
</span><span class="cx" style="display: block; padding: 0 10px">                                <p class="howto"><?php _e( 'Enter the destination URL' ); ?></p>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                <div>
-                                       <label><span><?php _e( 'URL' ); ?></span><input id="url-field" type="text" name="href" /></label>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         <div class="wp-link-text-field">
+                                       <label><span><?php _e( 'Text' ); ?></span><input id="wp-link-text" type="text" /></label>
</ins><span class="cx" style="display: block; padding: 0 10px">                                 </div>
</span><span class="cx" style="display: block; padding: 0 10px">                                <div>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        <label><span><?php _e( 'Title' ); ?></span><input id="link-title-field" type="text" name="linktitle" /></label>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 <label><span><?php _e( 'URL' ); ?></span><input id="wp-link-url" type="text" /></label>
</ins><span class="cx" style="display: block; padding: 0 10px">                                 </div>
</span><span class="cx" style="display: block; padding: 0 10px">                                <div class="link-target">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        <label><span>&nbsp;</span><input type="checkbox" id="link-target-checkbox" /> <?php _e( 'Open link in a new window/tab' ); ?></label>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 <label><span>&nbsp;</span><input type="checkbox" id="wp-link-target" /> <?php _e( 'Open link in a new window/tab' ); ?></label>
</ins><span class="cx" style="display: block; padding: 0 10px">                                 </div>
</span><span class="cx" style="display: block; padding: 0 10px">                        </div>
</span><span class="cx" style="display: block; padding: 0 10px">                        <p class="howto"><a href="#" id="wp-link-search-toggle"><?php _e( 'Or link to existing content' ); ?></a></p>
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1463,7 +1463,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                <div class="link-search-wrapper">
</span><span class="cx" style="display: block; padding: 0 10px">                                        <label>
</span><span class="cx" style="display: block; padding: 0 10px">                                                <span class="search-label"><?php _e( 'Search' ); ?></span>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                <input type="search" id="search-field" class="link-search-field" autocomplete="off" />
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         <input type="search" id="wp-link-search" class="link-search-field" autocomplete="off" />
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 <span class="spinner"></span>
</span><span class="cx" style="display: block; padding: 0 10px">                                        </label>
</span><span class="cx" style="display: block; padding: 0 10px">                                </div>
</span></span></pre></div>
<a id="trunksrcwpincludescsseditorcss"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/css/editor.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/css/editor.css      2015-03-11 02:06:32 UTC (rev 31712)
+++ trunk/src/wp-includes/css/editor.css        2015-03-11 02:39:02 UTC (rev 31713)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1193,7 +1193,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">        -webkit-box-shadow: 0 3px 6px rgba( 0, 0, 0, 0.3 );
</span><span class="cx" style="display: block; padding: 0 10px">        box-shadow: 0 3px 6px rgba( 0, 0, 0, 0.3 );
</span><span class="cx" style="display: block; padding: 0 10px">        width: 500px;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        height: 250px;
</del><span class="cx" style="display: block; padding: 0 10px">         overflow: hidden;
</span><span class="cx" style="display: block; padding: 0 10px">        margin-left: -250px;
</span><span class="cx" style="display: block; padding: 0 10px">        margin-top: -125px;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1229,6 +1228,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">        margin-top: -250px;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+#wp-link-wrap .wp-link-text-field {
+       display: none;
+}
+
+#wp-link-wrap.has-text-field .wp-link-text-field {
+       display: block;
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px"> #link-modal-title {
</span><span class="cx" style="display: block; padding: 0 10px">        background: #fcfcfc;
</span><span class="cx" style="display: block; padding: 0 10px">        border-bottom: 1px solid #dfdfdf;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1395,6 +1402,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">        left: 16px;
</span><span class="cx" style="display: block; padding: 0 10px">        right: 16px;
</span><span class="cx" style="display: block; padding: 0 10px">        bottom: 16px;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        top: 172px;
+}
+
+.has-text-field #wp-link .query-results {
</ins><span class="cx" style="display: block; padding: 0 10px">         top: 205px;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1529,11 +1540,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> @media screen and ( max-width: 782px ) {
</span><span class="cx" style="display: block; padding: 0 10px">        #wp-link-wrap {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                height: 280px;
</del><span class="cx" style="display: block; padding: 0 10px">                 margin-top: -140px;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        #wp-link-wrap.search-panel-visible .query-results {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                top: 195px;
+       }
+
+       #wp-link-wrap.search-panel-visible.has-text-field .query-results {
</ins><span class="cx" style="display: block; padding: 0 10px">                 top: 235px;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunksrcwpincludesjstinymcepluginswplinkpluginjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/js/tinymce/plugins/wplink/plugin.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/js/tinymce/plugins/wplink/plugin.js 2015-03-11 02:06:32 UTC (rev 31712)
+++ trunk/src/wp-includes/js/tinymce/plugins/wplink/plugin.js   2015-03-11 02:39:02 UTC (rev 31713)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,12 +1,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /* global tinymce */
</span><span class="cx" style="display: block; padding: 0 10px"> tinymce.PluginManager.add( 'wplink', function( editor ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        var linkButton;
-
-       // Register a command so that it can be invoked by using tinyMCE.activeEditor.execCommand( 'WP_Link' );
</del><span class="cx" style="display: block; padding: 0 10px">         editor.addCommand( 'WP_Link', function() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ( ! linkButton || ! linkButton.disabled() ) && typeof window.wpLink !== 'undefined' ) {
-                       window.wpLink.open( editor.id );
-               }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         window.wpLink && window.wpLink.open( editor.id );
</ins><span class="cx" style="display: block; padding: 0 10px">         });
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        // WP default shortcut
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -14,41 +9,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">        // The "de-facto standard" shortcut, see #27305
</span><span class="cx" style="display: block; padding: 0 10px">        editor.addShortcut( 'ctrl+k', '', 'WP_Link' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        function setState( button, node ) {
-               var parent = editor.dom.getParent( node, 'a' ),
-                       getView = editor.plugins.wpview ? editor.plugins.wpview.getView : function() { return false; };
-
-               button.disabled( ( editor.selection.isCollapsed() && ! parent ) || ( parent && ! parent.href ) || getView( node ) );
-               button.active( parent && parent.href );
-       }
-
</del><span class="cx" style="display: block; padding: 0 10px">         editor.addButton( 'link', {
</span><span class="cx" style="display: block; padding: 0 10px">                icon: 'link',
</span><span class="cx" style="display: block; padding: 0 10px">                tooltip: 'Insert/edit link',
</span><span class="cx" style="display: block; padding: 0 10px">                shortcut: 'Alt+Shift+A',
</span><span class="cx" style="display: block; padding: 0 10px">                cmd: 'WP_Link',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-               onPostRender: function() {
-                       linkButton = this;
-
-                       editor.on( 'nodechange', function( event ) {
-                               setState( linkButton, event.element );
-                       });
-               }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         stateSelector: 'a[href]'
</ins><span class="cx" style="display: block; padding: 0 10px">         });
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        editor.addButton( 'unlink', {
</span><span class="cx" style="display: block; padding: 0 10px">                icon: 'unlink',
</span><span class="cx" style="display: block; padding: 0 10px">                tooltip: 'Remove link',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                cmd: 'unlink',
-
-               onPostRender: function() {
-                       var unlinkButton = this;
-
-                       editor.on( 'nodechange', function( event ) {
-                               setState( unlinkButton, event.element );
-                       });
-               }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         cmd: 'unlink'
</ins><span class="cx" style="display: block; padding: 0 10px">         });
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        editor.addMenuItem( 'link', {
</span></span></pre></div>
<a id="trunksrcwpincludesjswplinkjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/js/wplink.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/js/wplink.js        2015-03-11 02:06:32 UTC (rev 31712)
+++ trunk/src/wp-includes/js/wplink.js  2015-03-11 02:39:02 UTC (rev 31713)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -7,6 +7,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                rivers = {},
</span><span class="cx" style="display: block; padding: 0 10px">                isTouch = ( 'ontouchend' in document );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        function getLink() {
+               return editor.dom.getParent( editor.selection.getNode(), 'a' );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         wpLink = {
</span><span class="cx" style="display: block; padding: 0 10px">                timeToTriggerRiver: 150,
</span><span class="cx" style="display: block; padding: 0 10px">                minRiverAJAXDuration: 200,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -21,14 +25,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        inputs.backdrop = $( '#wp-link-backdrop' );
</span><span class="cx" style="display: block; padding: 0 10px">                        inputs.submit = $( '#wp-link-submit' );
</span><span class="cx" style="display: block; padding: 0 10px">                        inputs.close = $( '#wp-link-close' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        // URL
-                       inputs.url = $( '#url-field' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                       // Input
+                       inputs.text = $( '#wp-link-text' );
+                       inputs.url = $( '#wp-link-url' );
</ins><span class="cx" style="display: block; padding: 0 10px">                         inputs.nonce = $( '#_ajax_linking_nonce' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        // Secondary options
-                       inputs.title = $( '#link-title-field' );
-                       // Advanced Options
-                       inputs.openInNewTab = $( '#link-target-checkbox' );
-                       inputs.search = $( '#search-field' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 inputs.openInNewTab = $( '#wp-link-target' );
+                       inputs.search = $( '#wp-link-search' );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                         // Build Rivers
</span><span class="cx" style="display: block; padding: 0 10px">                        rivers.search = new River( $( '#search-results' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                        rivers.recent = new River( $( '#most-recent-results' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -129,6 +133,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        inputs.backdrop.show();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        wpLink.refresh();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                         $( document ).trigger( 'wplink-open', inputs.wrap );
</span><span class="cx" style="display: block; padding: 0 10px">                },
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -144,6 +149,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( wpLink.isMCE() ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                wpLink.mceRefresh();
</span><span class="cx" style="display: block; padding: 0 10px">                        } else {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                inputs.wrap.removeClass( 'has-text-field' );
+                               inputs.text.val( '' );
</ins><span class="cx" style="display: block; padding: 0 10px">                                 wpLink.setDefaultValues();
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -154,7 +161,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                // Focus the URL field and highlight its contents.
</span><span class="cx" style="display: block; padding: 0 10px">                                // If this is moved above the selection changes,
</span><span class="cx" style="display: block; padding: 0 10px">                                // IE will show a flashing cursor over the dialog.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                inputs.url.focus()[0].select();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         if ( inputs.wrap.hasClass( 'has-text-field' ) ) {
+                                       inputs.text.focus();
+                               } else {
+                                       inputs.url.focus()[0].select();
+                               }
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // Load the most recent results if this is the first time opening the panel.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -165,22 +176,53 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        correctedURL = inputs.url.val().replace( /^http:\/\//, '' );
</span><span class="cx" style="display: block; padding: 0 10px">                },
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                hasSelectedText: function( linkNode ) {
+                       var html = editor.selection.getContent();
+
+                       // Partial html and not a fully selected anchor element
+                       if ( /</.test( html ) && ( ! /^<a [^>]+>[^<]+<\/a>$/.test( html ) || html.indexOf('href=') === -1 ) ) {
+                               return false;
+                       }
+
+                       if ( linkNode ) {
+                               var nodes = linkNode.childNodes, i;
+
+                               if ( nodes.length === 0 ) {
+                                       return false;
+                               }
+
+                               for ( i = nodes.length - 1; i >= 0; i-- ) {
+                                       if ( nodes[i].nodeType != 3 ) {
+                                               return false;
+                                       }
+                               }
+                       }
+
+                       return true;
+               },
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 mceRefresh: function() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        var e;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 var text,
+                               selectedNode = editor.selection.getNode(),
+                               linkNode = editor.dom.getParent( selectedNode, 'a[href]' ),
+                               onlyText = this.hasSelectedText( linkNode );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        // If link exists, select proper values.
-                       if ( e = editor.dom.getParent( editor.selection.getNode(), 'A' ) ) {
-                               // Set URL and description.
-                               inputs.url.val( editor.dom.getAttrib( e, 'href' ) );
-                               inputs.title.val( editor.dom.getAttrib( e, 'title' ) );
-                               // Set open in new tab.
-                               inputs.openInNewTab.prop( 'checked', ( '_blank' === editor.dom.getAttrib( e, 'target' ) ) );
-                               // Update save prompt.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( linkNode ) {
+                               text = linkNode.innerText || linkNode.textContent;
+                               inputs.url.val( editor.dom.getAttrib( linkNode, 'href' ) );
+                               inputs.openInNewTab.prop( 'checked', '_blank' === editor.dom.getAttrib( linkNode, 'target' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                                 inputs.submit.val( wpLinkL10n.update );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        } else {
+                               text = editor.selection.getContent({ format: 'text' });
+                               this.setDefaultValues();
+                       }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        // If there's no link, set the default values.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( onlyText ) {
+                               inputs.text.val( text || '' );
+                               inputs.wrap.addClass( 'has-text-field' );
</ins><span class="cx" style="display: block; padding: 0 10px">                         } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                wpLink.setDefaultValues();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         inputs.text.val( '' );
+                               inputs.wrap.removeClass( 'has-text-field' );
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px">                },
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -209,39 +251,37 @@
</span><span class="cx" style="display: block; padding: 0 10px">                getAttrs: function() {
</span><span class="cx" style="display: block; padding: 0 10px">                        return {
</span><span class="cx" style="display: block; padding: 0 10px">                                href: $.trim( inputs.url.val() ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                title: $.trim( inputs.title.val() ),
</del><span class="cx" style="display: block; padding: 0 10px">                                 target: inputs.openInNewTab.prop( 'checked' ) ? '_blank' : ''
</span><span class="cx" style="display: block; padding: 0 10px">                        };
</span><span class="cx" style="display: block; padding: 0 10px">                },
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                update: function() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( wpLink.isMCE() )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( wpLink.isMCE() ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                 wpLink.mceUpdate();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        else
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 } else {
</ins><span class="cx" style="display: block; padding: 0 10px">                                 wpLink.htmlUpdate();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        }
</ins><span class="cx" style="display: block; padding: 0 10px">                 },
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                htmlUpdate: function() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        var attrs, html, begin, end, cursor, title, selection,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 var attrs, text, html, begin, end, cursor, selection,
</ins><span class="cx" style="display: block; padding: 0 10px">                                 textarea = wpLink.textarea;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( ! textarea )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( ! textarea ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                 return;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        attrs = wpLink.getAttrs();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        text = inputs.text.val();
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // If there's no href, return.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( ! attrs.href )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( ! attrs.href ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                 return;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // Build HTML
</span><span class="cx" style="display: block; padding: 0 10px">                        html = '<a href="' + attrs.href + '"';
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( attrs.title ) {
-                               title = attrs.title.replace( /</g, '&lt;' ).replace( />/g, '&gt;' ).replace( /"/g, '&quot;' );
-                               html += ' title="' + title + '"';
-                       }
-
</del><span class="cx" style="display: block; padding: 0 10px">                         if ( attrs.target ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                html += ' target="' + attrs.target + '"';
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -254,25 +294,29 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                // Note: If no text is selected, IE will not place the cursor
</span><span class="cx" style="display: block; padding: 0 10px">                                //       inside the closing tag.
</span><span class="cx" style="display: block; padding: 0 10px">                                textarea.focus();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                wpLink.range.text = html + wpLink.range.text + '</a>';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         wpLink.range.text = html + ( text || wpLink.range.text ) + '</a>';
</ins><span class="cx" style="display: block; padding: 0 10px">                                 wpLink.range.moveToBookmark( wpLink.range.getBookmark() );
</span><span class="cx" style="display: block; padding: 0 10px">                                wpLink.range.select();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                wpLink.range = null;
</span><span class="cx" style="display: block; padding: 0 10px">                        } else if ( typeof textarea.selectionStart !== 'undefined' ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                // W3C
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                begin       = textarea.selectionStart;
-                               end         = textarea.selectionEnd;
-                               selection   = textarea.value.substring( begin, end );
-                               html        = html + selection + '</a>';
-                               cursor      = begin + html.length;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         begin = textarea.selectionStart;
+                               end = textarea.selectionEnd;
+                               selection = text || textarea.value.substring( begin, end );
+                               html = html + selection + '</a>';
+                               cursor = begin + html.length;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                // If no text is selected, place the cursor inside the closing tag.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                if ( begin == end )
-                                       cursor -= '</a>'.length;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         if ( begin === end && ! selection ) {
+                                       cursor -= 4;
+                               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                textarea.value = textarea.value.substring( 0, begin ) + html +
-                                       textarea.value.substring( end, textarea.value.length );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         textarea.value = (
+                                       textarea.value.substring( 0, begin ) +
+                                       html +
+                                       textarea.value.substring( end, textarea.value.length )
+                               );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                // Update cursor position
</span><span class="cx" style="display: block; padding: 0 10px">                                textarea.selectionStart = textarea.selectionEnd = cursor;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -283,8 +327,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                },
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                mceUpdate: function() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        var link,
-                               attrs = wpLink.getAttrs();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 var attrs = wpLink.getAttrs(),
+                               link, text;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        wpLink.close();
</span><span class="cx" style="display: block; padding: 0 10px">                        editor.focus();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -293,34 +337,51 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                editor.selection.moveToBookmark( editor.windowManager.bookmark );
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        link = editor.dom.getParent( editor.selection.getNode(), 'a[href]' );
-
-                       // If the values are empty, unlink and return
-                       if ( ! attrs.href || attrs.href == 'http://' ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( ! attrs.href ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                 editor.execCommand( 'unlink' );
</span><span class="cx" style="display: block; padding: 0 10px">                                return;
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        link = getLink();
+                       text = inputs.text.val();
+
</ins><span class="cx" style="display: block; padding: 0 10px">                         if ( link ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                if ( text ) {
+                                       if ( 'innerText' in link ) {
+                                               link.innerText = text;
+                                       } else {
+                                               link.textContent = text;
+                                       }
+                               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                                 editor.dom.setAttribs( link, attrs );
</span><span class="cx" style="display: block; padding: 0 10px">                        } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                editor.execCommand( 'mceInsertLink', false, attrs );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         if ( text ) {
+                                       editor.selection.setNode( editor.dom.create( 'a', attrs, text ) );
+                               } else {
+                                       editor.execCommand( 'mceInsertLink', false, attrs );
+                               }
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-                       // Move the cursor to the end of the selection
-                       editor.selection.collapse();
</del><span class="cx" style="display: block; padding: 0 10px">                 },
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                updateFields: function( e, li ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        inputs.url.val( li.children( '.item-permalink' ).val() );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        inputs.title.val( li.hasClass( 'no-title' ) ? '' : li.children( '.item-title' ).text() );
</del><span class="cx" style="display: block; padding: 0 10px">                 },
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                setDefaultValues: function() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        var selection = editor && editor.selection.getContent(),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 var selection,
</ins><span class="cx" style="display: block; padding: 0 10px">                                 emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i,
+                               text;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        if ( this.isMCE() ) {
+                               selection = editor.selection.getContent();
+                       } else if ( document.selection && wpLink.range ) {
+                               selection = wpLink.range.text;
+                       } else if ( typeof this.textarea.selectionStart !== 'undefined' ) {
+                               selection = this.textarea.value.substring( this.textarea.selectionStart, this.textarea.selectionEnd );
+                       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                         if ( selection && emailRegexp.test( selection ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                // Selection is email address
</span><span class="cx" style="display: block; padding: 0 10px">                                inputs.url.val( 'mailto:' + selection );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -332,9 +393,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                inputs.url.val( '' );
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        // Set description to default.
-                       inputs.title.val( '' );
-
</del><span class="cx" style="display: block; padding: 0 10px">                         // Update save prompt.
</span><span class="cx" style="display: block; padding: 0 10px">                        inputs.submit.val( wpLinkL10n.save );
</span><span class="cx" style="display: block; padding: 0 10px">                },
</span></span></pre>
</div>
</div>

</body>
</html>