TinyMCE: wplink: fix WPLinkPreview for multiple editors
Fixes #33264. Built from https://develop.svn.wordpress.org/trunk@33584 git-svn-id: http://core.svn.wordpress.org/trunk@33551 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
2fbdeae0a8
commit
34d50e6165
|
@ -1,4 +1,52 @@
|
|||
/* global tinymce */
|
||||
( function( tinymce ) {
|
||||
tinymce.ui.WPLinkPreview = tinymce.ui.Control.extend( {
|
||||
url: '#',
|
||||
renderHtml: function() {
|
||||
return (
|
||||
'<div id="' + this._id + '" class="wp-link-preview">' +
|
||||
'<a href="' + this.url + '" target="_blank" tabindex="-1">' + this.url + '</a>' +
|
||||
'</div>'
|
||||
);
|
||||
},
|
||||
setURL: function( url ) {
|
||||
var index, lastIndex;
|
||||
|
||||
if ( this.url !== url ) {
|
||||
this.url = url;
|
||||
|
||||
url = window.decodeURIComponent( url );
|
||||
|
||||
url = url.replace( /^(?:https?:)?\/\/(?:www\.)?/, '' );
|
||||
|
||||
if ( ( index = url.indexOf( '?' ) ) !== -1 ) {
|
||||
url = url.slice( 0, index );
|
||||
}
|
||||
|
||||
if ( ( index = url.indexOf( '#' ) ) !== -1 ) {
|
||||
url = url.slice( 0, index );
|
||||
}
|
||||
|
||||
url = url.replace( /(?:index)?\.html$/, '' );
|
||||
|
||||
if ( url.charAt( url.length - 1 ) === '/' ) {
|
||||
url = url.slice( 0, -1 );
|
||||
}
|
||||
|
||||
// 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.slice( 0, index + 1 ) + '\u2026' + url.slice( lastIndex );
|
||||
}
|
||||
|
||||
tinymce.$( this.getEl().firstChild ).attr( 'href', this.url ).text( url );
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
tinymce.PluginManager.add( 'wplink', function( editor ) {
|
||||
var toolbar;
|
||||
|
||||
|
@ -51,67 +99,26 @@ tinymce.PluginManager.add( 'wplink', function( editor ) {
|
|||
}
|
||||
} );
|
||||
|
||||
tinymce.ui.WPLinkPreview = tinymce.ui.Control.extend( {
|
||||
url: '#',
|
||||
renderHtml: function() {
|
||||
return (
|
||||
'<div id="' + this._id + '" class="wp-link-preview">' +
|
||||
'<a href="' + this.url + '" target="_blank" tabindex="-1">' + this.url + '</a>' +
|
||||
'</div>'
|
||||
);
|
||||
},
|
||||
setURL: function( url ) {
|
||||
var index, lastIndex;
|
||||
|
||||
if ( this.url !== url ) {
|
||||
this.url = url;
|
||||
|
||||
url = window.decodeURIComponent( url );
|
||||
|
||||
url = url.replace( /^(?:https?:)?\/\/(?:www\.)?/, '' );
|
||||
|
||||
if ( ( index = url.indexOf( '?' ) ) !== -1 ) {
|
||||
url = url.slice( 0, index );
|
||||
}
|
||||
|
||||
if ( ( index = url.indexOf( '#' ) ) !== -1 ) {
|
||||
url = url.slice( 0, index );
|
||||
}
|
||||
|
||||
url = url.replace( /(?:index)?\.html$/, '' );
|
||||
|
||||
if ( url.charAt( url.length - 1 ) === '/' ) {
|
||||
url = url.slice( 0, -1 );
|
||||
}
|
||||
|
||||
// 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.slice( 0, index + 1 ) + '\u2026' + url.slice( lastIndex );
|
||||
}
|
||||
|
||||
tinymce.$( this.getEl().firstChild ).attr( 'href', this.url ).text( url );
|
||||
}
|
||||
},
|
||||
postRender: function() {
|
||||
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' ),
|
||||
$ = editor.$,
|
||||
$anchor,
|
||||
href;
|
||||
|
||||
if ( anchor && ! $( anchor ).find( 'img' ).length &&
|
||||
( href = $( anchor ).attr( '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;
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
} );
|
||||
|
@ -130,9 +137,10 @@ tinymce.PluginManager.add( 'wplink', function( editor ) {
|
|||
|
||||
editor.on( 'preinit', function() {
|
||||
toolbar = editor.wp._createToolbar( [
|
||||
'WPLinkPreview',
|
||||
'wp_link_preview',
|
||||
'wp_link_edit',
|
||||
'wp_link_remove'
|
||||
], true );
|
||||
} );
|
||||
} );
|
||||
} )( window.tinymce );
|
||||
|
|
|
@ -1 +1 @@
|
|||
tinymce.PluginManager.add("wplink",function(a){var b;a.addCommand("WP_Link",function(){window.wpLink&&window.wpLink.open(a.id)}),a.addShortcut("Alt+Shift+A","","WP_Link"),a.addShortcut("Meta+K","","WP_Link"),a.addButton("link",{icon:"link",tooltip:"Insert/edit link",cmd:"WP_Link",stateSelector:"a[href]"}),a.addButton("unlink",{icon:"unlink",tooltip:"Remove link",cmd:"unlink"}),a.addMenuItem("link",{icon:"link",text:"Insert/edit link",cmd:"WP_Link",stateSelector:"a[href]",context:"insert",prependToContext:!0}),a.on("pastepreprocess",function(b){var c=b.content,d=/^(?:https?:)?\/\/\S+$/i;a.selection.isCollapsed()||d.test(a.selection.getContent())||(c=c.replace(/<[^>]+>/g,""),c=tinymce.trim(c),d.test(c)&&(a.execCommand("mceInsertLink",!1,{href:a.dom.decode(c)}),b.preventDefault()))}),tinymce.ui.WPLinkPreview=tinymce.ui.Control.extend({url:"#",renderHtml:function(){return'<div id="'+this._id+'" class="wp-link-preview"><a href="'+this.url+'" target="_blank" tabindex="-1">'+this.url+"</a></div>"},setURL:function(a){var b,c;this.url!==a&&(this.url=a,a=window.decodeURIComponent(a),a=a.replace(/^(?:https?:)?\/\/(?:www\.)?/,""),-1!==(b=a.indexOf("?"))&&(a=a.slice(0,b)),-1!==(b=a.indexOf("#"))&&(a=a.slice(0,b)),a=a.replace(/(?:index)?\.html$/,""),"/"===a.charAt(a.length-1)&&(a=a.slice(0,-1)),a.length>40&&-1!==(b=a.indexOf("/"))&&-1!==(c=a.lastIndexOf("/"))&&c!==b&&(b+a.length-c<40&&(c=-(40-(b+1))),a=a.slice(0,b+1)+"\u2026"+a.slice(c)),tinymce.$(this.getEl().firstChild).attr("href",this.url).text(a))},postRender:function(){var c=this;a.on("wptoolbar",function(d){var e,f=a.dom.getParent(d.element,"a"),g=a.$;f&&!g(f).find("img").length&&(e=g(f).attr("href"))&&(c.setURL(e),d.element=f,d.toolbar=b)})}}),a.addButton("wp_link_edit",{tooltip:"Edit ",icon:"dashicon dashicons-edit",cmd:"WP_Link"}),a.addButton("wp_link_remove",{tooltip:"Remove",icon:"dashicon dashicons-no",cmd:"unlink"}),a.on("preinit",function(){b=a.wp._createToolbar(["WPLinkPreview","wp_link_edit","wp_link_remove"],!0)})});
|
||||
!function(a){a.ui.WPLinkPreview=a.ui.Control.extend({url:"#",renderHtml:function(){return'<div id="'+this._id+'" class="wp-link-preview"><a href="'+this.url+'" target="_blank" tabindex="-1">'+this.url+"</a></div>"},setURL:function(b){var c,d;this.url!==b&&(this.url=b,b=window.decodeURIComponent(b),b=b.replace(/^(?:https?:)?\/\/(?:www\.)?/,""),-1!==(c=b.indexOf("?"))&&(b=b.slice(0,c)),-1!==(c=b.indexOf("#"))&&(b=b.slice(0,c)),b=b.replace(/(?:index)?\.html$/,""),"/"===b.charAt(b.length-1)&&(b=b.slice(0,-1)),b.length>40&&-1!==(c=b.indexOf("/"))&&-1!==(d=b.lastIndexOf("/"))&&d!==c&&(c+b.length-d<40&&(d=-(40-(c+1))),b=b.slice(0,c+1)+"\u2026"+b.slice(d)),a.$(this.getEl().firstChild).attr("href",this.url).text(b))}}),a.PluginManager.add("wplink",function(b){var c;b.addCommand("WP_Link",function(){window.wpLink&&window.wpLink.open(b.id)}),b.addShortcut("Alt+Shift+A","","WP_Link"),b.addShortcut("Meta+K","","WP_Link"),b.addButton("link",{icon:"link",tooltip:"Insert/edit link",cmd:"WP_Link",stateSelector:"a[href]"}),b.addButton("unlink",{icon:"unlink",tooltip:"Remove link",cmd:"unlink"}),b.addMenuItem("link",{icon:"link",text:"Insert/edit link",cmd:"WP_Link",stateSelector:"a[href]",context:"insert",prependToContext:!0}),b.on("pastepreprocess",function(c){var d=c.content,e=/^(?:https?:)?\/\/\S+$/i;b.selection.isCollapsed()||e.test(b.selection.getContent())||(d=d.replace(/<[^>]+>/g,""),d=a.trim(d),e.test(d)&&(b.execCommand("mceInsertLink",!1,{href:b.dom.decode(d)}),c.preventDefault()))}),b.addButton("wp_link_preview",{type:"WPLinkPreview",onPostRender:function(){var a=this;b.on("wptoolbar",function(d){var e,f,g=b.dom.getParent(d.element,"a");g&&(e=b.$(g),f=e.attr("href"),f&&!e.find("img").length&&(a.setURL(f),d.element=g,d.toolbar=c))})}}),b.addButton("wp_link_edit",{tooltip:"Edit ",icon:"dashicon dashicons-edit",cmd:"WP_Link"}),b.addButton("wp_link_remove",{tooltip:"Remove",icon:"dashicon dashicons-no",cmd:"unlink"}),b.on("preinit",function(){c=b.wp._createToolbar(["wp_link_preview","wp_link_edit","wp_link_remove"],!0)})})}(window.tinymce);
|
Binary file not shown.
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.3-RC2-33572';
|
||||
$wp_version = '4.3-RC2-33584';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue