summaryrefslogtreecommitdiff
path: root/lib/scripts
diff options
context:
space:
mode:
authorGabriel Birke <Gabriel.Birke@delti.com>2007-08-26 21:22:06 +0200
committerGabriel Birke <Gabriel.Birke@delti.com>2007-08-26 21:22:06 +0200
commitb7641d9e7bae9b7cf8c64772470e9e2525d18b5c (patch)
tree71f56073d0c4748bb4441231ce5d51ac61485b2d /lib/scripts
parentc818ebe64f8e84f603c77789e7b2a47248d33957 (diff)
downloadrpg-b7641d9e7bae9b7cf8c64772470e9e2525d18b5c.tar.gz
rpg-b7641d9e7bae9b7cf8c64772470e9e2525d18b5c.tar.bz2
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
Diffstat (limited to 'lib/scripts')
-rw-r--r--lib/scripts/edit.js158
1 files changed, 109 insertions, 49 deletions
diff --git a/lib/scripts/edit.js b/lib/scripts/edit.js
index ff32c9676..6743d8f58 100644
--- a/lib/scripts/edit.js
+++ b/lib/scripts/edit.js
@@ -135,62 +135,122 @@ 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
*
* Apply tagOpen/tagClose to selection in textarea, use sampleText instead