Index: src/wp-includes/css/editor.css
===================================================================
--- src/wp-includes/css/editor.css (revision 33563)
+++ src/wp-includes/css/editor.css (working copy)
@@ -1683,7 +1683,7 @@
div.wp-link-preview {
float: left;
margin: 5px;
- max-width: 694px;
+ max-width: 350px;
overflow: hidden;
text-overflow: ellipsis;
}
Index: src/wp-includes/js/tinymce/plugins/wplink/plugin.js
===================================================================
--- src/wp-includes/js/tinymce/plugins/wplink/plugin.js (revision 33563)
+++ src/wp-includes/js/tinymce/plugins/wplink/plugin.js (working copy)
@@ -1,138 +1,160 @@
-/* global tinymce */
-tinymce.PluginManager.add( 'wplink', function( editor ) {
- var toolbar;
-
- editor.addCommand( 'WP_Link', function() {
- window.wpLink && window.wpLink.open( editor.id );
- });
-
- // WP default shortcut
- editor.addShortcut( 'Alt+Shift+A', '', 'WP_Link' );
- // The "de-facto standard" shortcut, see #27305
- editor.addShortcut( 'Meta+K', '', 'WP_Link' );
-
- editor.addButton( 'link', {
- icon: 'link',
- tooltip: 'Insert/edit link',
- cmd: 'WP_Link',
- stateSelector: 'a[href]'
- });
-
- editor.addButton( 'unlink', {
- icon: 'unlink',
- tooltip: 'Remove link',
- cmd: 'unlink'
- });
-
- editor.addMenuItem( 'link', {
- icon: 'link',
- text: 'Insert/edit link',
- cmd: 'WP_Link',
- stateSelector: 'a[href]',
- context: 'insert',
- prependToContext: true
- });
-
- editor.on( 'pastepreprocess', function( event ) {
- var pastedStr = event.content,
- regExp = /^(?:https?:)?\/\/\S+$/i;
-
- if ( ! editor.selection.isCollapsed() && ! regExp.test( editor.selection.getContent() ) ) {
- pastedStr = pastedStr.replace( /<[^>]+>/g, '' );
- pastedStr = tinymce.trim( pastedStr );
-
- if ( regExp.test( pastedStr ) ) {
- editor.execCommand( 'mceInsertLink', false, {
- href: editor.dom.decode( pastedStr )
- } );
-
- event.preventDefault();
- }
- }
- } );
-
+( function( tinymce ) {
tinymce.ui.WPLinkPreview = tinymce.ui.Control.extend( {
url: '#',
renderHtml: function() {
- return (
- '
'
- );
+ return '';
},
- setURL: function( url ) {
+ prettyURL: function( url ) {
var index, lastIndex;
- if ( this.url !== url ) {
- this.url = url;
-
- url = window.decodeURIComponent( url );
-
- url = url.replace( /^(?:https?:)?\/\/(?:www\.)?/, '' );
+ url = window.decodeURIComponent( url );
- if ( ( index = url.indexOf( '?' ) ) !== -1 ) {
- url = url.slice( 0, index );
- }
+ index = url.indexOf( '?' );
- if ( ( index = url.indexOf( '#' ) ) !== -1 ) {
- url = url.slice( 0, index );
- }
+ if ( index === 0 ) {
+ return url;
+ } else if ( index !== -1 ) {
+ url = url.slice( 0, index );
+ }
- url = url.replace( /(?:index)?\.html$/, '' );
+ index = url.indexOf( '#' );
- if ( url.charAt( url.length - 1 ) === '/' ) {
- url = url.slice( 0, -1 );
- }
+ if ( index === 0 ) {
+ return url;
+ } else if ( index !== -1 ) {
+ url = url.slice( 0, index );
+ }
- // If the URL is longer that 40 chars, concatenate the beginning (after the domain) and ending with ...
- if ( url.length > 40 && ( index = url.indexOf( '/' ) ) !== -1 && ( lastIndex = url.lastIndexOf( '/' ) ) !== -1 && lastIndex !== index ) {
- // If the beginning + ending are shorter that 40 chars, show more of the ending
- if ( index + url.length - lastIndex < 40 ) {
- lastIndex = -( 40 - ( index + 1 ) );
- }
+ url = url.replace( /^(?:https?:)?\/\/(?:www\.)?/, '' );
+ url = url.replace( /(?:index)?\.html$/, '' );
- url = url.slice( 0, index + 1 ) + '\u2026' + url.slice( lastIndex );
- }
+ if ( url.charAt( url.length - 1 ) === '/' ) {
+ url = url.slice( 0, -1 );
+ }
- tinymce.$( this.getEl().firstChild ).attr( 'href', this.url ).text( url );
+ if ( ( index = url.indexOf( '/' ) ) !== -1 && ( lastIndex = url.lastIndexOf( '/' ) ) !== -1 && lastIndex !== index ) {
+ url = url.slice( 0, index + 1 ) + '\u2026' + url.slice( lastIndex );
}
+
+ return url;
},
- postRender: function() {
- var self = this;
+ setURL: function( url ) {
+ var $ = tinymce.$,
+ $element;
- editor.on( 'wptoolbar', function( event ) {
- var anchor = editor.dom.getParent( event.element, 'a' ),
- $ = editor.$,
- href;
-
- if ( anchor && ! $( anchor ).find( 'img' ).length &&
- ( href = $( anchor ).attr( 'href' ) ) ) {
-
- self.setURL( href );
- event.element = anchor;
- event.toolbar = toolbar;
+ if ( this.url !== url ) {
+ this.url = url;
+
+ if ( url.indexOf( '#' ) === 0 || url.indexOf( '?' ) === 0 ) {
+ $element = $( document.createElement( 'span' ) );
+ } else {
+ $element = $( document.createElement( 'a' ) );
+ $element.attr( 'href', this.url );
+ $element.attr( 'target', '_blank' );
+ $element.attr( 'tabindex', '-1' );
}
- } );
+
+ $element.text( this.prettyURL( url ) );
+
+ $( this.getEl() ).empty().append( $element );
+ }
}
} );
- editor.addButton( 'wp_link_edit', {
- tooltip: 'Edit ', // trailing space is needed, used for context
- icon: 'dashicon dashicons-edit',
- cmd: 'WP_Link'
- } );
+ tinymce.PluginManager.add( 'wplink', function( editor ) {
+ var toolbar;
- editor.addButton( 'wp_link_remove', {
- tooltip: 'Remove',
- icon: 'dashicon dashicons-no',
- cmd: 'unlink'
- } );
+ editor.addCommand( 'WP_Link', function() {
+ window.wpLink && window.wpLink.open( editor.id );
+ });
+
+ // WP default shortcut
+ editor.addShortcut( 'Alt+Shift+A', '', 'WP_Link' );
+ // The "de-facto standard" shortcut, see #27305
+ editor.addShortcut( 'Meta+K', '', 'WP_Link' );
+
+ editor.addButton( 'link', {
+ icon: 'link',
+ tooltip: 'Insert/edit link',
+ cmd: 'WP_Link',
+ stateSelector: 'a[href]'
+ });
+
+ editor.addButton( 'unlink', {
+ icon: 'unlink',
+ tooltip: 'Remove link',
+ cmd: 'unlink'
+ });
+
+ editor.addMenuItem( 'link', {
+ icon: 'link',
+ text: 'Insert/edit link',
+ cmd: 'WP_Link',
+ stateSelector: 'a[href]',
+ context: 'insert',
+ prependToContext: true
+ });
+
+ editor.on( 'pastepreprocess', function( event ) {
+ var pastedStr = event.content,
+ regExp = /^(?:https?:)?\/\/\S+$/i;
+
+ if ( ! editor.selection.isCollapsed() && ! regExp.test( editor.selection.getContent() ) ) {
+ pastedStr = pastedStr.replace( /<[^>]+>/g, '' );
+ pastedStr = tinymce.trim( pastedStr );
+
+ if ( regExp.test( pastedStr ) ) {
+ editor.execCommand( 'mceInsertLink', false, {
+ href: editor.dom.decode( pastedStr )
+ } );
+
+ event.preventDefault();
+ }
+ }
+ } );
+
+ editor.addButton( 'wp_link_preview', {
+ type: 'WPLinkPreview',
+ onPostRender: function() {
+ var self = this;
+
+ editor.on( 'wptoolbar', function( event ) {
+ var anchor = editor.dom.getParent( event.element, 'a' ),
+ $anchor,
+ href;
+
+ if ( anchor ) {
+ $anchor = editor.$( anchor );
+ href = $anchor.attr( 'href' );
+
+ if ( href && ! $anchor.find( 'img' ).length ) {
+ self.setURL( href );
+ event.element = anchor;
+ event.toolbar = toolbar;
+ }
+ }
+ } );
+ }
+ } );
- editor.on( 'preinit', function() {
- toolbar = editor.wp._createToolbar( [
- 'WPLinkPreview',
- 'wp_link_edit',
- 'wp_link_remove'
- ], true );
+ editor.addButton( 'wp_link_edit', {
+ tooltip: 'Edit ', // trailing space is needed, used for context
+ icon: 'dashicon dashicons-edit',
+ cmd: 'WP_Link'
+ } );
+
+ editor.addButton( 'wp_link_remove', {
+ tooltip: 'Remove',
+ icon: 'dashicon dashicons-no',
+ cmd: 'unlink'
+ } );
+
+ editor.on( 'preinit', function() {
+ toolbar = editor.wp._createToolbar( [
+ 'wp_link_preview',
+ 'wp_link_edit',
+ 'wp_link_remove'
+ ], true );
+ } );
} );
-});
+} )( window.tinymce );
Index: tests/qunit/index.html
===================================================================
--- tests/qunit/index.html (revision 33563)
+++ tests/qunit/index.html (working copy)
@@ -377,7 +377,9 @@
+
+