[dokuwiki] Preserving "wrap textarea" setting state in cookie

Hi!

I found it strange that docuwiki textarea height is saved in cookies,
but wrap property is not. Maybe it was done on purpose. So the given
patch solves this limitation, maybe someone will be interested.

I also ask the community to vote for solving this bug:

https://bugzilla.mozilla.org/show_bug.cgi?id=41464

which has an impact on the JS code in dokuwiki.

Nice weekend!
Index: script.js
===================================================================
--- script.js   (revision 25)
+++ script.js   (working copy)
@@ -411,6 +411,11 @@
       textarea.style.height = '300px';
     }
 
+    var wrp = DokuCookie.getValue('wrapCtl');
+    if(wrp){
+      setWrap(textarea, wrp);
+    } // else use default value
+
     var l = document.createElement('img');
     var s = document.createElement('img');
     var w = document.createElement('img');
@@ -439,25 +444,35 @@
 
 /**
  * Toggle the wrapping mode of a textarea
- *
- * @author Fluffy Convict <fluffyconvict@xxxxxxxxxxx>
- * @link   http://news.hping.org/comp.lang.javascript.archive/12265.html
- * @author <shutdown@xxxxxxxxxxxxx>
- * @link   https://bugzilla.mozilla.org/show_bug.cgi?id=302710#c2
  */
 function toggleWrap(edid){
-    var txtarea = $(edid);
-    var wrap = txtarea.getAttribute('wrap');
+    var textarea = $(edid);
+    var wrap = textarea.getAttribute('wrap');
     if(wrap && wrap.toLowerCase() == 'off'){
-        txtarea.setAttribute('wrap', 'soft');
+        setWrap(textarea, 'soft');
     }else{
-        txtarea.setAttribute('wrap', 'off');
+        setWrap(textarea, 'off');
     }
+
+    DokuCookie.setValue('wrapCtl',textarea.getAttribute('wrap'));
+}
+
+/**
+ * Set the wrapping mode of a textarea
+ *
+ * @author Fluffy Convict <fluffyconvict@xxxxxxxxxxx>
+ * @author <shutdown@xxxxxxxxxxxxx>
+ * @link   http://news.hping.org/comp.lang.javascript.archive/12265.html
+ * @link   https://bugzilla.mozilla.org/show_bug.cgi?id=41464
+ */
+function setWrap(textarea, wrapAttrValue){
+    textarea.setAttribute('wrap', wrapAttrValue);
+
     // Fix display for mozilla
-    var parNod = txtarea.parentNode;
-    var nxtSib = txtarea.nextSibling;
-    parNod.removeChild(txtarea);
-    parNod.insertBefore(txtarea, nxtSib);
+    var parNod = textarea.parentNode;
+    var nxtSib = textarea.nextSibling;
+    parNod.removeChild(textarea);
+    parNod.insertBefore(textarea, nxtSib);
 }
 
 /**

Other related posts: