diff options
Diffstat (limited to 'lib/scripts/script.js')
-rw-r--r-- | lib/scripts/script.js | 357 |
1 files changed, 84 insertions, 273 deletions
diff --git a/lib/scripts/script.js b/lib/scripts/script.js index c79c9b683..b44d95d6f 100644 --- a/lib/scripts/script.js +++ b/lib/scripts/script.js @@ -1,3 +1,51 @@ +// if jQuery was loaded, let's make it noConflict here. +if ('function' === typeof jQuery && 'function' === typeof jQuery.noConflict) { + jQuery.noConflict(); +} + +/** + * Mark a JavaScript function as deprecated + * + * This will print a warning to the JavaScript console (if available) in + * Firebug and Chrome and a stack trace (if available) to easily locate the + * problematic function call. + * + * @param msg optional message to print + */ +function DEPRECATED(msg){ + if(!window.console) return; + if(!msg) msg = ''; + + var func; + if(arguments.callee) func = arguments.callee.caller.name; + if(func) func = ' '+func+'()'; + var line = 'DEPRECATED function call'+func+'. '+msg; + + if(console.warn){ + console.warn(line); + }else{ + console.log(line); + } + + if(console.trace) console.trace(); +} + +/** + * Construct a wrapper function for deprecated function names + * + * This function returns a wrapper function which just calls DEPRECATED + * and the new function. + * + * @param func The new function + * @param context Optional; The context (`this`) of the call + */ +function DEPRECATED_WRAP(func, context) { + return function () { + DEPRECATED(); + return func.apply(context || this, arguments); + } +} + /** * Some of these scripts were taken from wikipedia.org and were modified for DokuWiki */ @@ -25,6 +73,8 @@ if (clientPC.indexOf('opera')!=-1) { * @link http://prototype.conio.net/ */ function $() { + DEPRECATED('Please use the JQuery() function instead.'); + var elements = new Array(); for (var i = 0; i < arguments.length; i++) { @@ -52,68 +102,20 @@ function isset(varname){ } /** - * Select elements by their class name + * Get the computed style of a node. * - * @author Dustin Diaz <dustin [at] dustindiaz [dot] com> - * @link http://www.dustindiaz.com/getelementsbyclass/ + * @link https://acidmartin.wordpress.com/2008/08/26/style-get-any-css-property-value-of-an-object/ + * @link http://svn.dojotoolkit.org/src/dojo/trunk/_base/html.js */ -function getElementsByClass(searchClass,node,tag) { - var classElements = new Array(); - if ( node == null ) - node = document; - if ( tag == null ) - tag = '*'; - var els = node.getElementsByTagName(tag); - var elsLen = els.length; - var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"); - for (var i = 0, j = 0; i < elsLen; i++) { - if ( pattern.test(els[i].className) ) { - classElements[j] = els[i]; - j++; - } +function gcs(node){ + if(node.currentStyle){ + return node.currentStyle; + }else{ + return node.ownerDocument.defaultView.getComputedStyle(node, null); } - return classElements; } /** - * Get the X offset of the top left corner of the given object - * - * @link http://www.quirksmode.org/js/findpos.html - */ -function findPosX(object){ - var curleft = 0; - var obj = $(object); - if (obj.offsetParent){ - do { - curleft += obj.offsetLeft; - } while (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/js/findpos.html - */ -function findPosY(object){ - var curtop = 0; - var obj = $(object); - if (obj.offsetParent){ - do { - curtop += obj.offsetTop; - } while (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> @@ -145,19 +147,6 @@ function escapeQuotes(text) { } /** - * Adds a node as the first childenode to the given parent - * - * @see appendChild() - */ -function prependChild(parent,element) { - if(!parent.firstChild){ - parent.appendChild(element); - }else{ - parent.insertBefore(element,parent.firstChild); - } -} - -/** * Prints a animated gif to show the search is performed * * Because we need to modify the DOM here before the document is loaded @@ -191,47 +180,6 @@ function hideLoadBar(id){ if(obj) obj.style.display="none"; } -/** - * Adds the toggle switch to the TOC - */ -function addTocToggle() { - if(!document.getElementById) return; - var header = $('toc__header'); - if(!header) return; - var toc = $('toc__inside'); - - var obj = document.createElement('span'); - obj.id = 'toc__toggle'; - obj.style.cursor = 'pointer'; - if (toc && toc.style.display == 'none') { - obj.innerHTML = '<span>+</span>'; - obj.className = 'toc_open'; - } else { - obj.innerHTML = '<span>−</span>'; - obj.className = 'toc_close'; - } - - prependChild(header,obj); - obj.parentNode.onclick = toggleToc; - obj.parentNode.style.cursor = 'pointer'; -} - -/** - * This toggles the visibility of the Table of Contents - */ -function toggleToc() { - var toc = $('toc__inside'); - var obj = $('toc__toggle'); - if(toc.style.display == 'none') { - toc.style.display = ''; - obj.innerHTML = '<span>−</span>'; - obj.className = 'toc_close'; - } else { - toc.style.display = 'none'; - obj.innerHTML = '<span>+</span>'; - obj.className = 'toc_open'; - } -} /** * Create JavaScript mouseover popup @@ -260,10 +208,32 @@ function insitu_popup(target, popup_id) { getElementsByClass('dokuwiki', document.body, 'div')[0].appendChild(fndiv); } + var non_static_parent = fndiv.parentNode; + while (non_static_parent != document && gcs(non_static_parent)['position'] == 'static') { + non_static_parent = non_static_parent.parentNode; + } + + var fixed_target_parent = target; + while (fixed_target_parent != document && gcs(fixed_target_parent)['position'] != 'fixed') { + fixed_target_parent = fixed_target_parent.parentNode; + } + // position the div and make it visible - fndiv.style.position = 'absolute'; - fndiv.style.left = findPosX(target)+'px'; - fndiv.style.top = (findPosY(target)+target.offsetHeight * 1.5) + 'px'; + if (fixed_target_parent != document) { + // the target has position fixed, that means the footnote needs to be fixed, too + fndiv.style.position = 'fixed'; + } else { + fndiv.style.position = 'absolute'; + } + + if (fixed_target_parent != document || non_static_parent == document) { + fndiv.style.left = findPosX(target)+'px'; + fndiv.style.top = (findPosY(target)+target.offsetHeight * 1.5) + 'px'; + } else { + fndiv.style.left = (findPosX(target) - findPosX(non_static_parent)) +'px'; + fndiv.style.top = (findPosY(target)+target.offsetHeight * 1.5 - findPosY(non_static_parent)) + 'px'; + } + fndiv.style.display = ''; return fndiv; } @@ -307,127 +277,12 @@ 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 */ function closePopups(){ - if(!document.getElementById){ return; } - - var divs = document.getElementsByTagName('div'); - for(var i=0; i < divs.length; i++){ - if(divs[i].className.indexOf('JSpopup') != -1){ - divs[i].style.display = 'none'; - } - } -} - -/** - * Looks for an element with the ID scroll__here at scrolls to it - */ -function scrollToMarker(){ - var obj = $('scroll__here'); - if(obj) obj.scrollIntoView(); -} - -/** - * Looks for an element with the ID focus__this at sets focus to it - */ -function focusMarker(){ - var obj = $('focus__this'); - if(obj) obj.focus(); -} - -/** - * Remove messages - */ -function cleanMsgArea(){ - var elems = getElementsByClass('(success|info|error)',document,'div'); - if(elems){ - for(var i=0; i<elems.length; i++){ - elems[i].style.display = 'none'; - } - } + jQuery('div.JSpopup').hide(); } /** @@ -459,50 +314,6 @@ addInitEvent(function(){ } }); -/** - * Add the event handler to the actiondropdown - * - * @author Andreas Gohr <andi@splitbrain.org> - */ -addInitEvent(function(){ - var selector = $('action__selector'); - if(!selector) return; - - addEvent(selector,'change',function(e){ - this.form.submit(); - }); - - $('action__selectorbtn').style.display = 'none'; -}); - -/** - * Display error for Windows Shares on browsers other than IE - * - * @author Michael Klier <chi@chimeric.de> - */ -function checkWindowsShares() { - if(!LANG['nosmblinks']) return true; - if(document.all != null) return true; - - var elems = getElementsByClass('windows',document,'a'); - if(elems){ - for(var i=0; i<elems.length; i++){ - var share = elems[i]; - addEvent(share,'click',function(){ - alert(LANG['nosmblinks']); - }); - } - } -} - -/** - * Add the event handler for the Windows Shares check - * - * @author Michael Klier <chi@chimeric.de> - */ -addInitEvent(function(){ - checkWindowsShares(); -}); /** * Highlight the section when hovering over the appropriate section edit button |