From 74bd6999c5e5c23ebbf90dbb6bdaabbddd7594cf Mon Sep 17 00:00:00 2001 From: sembrestels Date: Thu, 13 Oct 2011 15:23:11 +0200 Subject: Rename lib/dokuwiki to vendors/dokuwiki --- vendors/dokuwiki/lib/scripts/script.js | 561 +++++++++++++++++++++++++++++++++ 1 file changed, 561 insertions(+) create mode 100644 vendors/dokuwiki/lib/scripts/script.js (limited to 'vendors/dokuwiki/lib/scripts/script.js') diff --git a/vendors/dokuwiki/lib/scripts/script.js b/vendors/dokuwiki/lib/scripts/script.js new file mode 100644 index 000000000..491794f13 --- /dev/null +++ b/vendors/dokuwiki/lib/scripts/script.js @@ -0,0 +1,561 @@ +/** + * Some of these scripts were taken from wikipedia.org and were modified for DokuWiki + */ + +/** + * Some browser detection + */ +var clientPC = navigator.userAgent.toLowerCase(); // Get client info +var is_macos = navigator.appVersion.indexOf('Mac') != -1; +var is_gecko = ((clientPC.indexOf('gecko')!=-1) && (clientPC.indexOf('spoofer')==-1) && + (clientPC.indexOf('khtml') == -1) && (clientPC.indexOf('netscape/7.0')==-1)); +var is_safari = ((clientPC.indexOf('AppleWebKit')!=-1) && (clientPC.indexOf('spoofer')==-1)); +var is_khtml = (navigator.vendor == 'KDE' || ( document.childNodes && !document.all && !navigator.taintEnabled )); +if (clientPC.indexOf('opera')!=-1) { + var is_opera = true; + var is_opera_preseven = (window.opera && !document.childNodes); + var is_opera_seven = (window.opera && document.childNodes); +} + +/** + * Handy shortcut to document.getElementById + * + * This function was taken from the prototype library + * + * @link http://prototype.conio.net/ + */ +function DOKUid() { + var elements = new Array(); + + for (var i = 0; i < arguments.length; i++) { + var element = arguments[i]; + if (typeof element == 'string') + element = document.getElementById(element); + + if (arguments.length == 1) + return element; + + elements.push(element); + } + + return elements; +} + +/** + * Simple function to check if a global var is defined + * + * @author Kae Verens + * @link http://verens.com/archives/2005/07/25/isset-for-javascript/#comment-2835 + */ +function isset(varname){ + return(typeof(window[varname])!='undefined'); +} + +/** + * Select elements by their class name + * + * @author Dustin Diaz + * @link http://www.dustindiaz.com/getelementsbyclass/ + */ +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++; + } + } + return classElements; +} + +/** + * 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; + var obj = DOKUid(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; + var obj = DOKUid(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 + */ +function jsEscape(text){ + var re=new RegExp("\\\\","g"); + text=text.replace(re,"\\\\"); + re=new RegExp("'","g"); + text=text.replace(re,"\\'"); + re=new RegExp('"',"g"); + text=text.replace(re,'"'); + 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"); + text=text.replace(re,"\\'"); + re=new RegExp('"',"g"); + text=text.replace(re,'"'); + re=new RegExp("\\n","g"); + text=text.replace(re,"\\n"); + return 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 + * and parsed completely we have to rely on document.write() + * + * @author Andreas Gohr + */ +function showLoadBar(){ + + document.write('...'); + + /* this does not work reliable in IE + obj = DOKUid(id); + + if(obj){ + obj.innerHTML = '...'; + obj.style.display="block"; + } + */ +} + +/** + * Disables the animated gif to show the search is done + * + * @author Andreas Gohr + */ +function hideLoadBar(id){ + obj = DOKUid(id); + if(obj) obj.style.display="none"; +} + +/** + * Adds the toggle switch to the TOC + */ +function addTocToggle() { + if(!document.getElementById) return; + var header = DOKUid('toc__header'); + if(!header) return; + var toc = DOKUid('toc__inside'); + + var obj = document.createElement('span'); + obj.id = 'toc__toggle'; + obj.style.cursor = 'pointer'; + if (toc && toc.style.display == 'none') { + obj.innerHTML = '+'; + obj.className = 'toc_open'; + } else { + obj.innerHTML = ''; + obj.className = 'toc_close'; + } + + prependChild(header,obj); + obj.parentNode.onclick = toggleToc; + try { + obj.parentNode.style.cursor = 'pointer'; + obj.parentNode.style.cursor = 'hand'; + }catch(e){} +} + +/** + * This toggles the visibility of the Table of Contents + */ +function toggleToc() { + var toc = DOKUid('toc__inside'); + var obj = DOKUid('toc__toggle'); + if(toc.style.display == 'none') { + toc.style.display = ''; + obj.innerHTML = ''; + obj.className = 'toc_close'; + } else { + toc.style.display = 'none'; + obj.innerHTML = '+'; + obj.className = 'toc_open'; + } +} + +/** + * Display an insitu footnote popup + * + * @author Andreas Gohr + * @author Chris Smith + */ +function footnote(e){ + var obj = e.target; + var id = obj.id.substr(5); + + // get or create the footnote popup div + var fndiv = DOKUid('insitu__fn'); + if(!fndiv){ + fndiv = document.createElement('div'); + fndiv.id = 'insitu__fn'; + fndiv.className = 'insitu-footnote JSpopup dokuwiki'; + + // autoclose on mouseout - ignoring bubbled up events + addEvent(fndiv,'mouseout',function(e){ + if(e.target != fndiv){ + e.stopPropagation(); + return; + } + // check if the element was really left + if(e.pageX){ // Mozilla + var bx1 = findPosX(fndiv); + var bx2 = bx1 + fndiv.offsetWidth; + var by1 = findPosY(fndiv); + var by2 = by1 + fndiv.offsetHeight; + var x = e.pageX; + var y = e.pageY; + if(x > bx1 && x < bx2 && y > by1 && y < by2){ + // we're still inside boundaries + e.stopPropagation(); + return; + } + }else{ // IE + if(e.offsetX > 0 && e.offsetX < fndiv.offsetWidth-1 && + e.offsetY > 0 && e.offsetY < fndiv.offsetHeight-1){ + // we're still inside boundaries + e.stopPropagation(); + return; + } + } + // okay, hide it + fndiv.style.display='none'; + }); + document.body.appendChild(fndiv); + } + + // locate the footnote anchor element + var a = DOKUid( "fn__"+id ); + if (!a){ return; } + + // anchor parent is the footnote container, get its innerHTML + var content = new String (a.parentNode.parentNode.innerHTML); + + // strip the leading content anchors and their comma separators + content = content.replace(/.*<\/sup>/gi, ''); + content = content.replace(/^\s+(,\s+)+/,''); + + // prefix ids on any elements with "insitu__" to ensure they remain unique + content = content.replace(/\bid=\"(.*?)\"/gi,'id="insitu__$1'); + + // now put the content into the wrapper + fndiv.innerHTML = content; + + // position the div and make it visible + var x; var y; + if(e.pageX){ // Mozilla + x = e.pageX; + y = e.pageY; + }else{ // IE + x = e.offsetX; + y = e.offsetY; + } + fndiv.style.position = 'absolute'; + fndiv.style.left = (x+2)+'px'; + fndiv.style.top = (y+2)+'px'; + fndiv.style.display = ''; +} + +/** + * Add the event handlers to footnotes + * + * @author Andreas Gohr + */ +addInitEvent(function(){ + var elems = getElementsByClass('fn_top',null,'a'); + for(var i=0; i + * @author + * @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 = DOKUid('scroll__here'); + if(obj) obj.scrollIntoView(); +} + +/** + * Looks for an element with the ID focus__this at sets focus to it + */ +function focusMarker(){ + var obj = DOKUid('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 + */ +addInitEvent(function(){ + var revForm = DOKUid('page__revisions'); + if (!revForm) return; + var elems = revForm.elements; + var countTicks = 0; + for (var i=0; i= 2) input2.disabled = (input2.type=='checkbox' && !input2.checked); + else input2.disabled = (input2.type!='checkbox'); + } + }); + input1.checked = false; // chrome reselects on back button which messes up the logic + } else if(input1.type=='submit'){ + input1.disabled = true; + } + } +}); + +/** + * Add the event handler to the actiondropdown + * + * @author Andreas Gohr + */ +addInitEvent(function(){ + var selector = DOKUid('action__selector'); + if(!selector) return; + + addEvent(selector,'change',function(e){ + this.form.submit(); + }); + + DOKUid('action__selectorbtn').style.display = 'none'; +}); + +/** + * Display error for Windows Shares on browsers other than IE + * + * @author Michael Klier + */ +function checkWindowsShares() { + if(!LANG['nosmblinks']) return true; + var elems = getElementsByClass('windows',document,'a'); + if(elems){ + for(var i=0; i + */ +addInitEvent(function(){ + checkWindowsShares(); +}); + +/** + * Highlight the section when hovering over the appropriate section edit button + * + * @author Andreas Gohr + */ +addInitEvent(function(){ + var break_classes = new RegExp('secedit|toc|page'); + var btns = getElementsByClass('btn_secedit',document,'form'); + for(var i=0; i