From 276b8bd9566cbdcc99b7c3ab8349e8c06843c23d Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Thu, 25 May 2006 17:23:57 +0200 Subject: javascript to toggle editor wrapping This patch adds a way to sisable and enable the automating wrapping in the editor textarea. Disabling the wrapping is especially useful when editing large tables. darcs-hash:20060525152357-7ad00-ced566c5d640cc521877d4b3325640c3fcd3ded9.gz --- lib/scripts/script.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'lib/scripts') diff --git a/lib/scripts/script.js b/lib/scripts/script.js index df12a29fb..1f5a71e78 100644 --- a/lib/scripts/script.js +++ b/lib/scripts/script.js @@ -339,12 +339,16 @@ function initSizeCtl(ctlid,edid){ 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'; addEvent(l,'click',function(){sizeCtl(edid,100);}); addEvent(s,'click',function(){sizeCtl(edid,-100);}); + addEvent(w,'click',function(){toggleWrap(edid);}); ctl.appendChild(l); ctl.appendChild(s); + ctl.appendChild(w); } /** @@ -359,6 +363,29 @@ function sizeCtl(edid,val){ DokuCookie.setValue('sizeCtl',textarea.style.height); } +/** + * Toggle the wrapping mode of a textarea + * + * @author Fluffy Convict + * @link http://news.hping.org/comp.lang.javascript.archive/12265.html + * @author + * @link https://bugzilla.mozilla.org/show_bug.cgi?id=302710#c2 + */ +function toggleWrap(edid){ + var txtarea = $(edid); + var wrap = txtarea.getAttribute('wrap'); + if(wrap && wrap.toLowerCase() == 'off'){ + txtarea.setAttribute('wrap', 'soft'); + }else{ + txtarea.setAttribute('wrap', 'off'); + } + // Fix display for mozilla + var parNod = txtarea.parentNode; + var nxtSib = txtarea.nextSibling; + parNod.removeChild(txtarea); + parNod.insertBefore(txtarea, nxtSib); +} + /** * Handler to close all open Popups */ -- cgit v1.2.3