summaryrefslogtreecommitdiff
path: root/lib/scripts/edit.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/edit.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/edit.js')
-rw-r--r--lib/scripts/edit.js73
1 files changed, 5 insertions, 68 deletions
diff --git a/lib/scripts/edit.js b/lib/scripts/edit.js
index 86ebb230d..3b1ca8834 100644
--- a/lib/scripts/edit.js
+++ b/lib/scripts/edit.js
@@ -67,7 +67,7 @@ function createPicker(id,props,edid){
}
picker.id = id;
picker.style.position = 'absolute';
- picker.style.marginLeft = '-10000px'; // no display none, to keep access keys working
+ picker.style.marginLeft = '-10000px'; // no display:none, to keep access keys working
for(var key in list){
if (!list.hasOwnProperty(key)) continue;
@@ -84,9 +84,7 @@ function createPicker(id,props,edid){
}
btn.title = key;
btn.appendChild(ico);
- eval("btn.onclick = function(){pickerInsert('"+
- jsEscape(key)+"','"+
- jsEscape(edid)+"');return false;}");
+ addEvent(btn,'click',bind(pickerInsert,key,edid));
picker.appendChild(btn);
}else if(isString(list[key])){
// a list of text -> treat as text picker
@@ -95,9 +93,7 @@ function createPicker(id,props,edid){
var txt = document.createTextNode(list[key]);
btn.title = list[key];
btn.appendChild(txt);
- eval("btn.onclick = function(){pickerInsert('"+
- jsEscape(list[key])+"','"+
- jsEscape(edid)+"');return false;}");
+ addEvent(btn,'click',bind(pickerInsert,list[key],edid));
picker.appendChild(btn);
}else{
// a list of lists -> treat it as subtoolbar
@@ -117,9 +113,7 @@ function createPicker(id,props,edid){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function pickerInsert(text,edid){
- // insert
insertAtCarret(edid,text);
- // close picker
pickerClose();
}
@@ -132,51 +126,15 @@ function pickerInsert(text,edid){
* @return boolean If button should be appended
* @author Gabriel Birke <birke@d-scribe.de>
*/
-function addBtnActionSignature(btn, props, edid)
-{
+function addBtnActionSignature(btn, props, edid) {
if(typeof(SIG) != 'undefined' && SIG != ''){
- eval("btn.onclick = function(){insertAtCarret('"+
- jsEscape(edid)+"','"+
- jsEscape(SIG)+
- "');return false;}");
+ addEvent(btn,'click',bind(insertAtCarret,edid,SIG));
return true;
}
return false;
}
/**
- * 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('"+DOKU_BASE+
- jsEscape(props['url']+encodeURIComponent(NS))+"','"+
- jsEscape(props['name'])+"','"+
- jsEscape(props['options'])+
- "');return false;}");
- return true;
-}
-
-/**
- * Add button action for the headline buttons
- *
- * @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 Andreas Gohr <gohr@cosmocode.de>
- */
-function addBtnActionAutohead(btn, props, edid, id) {
- eval("btn.onclick = function(){"+
- "insertHeadline('"+edid+"',"+props['mod']+",'"+jsEscape(props['text'])+"'); "+
- "return false};");
- return true;
-}
-
-/**
* Make intended formattings easier to handle
*
* Listens to all key inputs and handle indentions
@@ -272,27 +230,6 @@ function currentHeadlineLevel(textboxId){
return 0;
}
-/**
- * Insert a new headline based on the current section level
- *
- * @param string textboxId - the edit field ID
- * @param int mod - the headline modificator ( -1, 0, 1)
- * @param string text - the sample text passed to insertTags
- */
-function insertHeadline(textboxId,mod,text){
- var lvl = currentHeadlineLevel(textboxId);
-
-
- // determine new level
- lvl += mod;
- if(lvl < 1) lvl = 1;
- if(lvl > 5) lvl = 5;
-
- var tags = '=';
- for(var i=0; i<=5-lvl; i++) tags += '=';
- insertTags(textboxId, tags+' ', ' '+tags+"\n", text);
- pickerClose();
-}
/**
* global var used for not saved yet warning