Skip to content
Snippets Groups Projects
Commit b7641d9e authored by Gabriel Birke's avatar Gabriel Birke
Browse files

Arbitrary Button types in JS toolbar

This is my patch for creating toolbar buttons with arbitrary button types,
tested with Firefox, Opera and IE7. If you want to create a new type of
button, you must have a function in the script.js file of your plugin. The
function name must begin with "addBtnAction", followed by the type name, for
example for the type "myType" the function must be called
"addBtnActionMyType" (bear in mind that the first char of the type must be
uppercased in the function name).

The function has four parameters:
"btn" is the HTML element for the button where you attach the onclick
handler
"props" is an associative array of the array properties that come from the
toolbar array that was created by toolbar.php
"edid" (optional) is the id of the editor textarea
"id" (optional) is a "unique" number for each button: the index variable of
the for loop where the buttons get created.

darcs-hash:20070826192206-79ce3-1fe6f49c1eb5d0c10adbadc43f7b2ee1aec1853e.gz
parent c818ebe6
No related branches found
No related tags found
No related merge requests found
......@@ -135,61 +135,121 @@ function initToolbar(tbid,edid,tb){
var cnt = tb.length;
for(var i=0; i<cnt; i++){
// create new button
btn = createToolButton(tb[i]['icon'],
var btn = createToolButton(tb[i]['icon'],
tb[i]['title'],
tb[i]['key']);
// add button action dependend on type
switch(tb[i]['type']){
case 'format':
var sample = tb[i]['title'];
if(tb[i]['sample']){ sample = tb[i]['sample']; }
eval("btn.onclick = function(){insertTags('"+
jsEscape(edid)+"','"+
jsEscape(tb[i]['open'])+"','"+
jsEscape(tb[i]['close'])+"','"+
jsEscape(sample)+
"');return false;}");
toolbar.appendChild(btn);
break;
case 'insert':
eval("btn.onclick = function(){insertAtCarret('"+
jsEscape(edid)+"','"+
jsEscape(tb[i]['insert'])+
"');return false;}");
toolbar.appendChild(btn);
break;
case 'signature':
if(typeof(SIG) != 'undefined' && SIG != ''){
eval("btn.onclick = function(){insertAtCarret('"+
jsEscape(edid)+"','"+
jsEscape(SIG)+
"');return false;}");
toolbar.appendChild(btn);
}
break;
case 'picker':
createPicker('picker'+i,
tb[i]['list'],
tb[i]['icobase'],
edid);
eval("btn.onclick = function(){showPicker('picker"+i+
"',this);return false;}");
toolbar.appendChild(btn);
break;
case 'mediapopup':
eval("btn.onclick = function(){window.open('"+
jsEscape(tb[i]['url']+NS)+"','"+
jsEscape(tb[i]['name'])+"','"+
jsEscape(tb[i]['options'])+
"');return false;}");
var actionFunc = 'addBtnAction'+tb[i]['type'].charAt(0).toUpperCase()+tb[i]['type'].substring(1);
var exists = eval("typeof("+actionFunc+") == 'function'");
if(exists)
{
if(eval(actionFunc+"(btn, tb[i], edid, i)"))
toolbar.appendChild(btn);
break;
} // end switch
}
} // end for
}
/**
* Add button action for format buttons
*
* @param DOMElement btn Button element to add the action to
* @param array props Associative array of button properties
* @param string edid ID of the editor textarea
* @return boolean If button should be appended
* @author Gabriel Birke <birke@d-scribe.de>
*/
function addBtnActionFormat(btn, props, edid)
{
var sample = props['title'];
if(props['sample']){ sample = props['sample']; }
eval("btn.onclick = function(){insertTags('"+
jsEscape(edid)+"','"+
jsEscape(props['open'])+"','"+
jsEscape(props['close'])+"','"+
jsEscape(sample)+
"');return false;}");
return true;
}
/**
* Add button action for insert buttons
*
* @param DOMElement btn Button element to add the action to
* @param array props Associative array of button properties
* @param string edid ID of the editor textarea
* @return boolean If button should be appended
* @author Gabriel Birke <birke@d-scribe.de>
*/
function addBtnActionInsert(btn, props, edid)
{
eval("btn.onclick = function(){insertAtCarret('"+
jsEscape(edid)+"','"+
jsEscape(props['insert'])+
"');return false;}");
return true;
}
/**
* Add button action for signature button
*
* @param DOMElement btn Button element to add the action to
* @param array props Associative array of button properties
* @param string edid ID of the editor textarea
* @return boolean If button should be appended
* @author Gabriel Birke <birke@d-scribe.de>
*/
function addBtnActionSignature(btn, props, edid)
{
if(typeof(SIG) != 'undefined' && SIG != ''){
eval("btn.onclick = function(){insertAtCarret('"+
jsEscape(edid)+"','"+
jsEscape(SIG)+
"');return false;}");
return true;
}
return false;
}
/**
* Add button action for picker buttons and create picker element
*
* @param DOMElement btn Button element to add the action to
* @param array props Associative array of button properties
* @param string edid ID of the editor textarea
* @param int id Unique number of the picker
* @return boolean If button should be appended
* @author Gabriel Birke <birke@d-scribe.de>
*/
function addBtnActionPicker(btn, props, edid, id)
{
createPicker('picker'+id,
props['list'],
props['icobase'],
edid);
eval("btn.onclick = function(){showPicker('picker"+id+
"',this);return false;}");
return true;
}
/**
* Add button action for the mediapopup button
*
* @param DOMElement btn Button element to add the action to
* @param array props Associative array of button properties
* @return boolean If button should be appended
* @author Gabriel Birke <birke@d-scribe.de>
*/
function addBtnActionMediapopup(btn, props)
{
eval("btn.onclick = function(){window.open('"+
jsEscape(props['url']+NS)+"','"+
jsEscape(props['name'])+"','"+
jsEscape(props['options'])+
"');return false;}");
return true;
}
/**
* Format selection
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment