summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/exe/js.php2
-rw-r--r--lib/scripts/compatibility.js4
-rw-r--r--lib/scripts/editor.js116
-rw-r--r--lib/scripts/script.js80
4 files changed, 121 insertions, 81 deletions
diff --git a/lib/exe/js.php b/lib/exe/js.php
index 0688825c6..720e34577 100644
--- a/lib/exe/js.php
+++ b/lib/exe/js.php
@@ -55,6 +55,7 @@ function js_out(){
DOKU_INC.'lib/scripts/textselection.js',
DOKU_INC.'lib/scripts/toolbar.js',
DOKU_INC.'lib/scripts/edit.js',
+ DOKU_INC.'lib/scripts/editor.js',
DOKU_INC.'lib/scripts/locktimer.js',
DOKU_INC.'lib/scripts/linkwiz.js',
DOKU_INC.'lib/scripts/media.js',
@@ -107,7 +108,6 @@ function js_out(){
// init stuff
js_runonstart("addEvent(document,'click',closePopups)");
js_runonstart('addTocToggle()');
- js_runonstart("initSizeCtl('size__ctl','wiki__text')");
js_runonstart("initToolbar('tool__bar','wiki__text',toolbar)");
if($conf['locktime'] != 0){
js_runonstart("locktimer.init(".($conf['locktime'] - 60).",'".js_escape($lang['willexpire'])."',".$conf['usedraft'].", 'wiki__text')");
diff --git a/lib/scripts/compatibility.js b/lib/scripts/compatibility.js
index ac17a4427..1ab7d02ad 100644
--- a/lib/scripts/compatibility.js
+++ b/lib/scripts/compatibility.js
@@ -29,6 +29,10 @@ var linkwiz = {
toggle: DEPRECATED_WRAP(dw_linkwiz.toggle, dw_linkwiz)
};
+initSizeCtl = DEPRECATED_WRAP(dw_editor.initSizeCtl);
+sizeCtl = DEPRECATED_WRAP(dw_editor.sizeCtl);
+toggleWrap = DEPRECATED_WRAP(dw_editor.toggleWrap);
+setWrap = DEPRECATED_WRAP(dw_editor.setWrap);
function findPosX(object){
DEPRECATED('Use jQuery.position() instead');
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);
diff --git a/lib/scripts/script.js b/lib/scripts/script.js
index 24473c2e6..a6951c4ce 100644
--- a/lib/scripts/script.js
+++ b/lib/scripts/script.js
@@ -331,86 +331,6 @@ addInitEvent(function(){
}
});
-/**
- * Add the edit window size controls
- */
-function initSizeCtl(ctlid,edid){
- if(!document.getElementById){ return; }
-
- var ctl = $(ctlid);
- var textarea = $(edid);
- if(!ctl || !textarea) return;
-
- var hgt = DokuCookie.getValue('sizeCtl');
- if(hgt){
- textarea.style.height = hgt;
- }else{
- 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');
- 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);
-}
-
-/**
- * This sets the vertical size of the editbox
- */
-function sizeCtl(edid,val){
- var textarea = $(edid);
- var height = parseInt(textarea.style.height.substr(0,textarea.style.height.length-2));
- height += val;
- textarea.style.height = height+'px';
-
- DokuCookie.setValue('sizeCtl',textarea.style.height);
-}
-
-/**
- * Toggle the wrapping mode of a textarea
- */
-function toggleWrap(edid){
- var textarea = $(edid);
- var wrap = textarea.getAttribute('wrap');
- if(wrap && wrap.toLowerCase() == 'off'){
- setWrap(textarea, 'soft');
- }else{
- setWrap(textarea, 'off');
- }
-
- DokuCookie.setValue('wrapCtl',textarea.getAttribute('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
- */
-function setWrap(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);
-}
/**
* Handler to close all open Popups