aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib/scripts/script.js
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2006-11-10 21:15:41 +0100
committerAndreas Gohr <andi@splitbrain.org>2006-11-10 21:15:41 +0100
commit6b379cbf0a8e0d4f0e2dcb639808b944ac8afa66 (patch)
tree1c23a94a4f5a00c4291b4b0ed8e00b5e5f793774 /lib/scripts/script.js
parentda96af357215605d855d6ce8ef8fb50ffb679641 (diff)
downloaddokuwiki-6b379cbf0a8e0d4f0e2dcb639808b944ac8afa66.tar.gz
dokuwiki-6b379cbf0a8e0d4f0e2dcb639808b944ac8afa66.zip
DOMlib removed
The DOMlib javascript library was removed. It was only used for footnote tooltips and access key fixup. Removing the library creates a much smaller JavaScript footprint. The size of the compacted non-edit Javascript output was reduces from 56110 bytes down to 29296 bytes. The footnote tooltip was completely rewritten and tested in FireFox 2.0, IE 6 and Opera 9.02. Please test other browsers as well. The acces key fixup might beahve different now on Mac platforms. darcs-hash:20061110201541-7ad00-0dffad095193bc7e7c505796a99b0a0a010a6b0d.gz
Diffstat (limited to 'lib/scripts/script.js')
-rw-r--r--lib/scripts/script.js153
1 files changed, 109 insertions, 44 deletions
diff --git a/lib/scripts/script.js b/lib/scripts/script.js
index c8963e1d6..6e9fd9334 100644
--- a/lib/scripts/script.js
+++ b/lib/scripts/script.js
@@ -27,15 +27,30 @@ if (clientPC.indexOf('opera')!=-1) {
function updateAccessKeyTooltip() {
// determin tooltip text (order matters)
var tip = 'ALT+'; //default
- if (domLib_isMac) { tip = 'CTRL+'; }
- if (domLib_isOpera) { tip = 'SHIFT+ESC '; }
+ if (is_safari) { tip = 'CTRL+'; }
+ if (is_opera) { tip = 'SHIFT+ESC '; }
// add other cases here...
// do tooltip update
if (tip=='ALT+') { return; }
var exp = /\[ALT\+/i;
var rep = '['+tip;
- var elements = domLib_getElementsByTagNames(['a', 'input', 'button']);
+
+ var elements = document.getElementsByTagName('a');
+ for (var i=0; i<elements.length; i++) {
+ if (elements[i].accessKey.length==1 && elements[i].title.length>0) {
+ elements[i].title = elements[i].title.replace(exp, rep);
+ }
+ }
+
+ elements = document.getElementsByTagName('input');
+ for (var i=0; i<elements.length; i++) {
+ if (elements[i].accessKey.length==1 && elements[i].title.length>0) {
+ elements[i].title = elements[i].title.replace(exp, rep);
+ }
+ }
+
+ elements = document.getElementsByTagName('button');
for (var i=0; i<elements.length; i++) {
if (elements[i].accessKey.length==1 && elements[i].title.length>0) {
elements[i].title = elements[i].title.replace(exp, rep);
@@ -225,23 +240,23 @@ function hideLoadBar(id){
function addTocToggle() {
if(!document.getElementById) return;
var header = $('toc__header');
- if(!header) return;
+ if(!header) return;
- var showimg = document.createElement('img');
+ var showimg = document.createElement('img');
showimg.id = 'toc__show';
- showimg.src = DOKU_BASE+'lib/images/arrow_down.gif';
- showimg.alt = '+';
+ showimg.src = DOKU_BASE+'lib/images/arrow_down.gif';
+ showimg.alt = '+';
showimg.onclick = toggleToc;
- showimg.style.display = 'none';
+ showimg.style.display = 'none';
var hideimg = document.createElement('img');
hideimg.id = 'toc__hide';
- hideimg.src = DOKU_BASE+'lib/images/arrow_up.gif';
- hideimg.alt = '-';
+ hideimg.src = DOKU_BASE+'lib/images/arrow_up.gif';
+ hideimg.alt = '-';
hideimg.onclick = toggleToc;
- prependChild(header,showimg);
- prependChild(header,hideimg);
+ prependChild(header,showimg);
+ prependChild(header,hideimg);
}
/**
@@ -262,7 +277,7 @@ function toggleToc() {
}
}
-/*
+/**
* This enables/disables checkboxes for acl-administration
*
* @author Frank Schubert <frank@schokilade.de>
@@ -286,48 +301,98 @@ function checkAclLevel(){
}
/**
- * insitu footnote addition
- *
- * provide a wrapper for domTT javascript library
- * this function is placed in the onmouseover event of footnote references in the main page
+ * Display an insitu footnote popup
*
- * @author Chris Smith <chris [at] jalakai [dot] co [dot] uk>
+ * @author Andreas Gohr <andi@splitbrain.org>
+ * @author Chris Smith <chris@jalakai.co.uk>
*/
-var currentFootnote = 0;
-function fnt(id, e, evt) {
-
- if (currentFootnote && id != currentFootnote) {
- domTT_close($('insitu__fn'+currentFootnote));
+function footnote(e){
+ var obj = e.target;
+ var id = obj.id.substr(5);
+
+ // get or create the footnote popup div
+ var fndiv = $('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);
}
- // does the footnote tooltip already exist?
- var fnote = $('insitu__fn'+id);
- var footnote;
- if (!fnote) {
- // if not create it...
+ // locate the footnote anchor element
+ var a = $( "fn__"+id );
+ if (!a){ return; }
- // locate the footnote anchor element
- var a = $( "fn__"+id );
- if (!a){ return; }
+ // anchor parent is the footnote container, get its innerHTML
+ var content = new String (a.parentNode.innerHTML);
- // anchor parent is the footnote container, get its innerHTML
- footnote = new String (a.parentNode.innerHTML);
+ // strip the leading content anchors and their comma separators
+ content = content.replace(/<a\s.*?href=\".*\#fnt__\d+\".*?<\/a>/gi, '');
+ content = content.replace(/^\s+(,\s+)+/,'');
- // strip the leading footnote anchors and their comma separators
- footnote = footnote.replace(/<a\s.*?href=\".*\#fnt__\d+\".*?<\/a>/gi, '');
- footnote = footnote.replace(/^\s+(,\s+)+/,'');
+ // prefix ids on any elements with "insitu__" to ensure they remain unique
+ content = content.replace(/\bid=\"(.*?)\"/gi,'id="insitu__$1');
- // prefix ids on any elements with "insitu__" to ensure they remain unique
- footnote = footnote.replace(/\bid=\"(.*?)\"/gi,'id="insitu__$1');
- } else {
- footnote = new String(fnt.innerHTML);
- }
+ // now put the content into the wrapper
+ fndiv.innerHTML = content;
- // activate the tooltip
- domTT_activate(e, evt, 'content', footnote, 'type', 'velcro', 'id', 'insitu__fn'+id, 'styleClass', 'insitu-footnote JSpopup dokuwiki', 'maxWidth', document.body.offsetWidth*0.4);
- currentFootnote = id;
+ // 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 <andi@splitbrain.org>
+ */
+addInitEvent(function(){
+ var elems = getElementsByClass('fn_top',null,'a');
+ for(var i=0; i<elems.length; i++){
+ addEvent(elems[i],'mouseover',function(e){footnote(e);});
+ }
+});
/**
* Add the edit window size controls