diff options
author | Kate Arzamastseva <pshns@ukr.net> | 2011-07-10 14:42:10 +0300 |
---|---|---|
committer | Kate Arzamastseva <pshns@ukr.net> | 2011-07-10 14:42:10 +0300 |
commit | abc5e9c041a9f062f4506e4d643d1838a562b460 (patch) | |
tree | 62e3331744130aac11fe2350e666af42e38995f2 /lib/scripts/editor.js | |
parent | de11c42f80968ac41dc4164829845c1e5dae25c2 (diff) | |
parent | 0cacf91f96aa51a4c66082fe6c9b034fe61a1290 (diff) | |
download | rpg-abc5e9c041a9f062f4506e4d643d1838a562b460.tar.gz rpg-abc5e9c041a9f062f4506e4d643d1838a562b460.tar.bz2 |
merging
Diffstat (limited to 'lib/scripts/editor.js')
-rw-r--r-- | lib/scripts/editor.js | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/lib/scripts/editor.js b/lib/scripts/editor.js new file mode 100644 index 000000000..fbdb1d79a --- /dev/null +++ b/lib/scripts/editor.js @@ -0,0 +1,116 @@ +/** + * The DokuWiki editor features + * + * These are the advanced features of the editor. It does NOT contain any + * code for the toolbar buttons and it functions. See toolbar.js for that. + */ + +var dw_editor = { + + /** + * initialize the default editor functionality + * + * All other functions can also be called separately for non-default + * textareas + */ + init: function(){ + var editor = jQuery('#wiki__text'); + if(!editor.length) return; + + dw_editor.initSizeCtl('#size__ctl',editor); + }, + + /** + * Add the edit window size and wrap controls + * + * Initial values are read from cookie if it exists + * + * @param selector ctlarea the div to place the controls + * @param selector editor the textarea to control + */ + initSizeCtl: function(ctlarea,editor){ + var ctl = jQuery(ctlarea); + var textarea = jQuery(editor); + if(!ctl.length || !textarea.length) return; + + var hgt = DokuCookie.getValue('sizeCtl'); + if(hgt){ + textarea.css('height', hgt); + }else{ + textarea.css('height', '300px'); + } + + var wrp = DokuCookie.getValue('wrapCtl'); + if(wrp){ + dw_editor.setWrap(textarea[0], wrp); + } // else use default value + + var l = document.createElement('img'); + var s = document.createElement('img'); + var w = document.createElement('img'); + l.src = DOKU_BASE+'lib/images/larger.gif'; + s.src = DOKU_BASE+'lib/images/smaller.gif'; + w.src = DOKU_BASE+'lib/images/wrap.gif'; + jQuery(l).click(function(){dw_editor.sizeCtl(editor,100);}); + jQuery(s).click(function(){dw_editor.sizeCtl(editor,-100);}); + jQuery(w).click(function(){dw_editor.toggleWrap(editor);}); + ctl.append(l); + ctl.append(s); + ctl.append(w); + }, + + /** + * This sets the vertical size of the editbox and adjusts the cookie + * + * @param selector editor the textarea to control + * @param int val the relative value to resize in pixel + */ + sizeCtl: function(editor,val){ + var textarea = jQuery(editor); + var height = parseInt(textarea.css('height')); + height += val; + textarea.css('height', height+'px'); + DokuCookie.setValue('sizeCtl',textarea.css('height')); + }, + + /** + * Toggle the wrapping mode of the editor textarea and adjusts the + * cookie + * + * @param selector editor the textarea to control + */ + toggleWrap: function(editor){ + var textarea = jQuery(editor); + var wrap = textarea.attr('wrap'); + if(wrap && wrap.toLowerCase() == 'off'){ + dw_editor.setWrap(textarea[0], 'soft'); + }else{ + dw_editor.setWrap(textarea[0], 'off'); + } + DokuCookie.setValue('wrapCtl',textarea.attr('wrap')); + }, + + /** + * Set the wrapping mode of a textarea + * + * @author Fluffy Convict <fluffyconvict@hotmail.com> + * @author <shutdown@flashmail.com> + * @link http://news.hping.org/comp.lang.javascript.archive/12265.html + * @link https://bugzilla.mozilla.org/show_bug.cgi?id=41464 + * @param DomObject textarea + * @param string wrapAttrValue + */ + setWrap: function(textarea, wrapAttrValue){ + textarea.setAttribute('wrap', wrapAttrValue); + + // Fix display for mozilla + var parNod = textarea.parentNode; + var nxtSib = textarea.nextSibling; + parNod.removeChild(textarea); + parNod.insertBefore(textarea, nxtSib); + } + + +}; + +jQuery(dw_editor.init); |