Improve quicktags back-compat, add method instance.getButtonElement(id), see #16695
git-svn-id: http://svn.automattic.com/wordpress/trunk@18611 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
07d81969bd
commit
a8df969ac9
|
@ -52,7 +52,7 @@ function edInsertContent(bah, txt) {
|
||||||
* @see QTags.addButton()
|
* @see QTags.addButton()
|
||||||
*/
|
*/
|
||||||
function edButton(id, display, tagStart, tagEnd, access, open) {
|
function edButton(id, display, tagStart, tagEnd, access, open) {
|
||||||
return QTags.addButton( id, display, tagStart, tagEnd, open, access );
|
return QTags.addButton( id, display, tagStart, tagEnd, open, access, '', -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
(function(){
|
(function(){
|
||||||
|
@ -140,12 +140,9 @@ function edButton(id, display, tagStart, tagEnd, access, open) {
|
||||||
|
|
||||||
var t = this,
|
var t = this,
|
||||||
id = settings.id,
|
id = settings.id,
|
||||||
buttons = {},
|
|
||||||
theButtons = {},
|
|
||||||
canvas = document.getElementById(id),
|
canvas = document.getElementById(id),
|
||||||
name = 'qt_' + id,
|
name = 'qt_' + id,
|
||||||
html = '',
|
tb, onclick, toolbar_id;
|
||||||
i, tb, qb, btn, onclick, toolbar_id;
|
|
||||||
|
|
||||||
if ( !id || !canvas )
|
if ( !id || !canvas )
|
||||||
return false;
|
return false;
|
||||||
|
@ -153,17 +150,9 @@ function edButton(id, display, tagStart, tagEnd, access, open) {
|
||||||
t.name = name;
|
t.name = name;
|
||||||
t.id = id;
|
t.id = id;
|
||||||
t.canvas = canvas;
|
t.canvas = canvas;
|
||||||
|
t.settings = settings;
|
||||||
// default buttons
|
|
||||||
for ( i in edButtons ) {
|
|
||||||
if ( !edButtons[i] )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
buttons[edButtons[i].id] = edButtons[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( id == 'content' && adminpage && ( adminpage == 'post-new-php' || adminpage == 'post-php' ) ) {
|
if ( id == 'content' && adminpage && ( adminpage == 'post-new-php' || adminpage == 'post-php' ) ) {
|
||||||
buttons['fullscreen'] = new qt.FullscreenButton();
|
|
||||||
// back compat hack :-(
|
// back compat hack :-(
|
||||||
edCanvas = canvas;
|
edCanvas = canvas;
|
||||||
toolbar_id = 'ed_toolbar';
|
toolbar_id = 'ed_toolbar';
|
||||||
|
@ -171,43 +160,11 @@ function edButton(id, display, tagStart, tagEnd, access, open) {
|
||||||
toolbar_id = name + '_toolbar';
|
toolbar_id = name + '_toolbar';
|
||||||
}
|
}
|
||||||
|
|
||||||
// add custom buttons
|
|
||||||
for ( i in t._customButtons ) {
|
|
||||||
buttons[i] = new t._customButtons[i]();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( settings.buttons ) {
|
|
||||||
qb = settings.buttons.split(',');
|
|
||||||
|
|
||||||
for ( i in qb ) {
|
|
||||||
btn = qb[i];
|
|
||||||
if ( buttons[btn] )
|
|
||||||
theButtons[btn] = buttons[btn];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
theButtons = buttons;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( settings.disabled_buttons ) {
|
|
||||||
qb = settings.disabled_buttons.split(',');
|
|
||||||
|
|
||||||
for ( i in qb ) {
|
|
||||||
btn = qb[i];
|
|
||||||
if ( theButtons[btn] )
|
|
||||||
delete(theButtons[btn]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( i in theButtons )
|
|
||||||
html += theButtons[i].html(name + '_');
|
|
||||||
|
|
||||||
tb = document.createElement('div');
|
tb = document.createElement('div');
|
||||||
tb.id = toolbar_id;
|
tb.id = toolbar_id;
|
||||||
tb.className = 'quicktags-toolbar';
|
tb.className = 'quicktags-toolbar';
|
||||||
|
|
||||||
canvas.parentNode.insertBefore(tb, canvas);
|
canvas.parentNode.insertBefore(tb, canvas);
|
||||||
|
|
||||||
tb.innerHTML = html;
|
|
||||||
t.toolbar = tb;
|
t.toolbar = tb;
|
||||||
|
|
||||||
// listen for click events
|
// listen for click events
|
||||||
|
@ -221,8 +178,8 @@ function edButton(id, display, tagStart, tagEnd, access, open) {
|
||||||
t.canvas = canvas = document.getElementById(id);
|
t.canvas = canvas = document.getElementById(id);
|
||||||
i = target.id.replace(name + '_', '');
|
i = target.id.replace(name + '_', '');
|
||||||
|
|
||||||
if ( theButtons[i] )
|
if ( t.theButtons[i] )
|
||||||
theButtons[i].callback.call(theButtons[i], target, canvas, t);
|
t.theButtons[i].callback.call(t.theButtons[i], target, canvas, t);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -233,13 +190,19 @@ function edButton(id, display, tagStart, tagEnd, access, open) {
|
||||||
}
|
}
|
||||||
|
|
||||||
t.getButton = function(id) {
|
t.getButton = function(id) {
|
||||||
return buttons[id];
|
return t.theButtons[id];
|
||||||
|
};
|
||||||
|
|
||||||
|
t.getButtonElement = function(id) {
|
||||||
|
return document.getElementById(name + '_' + id);
|
||||||
};
|
};
|
||||||
|
|
||||||
qt.instances[id] = t;
|
qt.instances[id] = t;
|
||||||
|
|
||||||
if ( !qt.instances[0] )
|
if ( !qt.instances[0] ) {
|
||||||
qt.instances[0] = qt.instances[id];
|
qt.instances[0] = qt.instances[id];
|
||||||
|
_domReady( function(){ qt._buttonsInit(); } );
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
qt.instances = {};
|
qt.instances = {};
|
||||||
|
@ -251,7 +214,67 @@ function edButton(id, display, tagStart, tagEnd, access, open) {
|
||||||
qt.getInstance = function(id) {
|
qt.getInstance = function(id) {
|
||||||
return qt.instances[id];
|
return qt.instances[id];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
qt._buttonsInit = function() {
|
||||||
|
var t = this, instance, canvas, name, settings, buttons = {}, theButtons = {}, html = '', id, i, qb, btn;;
|
||||||
|
|
||||||
|
for ( id in t.instances ) {
|
||||||
|
if ( id == 0 )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
instance = t.instances[id];
|
||||||
|
canvas = instance.canvas;
|
||||||
|
name = instance.name;
|
||||||
|
settings = instance.settings;
|
||||||
|
|
||||||
|
// set buttons
|
||||||
|
for ( i in edButtons ) {
|
||||||
|
if ( !edButtons[i] )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
buttons[edButtons[i].id] = edButtons[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( id == 'content' && adminpage && ( adminpage == 'post-new-php' || adminpage == 'post-php' ) )
|
||||||
|
buttons['fullscreen'] = new qt.FullscreenButton();
|
||||||
|
|
||||||
|
// add custom buttons
|
||||||
|
for ( i in t._customButtons ) {
|
||||||
|
if ( !buttons[i] )
|
||||||
|
buttons[i] = new t._customButtons[i]();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( settings.buttons ) {
|
||||||
|
qb = settings.buttons.split(',');
|
||||||
|
|
||||||
|
for ( i in qb ) {
|
||||||
|
btn = qb[i];
|
||||||
|
if ( buttons[btn] )
|
||||||
|
theButtons[btn] = buttons[btn];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
theButtons = buttons;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( settings.disabled_buttons ) {
|
||||||
|
qb = settings.disabled_buttons.split(',');
|
||||||
|
|
||||||
|
for ( i in qb ) {
|
||||||
|
btn = qb[i];
|
||||||
|
if ( theButtons[btn] )
|
||||||
|
delete(theButtons[btn]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( i in theButtons )
|
||||||
|
html += theButtons[i].html(name + '_');
|
||||||
|
|
||||||
|
instance.toolbar.innerHTML = html;
|
||||||
|
instance.theButtons = theButtons;
|
||||||
|
}
|
||||||
|
t.buttonsInitDone = true;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main API function for adding a button to Quicktags
|
* Main API function for adding a button to Quicktags
|
||||||
*
|
*
|
||||||
|
@ -283,16 +306,21 @@ function edButton(id, display, tagStart, tagEnd, access, open) {
|
||||||
if ( !id || !display )
|
if ( !id || !display )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
priority = priority || 0;
|
||||||
|
|
||||||
if ( typeof(arg1) == 'function' ) {
|
if ( typeof(arg1) == 'function' ) {
|
||||||
btn = new qt.Button(id, display, access, title);
|
btn = new qt.Button(id, display, access, title);
|
||||||
btn.callback = arg1;
|
btn.callback = arg1;
|
||||||
} else if ( typeof(arg1) == 'string' && arg1 && arg2 ) {
|
} else if ( arg1 && arg2 && typeof(arg1) == 'string' ) {
|
||||||
btn = new qt.TagButton(id, display, arg1, arg2, access, arg3, title);
|
btn = new qt.TagButton(id, display, arg1, arg2, access, arg3, title);
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( priority ) {
|
if ( priority == -1 ) // back-compat
|
||||||
|
return btn;
|
||||||
|
|
||||||
|
if ( priority > 0 ) {
|
||||||
while ( typeof(edButtons[priority]) != 'undefined' ) {
|
while ( typeof(edButtons[priority]) != 'undefined' ) {
|
||||||
priority++
|
priority++
|
||||||
}
|
}
|
||||||
|
@ -301,6 +329,9 @@ function edButton(id, display, tagStart, tagEnd, access, open) {
|
||||||
} else {
|
} else {
|
||||||
edButtons[edButtons.length] = btn;
|
edButtons[edButtons.length] = btn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( this.buttonsInitDone )
|
||||||
|
this._buttonsInit(); // add the button HTML to all instances toolbars if addButton() was called too late
|
||||||
};
|
};
|
||||||
|
|
||||||
qt.insertContent = function(content) {
|
qt.insertContent = function(content) {
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -68,7 +68,7 @@ function wp_default_scripts( &$scripts ) {
|
||||||
|
|
||||||
$scripts->add( 'sack', "/wp-includes/js/tw-sack$suffix.js", false, '1.6.1', 1 );
|
$scripts->add( 'sack', "/wp-includes/js/tw-sack$suffix.js", false, '1.6.1', 1 );
|
||||||
|
|
||||||
$scripts->add( 'quicktags', "/wp-includes/js/quicktags$suffix.js", false, '20110820', 1 );
|
$scripts->add( 'quicktags', "/wp-includes/js/quicktags$suffix.js", false, '20110826', 1 );
|
||||||
$scripts->add_script_data( 'quicktags', 'quicktagsL10n', array(
|
$scripts->add_script_data( 'quicktags', 'quicktagsL10n', array(
|
||||||
'wordLookup' => __('Enter a word to look up:'),
|
'wordLookup' => __('Enter a word to look up:'),
|
||||||
'dictionaryLookup' => esc_attr(__('Dictionary lookup')),
|
'dictionaryLookup' => esc_attr(__('Dictionary lookup')),
|
||||||
|
|
Loading…
Reference in New Issue