aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib/scripts/script.js
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2005-10-08 19:54:04 +0200
committerAndreas Gohr <andi@splitbrain.org>2005-10-08 19:54:04 +0200
commit20d062ca5220daf6606e2b1bcdd73d84eebafa45 (patch)
tree5e077db1d5d7f95ba43161b446b2c4fb8ff477b1 /lib/scripts/script.js
parentb73cc7dccaa01778de20ade004e0c3bde2e2e36a (diff)
downloaddokuwiki-20d062ca5220daf6606e2b1bcdd73d84eebafa45.tar.gz
dokuwiki-20d062ca5220daf6606e2b1bcdd73d84eebafa45.zip
first go on unobstrusive javascript, new toolbar
darcs-hash:20051008175404-7ad00-cd640de7660825b19d5e863cc8caf5467d59b055.gz
Diffstat (limited to 'lib/scripts/script.js')
-rw-r--r--lib/scripts/script.js281
1 files changed, 121 insertions, 160 deletions
diff --git a/lib/scripts/script.js b/lib/scripts/script.js
index 8ee3c3805..490394dfb 100644
--- a/lib/scripts/script.js
+++ b/lib/scripts/script.js
@@ -16,9 +16,87 @@ if (clientPC.indexOf('opera')!=-1) {
var is_opera_seven = (window.opera && document.childNodes);
}
+//http://simon.incutio.com/archive/2004/05/26/addLoadEvent#comment2
+function addEvent(oTarget, sType, fpDest) {
+ var oOldEvent = oTarget[sType];
+ if (typeof oOldEvent != "function") {
+ oTarget[sType] = fpDest;
+ } else {
+ oTarget[sType] = function(e) {
+ oOldEvent(e);
+ fpDest(e);
+ }
+ }
+}
+
+/**
+ * Get the X offset of the top left corner of the given object
+ *
+ * @link http://www.quirksmode.org/index.html?/js/findpos.html
+ */
+function findPosX(object){
+ var curleft = 0;
+ if(typeof(object) == 'object'){
+ var obj = object;
+ }else{
+ var obj = document.getElementById(object);
+ }
+ if (obj.offsetParent){
+ while (obj.offsetParent){
+ curleft += obj.offsetLeft;
+ obj = obj.offsetParent;
+ }
+ }
+ else if (obj.x){
+ curleft += obj.x;
+ }
+ return curleft;
+} //end findPosX function
+
+/**
+ * Get the Y offset of the top left corner of the given object
+ *
+ * @link http://www.quirksmode.org/index.html?/js/findpos.html
+ */
+function findPosY(object){
+ var curtop = 0;
+ if(typeof(object) == 'object'){
+ var obj = object;
+ }else{
+ var obj = document.getElementById(object);
+ }
+ if (obj.offsetParent){
+ while (obj.offsetParent){
+ curtop += obj.offsetTop;
+ obj = obj.offsetParent;
+ }
+ }
+ else if (obj.y){
+ curtop += obj.y;
+ }
+ return curtop;
+} //end findPosY function
+
+/**
+ * Escape special chars in JavaScript
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+function jsEscape(text){
+ var re=new RegExp("\\\\","g");
+ text=text.replace(re,"\\\\");
+ var re=new RegExp("'","g");
+ text=text.replace(re,"\\'");
+ re=new RegExp('"',"g");
+ text=text.replace(re,'&quot;');
+ re=new RegExp("\\\\\\\\n","g");
+ text=text.replace(re,"\\n");
+ return text;
+}
/**
* This function escapes some special chars
+ * @deprecated by above function
*/
function escapeQuotes(text) {
var re=new RegExp("'","g");
@@ -72,6 +150,7 @@ function summaryCheck(){
/**
* This function generates the actual toolbar buttons with localized text
* we use it to avoid creating the toolbar where javascript is not enabled
+ * @deprecated
*/
function formatButton(imageFile, speedTip, tagOpen, tagClose, sampleText, accessKey) {
speedTip=escapeQuotes(speedTip);
@@ -97,6 +176,7 @@ function formatButton(imageFile, speedTip, tagOpen, tagClose, sampleText, access
/**
* This function generates the actual toolbar buttons with localized text
* we use it to avoid creating the toolbar where javascript is not enabled
+ * @deprecated
*/
function insertButton(imageFile, speedTip, value, accessKey) {
speedTip=escapeQuotes(speedTip);
@@ -119,6 +199,7 @@ function insertButton(imageFile, speedTip, value, accessKey) {
/**
* This adds a button for the MediaSelection Popup
+ * @deprecated
*/
function mediaButton(imageFile, speedTip, accessKey, namespace) {
speedTip=escapeQuotes(speedTip);
@@ -135,99 +216,6 @@ function mediaButton(imageFile, speedTip, accessKey, namespace) {
return;
}
-/**
- * apply tagOpen/tagClose to selection in textarea, use sampleText instead
- * of selection if there is none copied and adapted from phpBB
- *
- * @author phpBB development team
- * @author MediaWiki development team
- * @author Andreas Gohr <andi@splitbrain.org>
- * @author Jim Raynor <jim_raynor@web.de>
- */
-function insertTags(tagOpen, tagClose, sampleText) {
- var txtarea = document.editform.wikitext;
- // IE
- if(document.selection && !is_gecko) {
- var theSelection = document.selection.createRange().text;
- var replaced = true;
- if(!theSelection){
- replaced = false;
- theSelection=sampleText;
- }
- txtarea.focus();
-
- // This has change
- text = theSelection;
- if(theSelection.charAt(theSelection.length - 1) == " "){// exclude ending space char, if any
- theSelection = theSelection.substring(0, theSelection.length - 1);
- r = document.selection.createRange();
- r.text = tagOpen + theSelection + tagClose + " ";
- } else {
- r = document.selection.createRange();
- r.text = tagOpen + theSelection + tagClose;
- }
- if(!replaced){
- r.moveStart('character',-text.length-tagClose.length);
- r.moveEnd('character',-tagClose.length);
- }
- r.select();
- // Mozilla
- } else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
- var replaced = false;
- var startPos = txtarea.selectionStart;
- var endPos = txtarea.selectionEnd;
- if(endPos - startPos) replaced = true;
- var scrollTop=txtarea.scrollTop;
- var myText = (txtarea.value).substring(startPos, endPos);
- if(!myText) { myText=sampleText;}
- if(myText.charAt(myText.length - 1) == " "){ // exclude ending space char, if any
- subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
- } else {
- subst = tagOpen + myText + tagClose;
- }
- txtarea.value = txtarea.value.substring(0, startPos) + subst +
- txtarea.value.substring(endPos, txtarea.value.length);
- txtarea.focus();
-
- //set new selection
- if(replaced){
- var cPos=startPos+(tagOpen.length+myText.length+tagClose.length);
- txtarea.selectionStart=cPos;
- txtarea.selectionEnd=cPos;
- }else{
- txtarea.selectionStart=startPos+tagOpen.length;
- txtarea.selectionEnd=startPos+tagOpen.length+myText.length;
- }
- txtarea.scrollTop=scrollTop;
- // All others
- } else {
- var copy_alertText=alertText;
- var re1=new RegExp("\\$1","g");
- var re2=new RegExp("\\$2","g");
- copy_alertText=copy_alertText.replace(re1,sampleText);
- copy_alertText=copy_alertText.replace(re2,tagOpen+sampleText+tagClose);
- var text;
- if (sampleText) {
- text=prompt(copy_alertText);
- } else {
- text="";
- }
- if(!text) { text=sampleText;}
- text=tagOpen+text+tagClose;
- //append to the end
- txtarea.value += "\n"+text;
-
- // in Safari this causes scrolling
- if(!is_safari) {
- txtarea.focus();
- }
-
- }
- // reposition cursor if possible
- if (txtarea.createTextRange) txtarea.caretPos = document.selection.createRange().duplicate();
-}
-
-
/*
* Insert the selected filename and close the window
*
@@ -238,41 +226,6 @@ function mediaSelect(file){
window.close();
}
-/*
- * Insert the given value at the current cursor position
- *
- * @see http://www.alexking.org/index.php?content=software/javascript/content.php
- */
-function insertAtCarret(field,value){
- //IE support
- if (document.selection) {
- field.focus();
- if(opener == null){
- sel = document.selection.createRange();
- }else{
- sel = opener.document.selection.createRange();
- }
- sel.text = value;
- //MOZILLA/NETSCAPE support
- }else if (field.selectionStart || field.selectionStart == '0') {
- var startPos = field.selectionStart;
- var endPos = field.selectionEnd;
- var scrollTop = field.scrollTop;
- field.value = field.value.substring(0, startPos)
- + value
- + field.value.substring(endPos, field.value.length);
-
- field.focus();
- var cPos=startPos+(value.length);
- field.selectionStart=cPos;
- field.selectionEnd=cPos;
- field.scrollTop=scrollTop;
- } else {
- field.value += "\n"+value;
- }
- // reposition cursor if possible
- if (field.createTextRange) field.caretPos = document.selection.createRange().duplicate();
-}
/**
* For the upload Dialog. Prefills the wikiname.
@@ -321,38 +274,6 @@ function toggleToc() {
}
}
-/**
- * Sizecontrol inspired by TikiWiki. This displays the buttons.
- */
-function showSizeCtl(){
- if(document.getElementById) {
- var textarea = document.getElementById('wikitext');
- var hgt = getCookie('DokuWikisizeCtl');
- if(hgt == null){
- textarea.style.height = '300px';
- }else{
- textarea.style.height = hgt;
- }
- document.writeln('<a href="javascript:sizeCtl(100)"><img src="'+DOKU_BASE+'lib/images/larger.gif" width="20" height="20" border="0"></a>');
- document.writeln('<a href="javascript:sizeCtl(-100)"><img src="'+DOKU_BASE+'lib/images/smaller.gif" width="20" height="20" border="0"></a>');
- }
-}
-
-/**
- * This sets the vertical size of the editbox
- */
-function sizeCtl(val){
- var textarea = document.getElementById('wikitext');
- var height = parseInt(textarea.style.height.substr(0,textarea.style.height.length-2));
- height += val;
- textarea.style.height = height+'px';
-
- var now = new Date();
- fixDate(now);
- now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000); //expire in a year
- setCookie('DokuWikisizeCtl',textarea.style.height,now);
-}
-
/**
* global var used for not saved yet warning
@@ -497,3 +418,43 @@ function fnt(id, e, evt) {
domTT_activate(e, evt, 'content', footnote, 'type', 'velcro', 'id', 'insitu-fn'+id, 'styleClass', 'insitu-footnote', 'maxWidth', document.body.offsetWidth*0.4);
currentFootnote = id;
}
+
+
+/**
+ * Add the edit window size controls
+ */
+function initSizeCtl(ctlid,edid){
+ var ctl = document.getElementById(ctlid);
+ var textarea = document.getElementById(edid);
+
+ var hgt = getCookie('DokuWikisizeCtl');
+ if(hgt == null){
+ textarea.style.height = '300px';
+ }else{
+ textarea.style.height = hgt;
+ }
+
+ var l = document.createElement('img');
+ var s = document.createElement('img');
+ l.src = DOKU_BASE+'lib/images/larger.gif';
+ s.src = DOKU_BASE+'lib/images/smaller.gif';
+ l.onclick = function(){sizeCtl(edid,100);}
+ s.onclick = function(){sizeCtl(edid,-100);}
+ ctl.appendChild(l);
+ ctl.appendChild(s);
+}
+
+/**
+ * This sets the vertical size of the editbox
+ */
+function sizeCtl(edid,val){
+ var textarea = document.getElementById(edid);
+ var height = parseInt(textarea.style.height.substr(0,textarea.style.height.length-2));
+ height += val;
+ textarea.style.height = height+'px';
+
+ var now = new Date();
+ fixDate(now);
+ now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000); //expire in a year
+ setCookie('DokuWikisizeCtl',textarea.style.height,now);
+}