[dokuwiki] Patch: Arbitrary Button types in JS toolbar
- From: "Gabriel Birke" <Gabriel.Birke@xxxxxxxxx>
- To: <dokuwiki@xxxxxxxxxxxxx>
- Date: Thu, 23 Aug 2007 15:59:55 +0200
Hello,
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.
There is one thing I would like to discuss:
Using closures instead of eval calls in the addBtnAction functions would
make the code shorter, more readable and bug-tracking easier. Was the use of
eval a conscious design decision (maybe to avoid leaks)? I am aware that
closures can possibly create memory leaks in IE but I tested a closure-based
version of my code with IE7 and Drip
(http://jgwebber.blogspot.com/2005/05/drip-ie-leak-detector.html ) and
could't detect any leaks. So my question to the community: should we use
closures instead of eval calls?
An example:
// a closure like this
btn.onclick = function(){
insertTags(edid, props['open'],props['close'],sample);
return false;
}
// instead of this eval call
eval("btn.onclick = function(){insertTags('"+
jsEscape(edid)+"','"+
jsEscape(props['open'])+"','"+
jsEscape(props['close'])+"','"+
jsEscape(sample)+
"');return false;}");
If anyone is interested in my closure-based version of edit.js it can send
this version (or a patch).
Greetings,
Gabriel
- Follow-Ups:
- [dokuwiki] Re: Patch: Arbitrary Button types in JS toolbar
- From: Andreas Gohr
Other related posts:
- » [dokuwiki] Patch: Arbitrary Button types in JS toolbar
- » [dokuwiki] Re: Patch: Arbitrary Button types in JS toolbar
- [dokuwiki] Re: Patch: Arbitrary Button types in JS toolbar
- From: Andreas Gohr