<!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>[36384] trunk/src: TinyMCE: add inline link dialog</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/36384">36384</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/36384","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>iseulde</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-01-23 00:07:29 +0000 (Sat, 23 Jan 2016)</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'>TinyMCE: add inline link dialog
First run.
Links the advanced button to the "old" dialog for now.
See <a href="https://core.trac.wordpress.org/ticket/33301">#33301</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesajaxactionsphp">trunk/src/wp-admin/includes/ajax-actions.php</a></li>
<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="#trunksrcwpincludesjstinymcepluginswordpresspluginjs">trunk/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js</a></li>
<li><a href="#trunksrcwpincludesjstinymcepluginswplinkpluginjs">trunk/src/wp-includes/js/tinymce/plugins/wplink/plugin.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesajaxactionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/ajax-actions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/ajax-actions.php 2016-01-22 21:20:26 UTC (rev 36383)
+++ trunk/src/wp-admin/includes/ajax-actions.php 2016-01-23 00:07:29 UTC (rev 36384)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1477,8 +1477,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $args = array();
</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 ( isset( $_POST['search'] ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( isset( $_POST['search'] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $args['s'] = wp_unslash( $_POST['search'] );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
+
+ if ( isset( $_POST['term'] ) ) {
+ $args['s'] = wp_unslash( $_POST['term'] );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $args['pagenum'] = ! empty( $_POST['page'] ) ? absint( $_POST['page'] ) : 1;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> require(ABSPATH . WPINC . '/class-wp-editor.php');
</span></span></pre></div>
<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 2016-01-22 21:20:26 UTC (rev 36383)
+++ trunk/src/wp-includes/class-wp-editor.php 2016-01-23 00:07:29 UTC (rev 36384)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -779,6 +779,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( in_array('wplink', self::$plugins, true) || in_array('link', self::$qt_buttons, true) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> wp_enqueue_script('wplink');
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_enqueue_script( 'jquery-ui-autocomplete' );
</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"> if ( self::$old_dfw_compat ) {
</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 2016-01-22 21:20:26 UTC (rev 36383)
+++ trunk/src/wp-includes/css/editor.css 2016-01-23 00:07:29 UTC (rev 36384)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -451,6 +451,46 @@
</span><span class="cx" style="display: block; padding: 0 10px"> width: 20px;
</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">+.mce-toolbar .mce-btn-group .mce-btn.mce-primary {
+ min-width: 0;
+ background: #0085ba;
+ border-color: #0073aa #006799 #006799;
+ -webkit-box-shadow: 0 1px 0 #006799;
+ box-shadow: 0 1px 0 #006799;
+ color: #fff;
+ text-decoration: none;
+ text-shadow: 0 -1px 1px #006799,
+ 1px 0 1px #006799,
+ 0 1px 1px #006799,
+ -1px 0 1px #006799;
+}
+
+.mce-toolbar .mce-btn-group .mce-btn.mce-primary .mce-ico {
+ color: #fff;
+}
+
+.mce-toolbar .mce-btn-group .mce-btn.mce-primary:hover,
+.mce-toolbar .mce-btn-group .mce-btn.mce-primary:focus {
+ background: #008ec2;
+ border-color: #006799;
+ color: #fff;
+}
+
+.mce-toolbar .mce-btn-group .mce-btn.mce-primary:focus {
+ -webkit-box-shadow: 0 1px 0 #0073aa,
+ 0 0 2px 1px #33b3db;
+ box-shadow: 0 1px 0 #0073aa,
+ 0 0 2px 1px #33b3db;
+}
+
+.mce-toolbar .mce-btn-group .mce-btn.mce-primary:active {
+ background: #0073aa;
+ border-color: #006799;
+ -webkit-box-shadow: inset 0 2px 0 #006799;
+ box-shadow: inset 0 2px 0 #006799;
+ vertical-align: top;
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /* mce listbox */
</span><span class="cx" style="display: block; padding: 0 10px"> .mce-toolbar .mce-btn-group .mce-btn.mce-listbox {
</span><span class="cx" style="display: block; padding: 0 10px"> -webkit-border-radius: 0;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1709,6 +1749,42 @@
</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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+div.wp-link-input {
+ float: left;
+ margin: 2px;
+ max-width: 694px;
+}
+
+div.wp-link-input input {
+ width: 300px;
+ padding: 3px;
+ -webkit-box-sizing: border-box;
+ -moz-box-sizing: border-box;
+ box-sizing: border-box;
+}
+
+@media screen and ( max-width: 400px ) {
+ div.wp-link-input {
+ min-width: 0;
+ max-width: 70%;
+ max-width: -webkit-calc(100% - 80px);
+ max-width: calc(100% - 80px);
+ }
+
+ div.wp-link-input input {
+ width: 100%;
+ font-size: 16px;
+ padding: 4px;
+ }
+}
+
+.ui-autocomplete.mce-wp-autocomplete {
+ z-index: 100100;
+ margin-top: 10px;
+ max-height: 200px;
+ overflow-y: auto;
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /* =Overlay Body
</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="trunksrcwpincludesjstinymcepluginswordpresspluginjs"></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/wordpress/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/wordpress/plugin.js 2016-01-22 21:20:26 UTC (rev 36383)
+++ trunk/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js 2016-01-23 00:07:29 UTC (rev 36384)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -744,7 +744,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> top, left;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( spaceTop >= editorHeight || spaceBottom >= editorHeight ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return this.hide();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ this.scrolling = true;
+ this.hide();
+ this.scrolling = false;
+ return this;
</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"> // Add offset in iOS to move the menu over the image, out of the way of the default iOS menu.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -850,13 +853,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> currentSelection = args.selection || args.element;
</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 ( activeToolbar ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( activeToolbar && activeToolbar !== args.toolbar ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> activeToolbar.hide();
</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"> if ( args.toolbar ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- activeToolbar = args.toolbar;
- activeToolbar.show();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( activeToolbar !== args.toolbar ) {
+ activeToolbar = args.toolbar;
+ activeToolbar.show();
+ } else {
+ activeToolbar.reposition();
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> activeToolbar = false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -870,18 +877,21 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> function hide( event ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( activeToolbar ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- activeToolbar.hide();
-
</del><span class="cx" style="display: block; padding: 0 10px"> if ( event.type === 'hide' ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ activeToolbar.hide();
</ins><span class="cx" style="display: block; padding: 0 10px"> activeToolbar = false;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } else if ( event.type === 'resize' || event.type === 'scroll' ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } else if ( ( event.type === 'resize' || event.type === 'scroll' ) && ! activeToolbar.blockHide ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> clearTimeout( timeout );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> timeout = setTimeout( function() {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( activeToolbar && typeof activeToolbar.show === 'function' ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ activeToolbar.scrolling = false;
</ins><span class="cx" style="display: block; padding: 0 10px"> activeToolbar.show();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }, 250 );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ activeToolbar.scrolling = true;
+ activeToolbar.hide();
</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></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 2016-01-22 21:20:26 UTC (rev 36383)
+++ trunk/src/wp-includes/js/tinymce/plugins/wplink/plugin.js 2016-01-23 00:07:29 UTC (rev 36384)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -47,13 +47,106 @@
</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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ tinymce.ui.WPLinkInput = tinymce.ui.Control.extend( {
+ renderHtml: function() {
+ return (
+ '<div id="' + this._id + '" class="wp-link-input">' +
+ '<input type="text" value="" tabindex="-1" />' +
+ '</div>'
+ );
+ },
+ setURL: function( url ) {
+ this.getEl().firstChild.value = url;
+ }
+ } );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> tinymce.PluginManager.add( 'wplink', function( editor ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ var a;
</ins><span class="cx" style="display: block; padding: 0 10px"> var toolbar;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ var editToolbar;
+ var previewInstance;
+ var inputInstance;
+ var $ = window.jQuery;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ editor.on( 'preinit', function() {
+ if ( editor.wp && editor.wp._createToolbar ) {
+ toolbar = editor.wp._createToolbar( [
+ 'wp_link_preview',
+ 'wp_link_edit',
+ 'wp_link_remove'
+ ], true );
+
+ editToolbar = editor.wp._createToolbar( [
+ 'wp_link_input',
+ 'wp_link_apply',
+ 'wp_link_advanced'
+ ], true );
+
+ editToolbar.on( 'show', function() {
+ var node = editToolbar.find( 'toolbar' )[0];
+ node && node.focus( true );
+ a = editor.dom.getParent( editor.selection.getNode(), 'a' );
+ } );
+
+ editToolbar.on( 'hide', function() {
+ editToolbar.scrolling || editor.execCommand( 'wp_link_cancel' );
+ } );
+ }
+ } );
+
</ins><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">- window.wpLink && window.wpLink.open( editor.id );
- });
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ var a = editor.dom.getParent( editor.selection.getNode(), 'a' );
</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 ( a ) {
+ editor.dom.setAttribs( a, { 'data-wp-edit': true } );
+ } else {
+ editor.execCommand( 'mceInsertLink', false, { href: '_wp_link_placeholder' } );
+ }
+
+ editor.nodeChanged();
+ } );
+
+ editor.addCommand( 'wp_link_apply', function() {
+ if ( editToolbar.scrolling ) {
+ return;
+ }
+
+ var href = tinymce.trim( inputInstance.getEl().firstChild.value );
+
+ if ( href && ! /^(?:[a-z]+:|#|\?|\.|\/)/.test( href ) ) {
+ href = 'http://' + href;
+ }
+
+ if ( ! href ) {
+ editor.dom.remove( a, true );
+ return;
+ }
+
+ if ( a ) {
+ editor.dom.setAttribs( a, { href: href, 'data-wp-edit': null } );
+ }
+
+ a = false;
+
+ editor.nodeChanged();
+ editor.focus();
+ } );
+
+ editor.addCommand( 'wp_link_cancel', function() {
+ if ( a ) {
+ if ( editor.$( a ).attr( 'href' ) === '_wp_link_placeholder' ) {
+ editor.dom.remove( a, true );
+ } else {
+ editor.dom.setAttribs( a, { 'data-wp-edit': null } );
+ }
+ }
+
+ a = false;
+
+ editor.nodeChanged();
+ editor.focus();
+ } );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // WP default shortcut
</span><span class="cx" style="display: block; padding: 0 10px"> editor.addShortcut( 'access+a', '', 'WP_Link' );
</span><span class="cx" style="display: block; padding: 0 10px"> // The "de-facto standard" shortcut, see #27305
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -102,27 +195,115 @@
</span><span class="cx" style="display: block; padding: 0 10px"> editor.addButton( 'wp_link_preview', {
</span><span class="cx" style="display: block; padding: 0 10px"> type: 'WPLinkPreview',
</span><span class="cx" style="display: block; padding: 0 10px"> onPostRender: function() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- var self = this;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ previewInstance = this;
+ }
+ } );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- editor.on( 'wptoolbar', function( event ) {
- var anchor = editor.dom.getParent( event.element, 'a' ),
- $anchor,
- href;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ editor.addButton( 'wp_link_input', {
+ type: 'WPLinkInput',
+ onPostRender: function() {
+ var input = this.getEl().firstChild;
+ var cache;
+ var last;
</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 ( anchor ) {
- $anchor = editor.$( anchor );
- href = $anchor.attr( 'href' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ inputInstance = this;
</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 ( href && ! $anchor.find( 'img' ).length ) {
- self.setURL( href );
- event.element = anchor;
- event.toolbar = toolbar;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $ ) {
+ $( input )
+ .on( 'keydown', function() {
+ $( input ).removeAttr( 'aria-activedescendant' );
+ } )
+ .autocomplete( {
+ source: function( request, response ) {
+ if ( last === request.term ) {
+ response( cache );
+ return;
+ }
+
+ if ( /^https?:/.test( request.term ) || request.term.indexOf( '.' ) !== -1 ) {
+ return response();
+ }
+
+ $.post( window.ajaxurl, {
+ action: 'wp-link-ajax',
+ page: 1,
+ search: request.term,
+ _ajax_linking_nonce: $( '#_ajax_linking_nonce' ).val()
+ }, function( data ) {
+ cache = data;
+ response( data );
+ }, 'json' );
+
+ last = request.term;
+ },
+ focus: function( event, ui ) {
+ $( input ).attr( 'aria-activedescendant', 'mce-wp-autocomplete-' + ui.item.ID );
+ },
+ select: function( event, ui ) {
+ $( input ).val( ui.item.permalink );
+ return false;
+ },
+ open: function() {
+ $( input ).attr( 'aria-expanded', 'true' );
+ editToolbar.blockHide = true;
+ },
+ close: function() {
+ $( input ).attr( 'aria-expanded', 'false' );
+ editToolbar.blockHide = false;
+ },
+ minLength: 2,
+ position: {
+ my: 'left top+5'
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } ).autocomplete( 'instance' )._renderItem = function( ul, item ) {
+ return $( '<li role="option" id="mce-wp-autocomplete-' + item.ID + '">' )
+ .append( '<span>' + item.title + '</span> <span class="alignright">' + item.info + '</span>' )
+ .appendTo( ul );
+ };
+
+ $( input )
+ .attr( {
+ 'role': 'combobox',
+ 'aria-autocomplete': 'list',
+ 'aria-expanded': 'false',
+ 'aria-owns': $( input ).autocomplete( 'widget' ).attr( 'id' )
+ } )
+ .on( 'focus', function() {
+ $( input ).autocomplete( 'search' );
+ } )
+ .autocomplete( 'widget' )
+ .addClass( 'mce-wp-autocomplete' )
+ .attr( 'role', 'listbox' );
+ }
+
+ tinymce.$( input ).on( 'keydown', function( event ) {
+ event.keyCode === 13 && editor.execCommand( 'wp_link_apply' );
</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="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ editor.on( 'wptoolbar', function( event ) {
+ var anchor = editor.dom.getParent( event.element, 'a' ),
+ $anchor,
+ href, edit;
+
+ if ( anchor ) {
+ $anchor = editor.$( anchor );
+ href = $anchor.attr( 'href' );
+ edit = $anchor.attr( 'data-wp-edit' );
+
+ if ( href === '_wp_link_placeholder' || edit ) {
+ inputInstance.setURL( edit ? href : '' );
+ event.element = anchor;
+ event.toolbar = editToolbar;
+ } else if ( href && ! $anchor.find( 'img' ).length ) {
+ previewInstance.setURL( href );
+ event.element = anchor;
+ event.toolbar = toolbar;
+ }
+ }
+ } );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> editor.addButton( 'wp_link_edit', {
</span><span class="cx" style="display: block; padding: 0 10px"> tooltip: 'Edit ', // trailing space is needed, used for context
</span><span class="cx" style="display: block; padding: 0 10px"> icon: 'dashicon dashicons-edit',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -135,14 +316,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> cmd: 'unlink'
</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">- editor.on( 'preinit', function() {
- if ( editor.wp && editor.wp._createToolbar ) {
- toolbar = editor.wp._createToolbar( [
- 'wp_link_preview',
- 'wp_link_edit',
- 'wp_link_remove'
- ], true );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Advanced, more, options?
+ editor.addButton( 'wp_link_advanced', {
+ tooltip: 'Advanced',
+ icon: 'dashicon dashicons-admin-generic',
+ onclick: function() {
+ editor.execCommand( 'wp_link_apply' );
+ 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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ editor.addButton( 'wp_link_apply', {
+ tooltip: 'Apply',
+ icon: 'dashicon dashicons-editor-break',
+ cmd: 'wp_link_apply',
+ classes: 'widget btn primary'
+ } );
</ins><span class="cx" style="display: block; padding: 0 10px"> } );
</span><span class="cx" style="display: block; padding: 0 10px"> } )( window.tinymce );
</span></span></pre>
</div>
</div>
</body>
</html>