diff options
Diffstat (limited to 'lib/scripts/script.js')
-rw-r--r-- | lib/scripts/script.js | 134 |
1 files changed, 56 insertions, 78 deletions
diff --git a/lib/scripts/script.js b/lib/scripts/script.js index ccba82144..57917aeb5 100644 --- a/lib/scripts/script.js +++ b/lib/scripts/script.js @@ -9,7 +9,7 @@ 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_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; @@ -78,16 +78,15 @@ function getElementsByClass(searchClass,node,tag) { /** * Get the X offset of the top left corner of the given object * - * @link http://www.quirksmode.org/index.html?/js/findpos.html + * @link http://www.quirksmode.org/js/findpos.html */ function findPosX(object){ var curleft = 0; var obj = $(object); if (obj.offsetParent){ - while (obj.offsetParent){ + do { curleft += obj.offsetLeft; - obj = obj.offsetParent; - } + } while (obj = obj.offsetParent); } else if (obj.x){ curleft += obj.x; @@ -98,16 +97,15 @@ function findPosX(object){ /** * Get the Y offset of the top left corner of the given object * - * @link http://www.quirksmode.org/index.html?/js/findpos.html + * @link http://www.quirksmode.org/js/findpos.html */ function findPosY(object){ var curtop = 0; var obj = $(object); if (obj.offsetParent){ - while (obj.offsetParent){ + do { curtop += obj.offsetTop; - obj = obj.offsetParent; - } + } while (obj = obj.offsetParent); } else if (obj.y){ curtop += obj.y; @@ -215,10 +213,7 @@ function addTocToggle() { prependChild(header,obj); obj.parentNode.onclick = toggleToc; - try { - obj.parentNode.style.cursor = 'pointer'; - obj.parentNode.style.cursor = 'hand'; - }catch(e){} + obj.parentNode.style.cursor = 'pointer'; } /** @@ -239,57 +234,51 @@ function toggleToc() { } /** - * Display an insitu footnote popup - * - * @author Andreas Gohr <andi@splitbrain.org> - * @author Chris Smith <chris@jalakai.co.uk> + * Create JavaScript mouseover popup */ -function footnote(e){ - var obj = e.target; - var id = obj.id.substr(5); +function insitu_popup(target, popup_id) { - // get or create the footnote popup div - var fndiv = $('insitu__fn'); + // get or create the popup div + var fndiv = $(popup_id); if(!fndiv){ fndiv = document.createElement('div'); - fndiv.id = 'insitu__fn'; + fndiv.id = popup_id; 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; + var p = e.relatedTarget || e.toElement; + while (p && p !== this) { + p = p.parentNode; } - // 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; - } + if (p === this) { + return; } // okay, hide it - fndiv.style.display='none'; + this.style.display='none'; }); - document.body.appendChild(fndiv); + getElementsByClass('dokuwiki', document.body, 'div')[0].appendChild(fndiv); } + // 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'; + fndiv.style.display = ''; + return fndiv; +} + +/** + * Display an insitu footnote popup + * + * @author Andreas Gohr <andi@splitbrain.org> + * @author Chris Smith <chris@jalakai.co.uk> + */ +function footnote(e){ + var fndiv = insitu_popup(e.target, 'insitu__fn'); + // locate the footnote anchor element - var a = $( "fn__"+id ); + var a = $("fn__" + e.target.id.substr(5)); if (!a){ return; } // anchor parent is the footnote container, get its innerHTML @@ -300,24 +289,10 @@ function footnote(e){ 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'); + content = content.replace(/\bid=(['"])([^"']+)\1/gi,'id="insitu__$2'); // 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 = ''; } /** @@ -507,14 +482,14 @@ addInitEvent(function(){ */ 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(){ - if(document.all == null) { - alert(LANG['nosmblinks']); - } + alert(LANG['nosmblinks']); }); } } @@ -535,27 +510,30 @@ addInitEvent(function(){ * @author Andreas Gohr <andi@splitbrain.org> */ addInitEvent(function(){ - var break_classes = new RegExp('secedit|toc|page'); var btns = getElementsByClass('btn_secedit',document,'form'); for(var i=0; i<btns.length; i++){ addEvent(btns[i],'mouseover',function(e){ - var tgt = e.target; - if(tgt.form) tgt = tgt.form; - tgt = tgt.parentNode.previousSibling; - if(tgt.nodeName != "DIV") tgt = tgt.previousSibling; - while(!break_classes.test(tgt.className)) { - tgt.className += ' section_highlight'; - if (tgt.tagName == 'H1') break; - tgt = (tgt.previousSibling != null) ? tgt.previousSibling : tgt.parentNode; + var tgt = this.parentNode; + var nr = tgt.className.match(/(\s+|^)editbutton_(\d+)(\s+|$)/)[2]; + do { + tgt = tgt.previousSibling; + } while (tgt !== null && typeof tgt.tagName === 'undefined'); + if (tgt === null) return; + while(typeof tgt.className === 'undefined' || + tgt.className.match('(\\s+|^)sectionedit' + nr + '(\\s+|$)') === null) { + if (typeof tgt.className !== 'undefined') { + tgt.className += ' section_highlight'; + } + tgt = (tgt.previousSibling !== null) ? tgt.previousSibling : tgt.parentNode; } + if (typeof tgt.className !== 'undefined') tgt.className += ' section_highlight'; }); addEvent(btns[i],'mouseout',function(e){ var secs = getElementsByClass('section_highlight'); for(var j=0; j<secs.length; j++){ - secs[j].className = secs[j].className.replace(/section_highlight/,''); + secs[j].className = secs[j].className.replace(/section_highlight/g,''); } - var secs = getElementsByClass('section_highlight'); }); } }); |