summaryrefslogtreecommitdiff
path: root/lib/scripts/toolbar.js
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2009-10-18 22:17:10 +0200
committerAndreas Gohr <andi@splitbrain.org>2009-10-18 22:17:10 +0200
commite81529bd8d8b5b43282733c8f55e9b9459b4b063 (patch)
tree3ddf4ed23c3f5ad8030f639e11a74a48cf3628ac /lib/scripts/toolbar.js
parent673c04e7e3f11d45a51bd7d9e6505e3200c5bcb7 (diff)
downloadrpg-e81529bd8d8b5b43282733c8f55e9b9459b4b063.tar.gz
rpg-e81529bd8d8b5b43282733c8f55e9b9459b4b063.tar.bz2
added bind() JS function got rid of all eval() calls
Ignore-this: 4c7b7b3ebc83ce596e8a7e41d6a88f09 Another round of cleaning up the JavaScript code. A new bind() utility function [1] was introduced and all eval() calls where removed from the toolbar code. [1] See http://www.cosmocode.de/en/blog/gohr/2009-10/15-javascript-fixing-the-closure-scope-in-loops darcs-hash:20091018201710-7ad00-d0bcfa62e28a7a360c8bb8303367a94a9fa78fe1.gz
Diffstat (limited to 'lib/scripts/toolbar.js')
-rw-r--r--lib/scripts/toolbar.js50
1 files changed, 43 insertions, 7 deletions
diff --git a/lib/scripts/toolbar.js b/lib/scripts/toolbar.js
index 599386fb8..46f6ad789 100644
--- a/lib/scripts/toolbar.js
+++ b/lib/scripts/toolbar.js
@@ -33,13 +33,7 @@ function initToolbar(tbid,edid,tb){
// type is a tb function -> assign it as onclick
actionFunc = 'tb_'+tb[i]['type'];
if( isFunction(window[actionFunc]) ){
- addEvent(btn,'click', function(func,btn, props, edid){
- return function(){
- window[func](btn, props, edid);
- return false;
- }
- }(actionFunc,btn,tb[i],edid) );
- //above fixes the scope problem as descried at http://www.mennovanslooten.nl/blog/post/62
+ addEvent(btn,'click', bind(window[actionFunc],btn,tb[i],edid));
toolbar.appendChild(btn);
continue;
}
@@ -136,6 +130,48 @@ function tb_formatln(btn, props, edid) {
function tb_insert(btn, props, edid) {
insertAtCarret(edid,fixtxt(props['insert']));
pickerClose();
+ return false;
+}
+
+/**
+ * Button action for the media popup
+ *
+ * @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
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+function tb_mediapopup(btn, props, edid) {
+ window.open(
+ DOKU_BASE+props['url']+encodeURIComponent(NS),
+ props['name'],
+ props['options']);
+ return false;
+}
+
+/**
+ * Button action for automatic headlines
+ *
+ * Insert a new headline based on the current section level
+ *
+ * @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
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+function tb_autohead(btn, props, edid){
+ var lvl = currentHeadlineLevel(edid);
+
+ // determine new level
+ lvl += props['mod'];
+ if(lvl < 1) lvl = 1;
+ if(lvl > 5) lvl = 5;
+
+ var tags = '=';
+ for(var i=0; i<=5-lvl; i++) tags += '=';
+ insertTags(edid, tags+' ', ' '+tags+"\n", props['text']);
+ pickerClose();
+ return false;
}