Use wpLink in the HTML editor too, props koopersmith, fixes #16631

git-svn-id: http://svn.automattic.com/wordpress/trunk@17687 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2011-04-23 02:12:56 +00:00
parent 0a5a01e991
commit 4f9f5f1765
9 changed files with 247 additions and 104 deletions

View File

@ -360,19 +360,23 @@ function edInsertContent(myField, myValue) {
}
function edInsertLink(myField, i, defaultValue) {
if (!defaultValue) {
defaultValue = 'http://';
}
if (!edCheckOpenTags(i)) {
var URL = prompt(quicktagsL10n.enterURL, defaultValue);
if (URL) {
edButtons[i].tagStart = '<a href="' + URL + '">';
if ( 'object' == typeof(wpLink) ) {
wpLink.open();
} else {
if (!defaultValue) {
defaultValue = 'http://';
}
if (!edCheckOpenTags(i)) {
var URL = prompt(quicktagsL10n.enterURL, defaultValue);
if (URL) {
edButtons[i].tagStart = '<a href="' + URL + '">';
edInsertTag(myField, i);
}
}
else {
edInsertTag(myField, i);
}
}
else {
edInsertTag(myField, i);
}
}
function edInsertImage(myField) {

File diff suppressed because one or more lines are too long

View File

@ -8,18 +8,56 @@
* Contributing: http://tinymce.moxiecode.com/contributing
*/
(function($) {
var wpDialogFn = function( fn ) {
return function() {
if ( this.features.wpDialog )
return fn.apply( this, arguments );
else
return this.parent.apply( this, arguments );
};
};
(function() {
tinymce.create('tinymce.plugins.WPDialogs', {
init : function(ed, url) {
tinymce.create('tinymce.WPWindowManager:tinymce.InlineWindowManager', {
WPWindowManager : function(ed) {
this.parent(ed);
},
open : function(f, p) {
var t = this, element;
if ( ! f.wpDialog )
return this.parent( f, p );
else if ( ! f.id )
return;
element = jQuery('#' + f.id);
if ( ! element.length )
return;
t.features = f;
t.params = p;
t.onOpen.dispatch(t, f, p);
t.element = t.windows[ f.id ] = element;
// Store selection
t.bookmark = t.editor.selection.getBookmark(1);
// Create the dialog if necessary
if ( ! element.data('wpdialog') ) {
element.wpdialog({
title: f.title,
width: f.width,
height: f.height,
modal: true,
dialogClass: 'wp-dialog',
zIndex: 300000
});
}
element.wpdialog('open');
},
close : function() {
if ( ! this.features.wpDialog )
return this.parent.apply( this, arguments );
this.element.wpdialog('close');
}
});
// Replace window manager
ed.onBeforeRenderUI.add(function() {
ed.windowManager = new tinymce.WPWindowManager(ed);
@ -36,62 +74,7 @@
};
}
});
$(document).ready(function() {
$.widget("wp.wpdialog", $.ui.dialog, {
open: function() {
// Initialize tinyMCEPopup if it exists.
if ( tinyMCEPopup )
tinyMCEPopup.init();
// Open the dialog.
$.ui.dialog.prototype.open.apply( this, arguments );
// WebKit leaves focus in the TinyMCE editor unless we shift focus.
this.element.focus();
this._trigger('refresh');
}
});
});
tinymce.create('tinymce.WPWindowManager:tinymce.InlineWindowManager', {
WPWindowManager : function(ed) {
this.parent(ed);
},
open : function(f, p) {
var t = this, element;
// Can't use wpDialogFn here; this.features isn't set yet.
if ( ! f.wpDialog )
return this.parent( f, p );
else if ( ! f.id )
return;
element = $('#' + f.id);
if ( ! element.length )
return;
t.features = f;
t.params = p;
t.onOpen.dispatch(t, f, p);
t.element = t.windows[ f.id ] = element;
// Store selection
t.bookmark = t.editor.selection.getBookmark(1);
element.wpdialog({
title: f.title,
width: f.width,
height: f.height,
modal: true,
dialogClass: 'wp-dialog',
zIndex: 300000
});
},
close : wpDialogFn(function() {
this.element.wpdialog('close');
})
});
// Register plugin
tinymce.PluginManager.add('wpdialogs', tinymce.plugins.WPDialogs);
})(jQuery);
})();

View File

@ -1 +1 @@
(function(b){var a=function(c){return function(){if(this.features.wpDialog){return c.apply(this,arguments)}else{return this.parent.apply(this,arguments)}}};tinymce.create("tinymce.plugins.WPDialogs",{init:function(c,d){c.onBeforeRenderUI.add(function(){c.windowManager=new tinymce.WPWindowManager(c)})},getInfo:function(){return{longname:"WPDialogs",author:"WordPress",authorurl:"http://wordpress.org",infourl:"http://wordpress.org",version:"0.1"}}});b(document).ready(function(){b.widget("wp.wpdialog",b.ui.dialog,{open:function(){if(tinyMCEPopup){tinyMCEPopup.init()}b.ui.dialog.prototype.open.apply(this,arguments);this.element.focus();this._trigger("refresh")}})});tinymce.create("tinymce.WPWindowManager:tinymce.InlineWindowManager",{WPWindowManager:function(c){this.parent(c)},open:function(e,g){var d=this,c;if(!e.wpDialog){return this.parent(e,g)}else{if(!e.id){return}}c=b("#"+e.id);if(!c.length){return}d.features=e;d.params=g;d.onOpen.dispatch(d,e,g);d.element=d.windows[e.id]=c;d.bookmark=d.editor.selection.getBookmark(1);c.wpdialog({title:e.title,width:e.width,height:e.height,modal:true,dialogClass:"wp-dialog",zIndex:300000})},close:a(function(){this.element.wpdialog("close")})});tinymce.PluginManager.add("wpdialogs",tinymce.plugins.WPDialogs)})(jQuery);
(function(){tinymce.create("tinymce.plugins.WPDialogs",{init:function(a,b){tinymce.create("tinymce.WPWindowManager:tinymce.InlineWindowManager",{WPWindowManager:function(c){this.parent(c)},open:function(e,g){var d=this,c;if(!e.wpDialog){return this.parent(e,g)}else{if(!e.id){return}}c=jQuery("#"+e.id);if(!c.length){return}d.features=e;d.params=g;d.onOpen.dispatch(d,e,g);d.element=d.windows[e.id]=c;d.bookmark=d.editor.selection.getBookmark(1);if(!c.data("wpdialog")){c.wpdialog({title:e.title,width:e.width,height:e.height,modal:true,dialogClass:"wp-dialog",zIndex:300000})}c.wpdialog("open")},close:function(){if(!this.features.wpDialog){return this.parent.apply(this,arguments)}this.element.wpdialog("close")}});a.onBeforeRenderUI.add(function(){a.windowManager=new tinymce.WPWindowManager(a)})},getInfo:function(){return{longname:"WPDialogs",author:"WordPress",authorurl:"http://wordpress.org",infourl:"http://wordpress.org",version:"0.1"}}});tinymce.PluginManager.add("wpdialogs",tinymce.plugins.WPDialogs)})();

View File

@ -0,0 +1,23 @@
(function($){
$.widget("wp.wpdialog", $.ui.dialog, {
open: function() {
var ed;
// Initialize tinyMCEPopup if it exists and is the editor is active.
if ( tinyMCEPopup && typeof tinyMCE != 'undefined' && ( ed = tinyMCE.activeEditor ) && !ed.isHidden() ) {
tinyMCEPopup.init();
}
// Add beforeOpen event.
if ( this._isOpen || false === this._trigger('beforeOpen') ) {
return;
}
// Open the dialog.
$.ui.dialog.prototype.open.apply( this, arguments );
// WebKit leaves focus in the TinyMCE editor unless we shift focus.
this.element.focus();
this._trigger('refresh');
}
});
})(jQuery);

View File

@ -0,0 +1 @@
(function(a){a.widget("wp.wpdialog",a.ui.dialog,{open:function(){var b;if(tinyMCEPopup&&typeof tinyMCE!="undefined"&&(b=tinyMCE.activeEditor)&&!b.isHidden()){tinyMCEPopup.init()}if(this._isOpen||false===this._trigger("beforeOpen")){return}a.ui.dialog.prototype.open.apply(this,arguments);this.element.focus();this._trigger("refresh")}})})(jQuery);

View File

@ -9,6 +9,8 @@ var wpLink;
riverBottomThreshold: 5,
keySensitivity: 100,
lastSearch: '',
textarea: edCanvas,
init : function() {
inputs.dialog = $('#wp-link');
inputs.submit = $('#wp-link-submit');
@ -31,7 +33,7 @@ var wpLink;
wpLink.update();
e.preventDefault();
});
$('#wp-link-cancel').click( wpLink.cancel );
$('#wp-link-cancel').click( wpLink.close );
$('#internal-toggle').click( wpLink.toggleInternalLinking );
rivers.elements.bind('river-select', wpLink.updateFields );
@ -39,16 +41,62 @@ var wpLink;
inputs.search.keyup( wpLink.searchInternalLinks );
inputs.dialog.bind('wpdialogrefresh', wpLink.refresh);
inputs.dialog.bind('wpdialogbeforeopen', wpLink.beforeOpen);
inputs.dialog.bind('wpdialogclose', wpLink.onClose);
},
beforeOpen : function() {
wpLink.range = null;
if ( ! wpLink.isMCE() && document.selection ) {
wpLink.textarea.focus();
wpLink.range = document.selection.createRange();
}
},
open : function() {
// Initialize the dialog if necessary (html mode).
if ( ! inputs.dialog.data('wpdialog') ) {
inputs.dialog.wpdialog({
title: wpLinkL10n.title,
width: 480,
height: 'auto',
modal: true,
dialogClass: 'wp-dialog',
zIndex: 300000
});
}
inputs.dialog.wpdialog('open');
},
isMCE : function() {
return tinyMCEPopup && ( ed = tinyMCEPopup.editor ) && ! ed.isHidden();
},
refresh : function() {
var e;
ed = tinyMCEPopup.editor;
// Refresh rivers (clear links, check visibility)
rivers.search.refresh();
rivers.recent.refresh();
if ( wpLink.isMCE() )
wpLink.mceRefresh();
else
wpLink.setDefaultValues();
// Focus the URL field and highlight its contents.
// If this is moved above the selection changes,
// IE will show a flashing cursor over the dialog.
inputs.url.focus()[0].select();
// Load the most recent results if this is the first time opening the panel.
if ( ! rivers.recent.ul.children().length )
rivers.recent.ajax();
},
mceRefresh : function() {
var e;
ed = tinyMCEPopup.editor;
tinyMCEPopup.restoreSelection();
// If link exists, select proper values.
@ -65,31 +113,106 @@ var wpLink;
// If there's no link, set the default values.
} else {
wpLink.setDefaultValues();
// Update save prompt.
inputs.submit.val( wpLinkL10n.save );
}
tinyMCEPopup.storeSelection();
// Focus the URL field and highlight its contents.
// If this is moved above the selection changes,
// IE will show a flashing cursor over the dialog.
inputs.url.focus()[0].select();
// Load the most recent results if this is the first time opening the panel.
if ( ! rivers.recent.ul.children().length )
rivers.recent.ajax();
},
cancel : function() {
tinyMCEPopup.close();
close : function() {
if ( wpLink.isMCE() )
tinyMCEPopup.close();
else
inputs.dialog.wpdialog('close');
},
onClose: function() {
if ( ! wpLink.isMCE() ) {
wpLink.textarea.focus();
if ( wpLink.range ) {
wpLink.range.moveToBookmark( wpLink.range.getBookmark() );
wpLink.range.select();
}
}
},
getAttrs : function() {
return {
href : inputs.url.val(),
title : inputs.title.val(),
target : inputs.openInNewTab.attr('checked') ? '_blank' : ''
};
},
update : function() {
if ( wpLink.isMCE() )
wpLink.mceUpdate();
else
wpLink.htmlUpdate();
},
htmlUpdate : function() {
var attrs, html, start, end, cursor,
textarea = wpLink.textarea;
if ( ! textarea )
return;
attrs = wpLink.getAttrs();
// If there's no href, return.
if ( ! attrs.href || attrs.href == 'http://' )
return;
// Build HTML
html = '<a href="' + attrs.href + '"';
if ( attrs.title )
html += ' title="' + attrs.title + '"';
if ( attrs.target )
html += ' target="' + attrs.target + '"';
html += '>';
// Insert HTML
// W3C
if ( typeof textarea.selectionStart !== 'undefined' ) {
start = textarea.selectionStart;
end = textarea.selectionEnd;
selection = textarea.value.substring( start, end );
html = html + selection + '</a>';
cursor = start + html.length;
// If no next is selected, place the cursor inside the closing tag.
if ( start == end )
cursor -= '</a>'.length;
textarea.value = textarea.value.substring( 0, start )
+ html
+ textarea.value.substring( end, textarea.value.length );
// Update cursor position
textarea.selectionStart = textarea.selectionEnd = cursor;
// IE
// Note: If no text is selected, IE will not place the cursor
// inside the closing tag.
} else if ( document.selection && wpLink.range ) {
textarea.focus();
wpLink.range.text = html + wpLink.range.text + '</a>';
wpLink.range.moveToBookmark( wpLink.range.getBookmark() );
wpLink.range.select();
wpLink.range = null;
}
wpLink.close();
textarea.focus();
},
mceUpdate : function() {
var ed = tinyMCEPopup.editor,
attrs = {
href : inputs.url.val(),
title : inputs.title.val(),
target : inputs.openInNewTab.attr('checked') ? '_blank' : ''
}, e, b;
attrs = wpLink.getAttrs(),
e, b;
tinyMCEPopup.restoreSelection();
e = ed.dom.getParent(ed.selection.getNode(), 'A');
@ -102,7 +225,7 @@ var wpLink;
ed.dom.remove(e, 1);
ed.selection.moveToBookmark(b);
tinyMCEPopup.execCommand("mceEndUndoLevel");
tinyMCEPopup.close();
wpLink.close();
}
return;
}
@ -140,7 +263,7 @@ var wpLink;
}
tinyMCEPopup.execCommand("mceEndUndoLevel");
tinyMCEPopup.close();
wpLink.close();
},
updateFields : function( e, li, originalEvent ) {
@ -154,6 +277,9 @@ var wpLink;
// Leave the new tab setting as-is.
inputs.url.val('http://');
inputs.title.val('');
// Update save prompt.
inputs.submit.val( wpLinkL10n.save );
},
searchInternalLinks : function() {
@ -210,7 +336,7 @@ var wpLink;
switch( event.which ) {
case key.ESCAPE:
wpLink.cancel();
wpLink.close();
break;
case key.UP:
case key.DOWN:

File diff suppressed because one or more lines are too long

View File

@ -267,8 +267,10 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'admin-bar', "/wp-includes/js/admin-bar$suffix.js", false, '20110131' );
$scripts->add_data( 'admin-bar', 'group', 1 );
$scripts->add( 'wplink', "/wp-includes/js/tinymce/plugins/wplink/js/wplink$suffix.js", array('jquery'), '20110111' );
$scripts->add( 'wplink', "/wp-includes/js/tinymce/plugins/wplink/js/wplink$suffix.js", array( 'jquery', 'wpdialogs' ), '20110421' );
$scripts->add_data( 'wplink', 'group', 1 );
$scripts->localize( 'wplink', 'wpLinkL10n', array(
'title' => __('Insert/edit link'),
'update' => __('Update'),
'save' => __('Add Link'),
'noTitle' => __('(no title)'),
@ -276,7 +278,11 @@ function wp_default_scripts( &$scripts ) {
'l10n_print_after' => 'try{convertEntities(wpLinkL10n);}catch(e){};',
) );
$scripts->add( 'wpdialogs-popup', "/wp-includes/js/tinymce/plugins/wpdialogs/js/popup$suffix.js", array( 'jquery-ui-dialog' ), '20101119' );
$scripts->add( 'wpdialogs', "/wp-includes/js/tinymce/plugins/wpdialogs/js/wpdialog$suffix.js", array( 'jquery-ui-dialog' ), '20110421' );
$scripts->add_data( 'wpdialogs', 'group', 1 );
$scripts->add( 'wpdialogs-popup', "/wp-includes/js/tinymce/plugins/wpdialogs/js/popup$suffix.js", array( 'wpdialogs' ), '20110421' );
$scripts->add_data( 'wpdialogs-popup', 'group', 1 );
if ( is_admin() ) {
$scripts->add( 'ajaxcat', "/wp-admin/js/cat$suffix.js", array( 'wp-lists' ), '20090102' );