diff options
-rw-r--r-- | lib/scripts/edit.js | 158 |
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 |