lib/TWiki/Configure/JS.pm
author Colas Nahaboo <colas@nahaboo.net>
Sat, 26 Jan 2008 15:50:53 +0100
changeset 0 414e01d06fd5
permissions -rw-r--r--
RELEASE 4.2.0 freetown
colas@0
     1
package TWiki::Configure::JS;
colas@0
     2
colas@0
     3
use strict;
colas@0
     4
colas@0
     5
use vars qw( $js1 $js2 );
colas@0
     6
colas@0
     7
sub js1 {
colas@0
     8
    local $/ = undef;
colas@0
     9
    return <DATA>;
colas@0
    10
}
colas@0
    11
colas@0
    12
sub js2 {
colas@0
    13
    return <<'HERE';
colas@0
    14
//<!--
colas@0
    15
document.write("<style type='text/css'>");
colas@0
    16
document.write(".foldableBlockClosed {display:none;}");
colas@0
    17
document.write("<\/style>");
colas@0
    18
//-->
colas@0
    19
HERE
colas@0
    20
}
colas@0
    21
colas@0
    22
1;
colas@0
    23
__DATA__
colas@0
    24
//<!--
colas@0
    25
colas@0
    26
var lastOpenBlock = null;
colas@0
    27
var lastOpenBlockLink = null;
colas@0
    28
var allBlocks = null; // array of all foldable blocks
colas@0
    29
var allBlockLinks = null; // array of all foldable block links (headers)
colas@0
    30
colas@0
    31
function foldBlock(id) {
colas@0
    32
    var shouldClose = false;
colas@0
    33
    var block = null;
colas@0
    34
    if (lastOpenBlock == null) {
colas@0
    35
        block = document.getElementById(id);
colas@0
    36
        if (block.open) {
colas@0
    37
            shouldClose = true;
colas@0
    38
        }
colas@0
    39
    }
colas@0
    40
    if (shouldClose) {
colas@0
    41
        closeBlock(id);
colas@0
    42
    } else {
colas@0
    43
        var o = openBlock(id);
colas@0
    44
        if (lastOpenBlock != null) {
colas@0
    45
            closeBlockElement(lastOpenBlock, lastOpenBlockLink);
colas@0
    46
        }
colas@0
    47
    }
colas@0
    48
    if (o && o.block) {
colas@0
    49
        lastOpenBlock = (lastOpenBlock == o.block) ? null : o.block;
colas@0
    50
    }
colas@0
    51
    if (o && o.blockLink) {
colas@0
    52
        lastOpenBlockLink = (lastOpenBlockLink == o.blockLink) ? null : o.blockLink;
colas@0
    53
    }
colas@0
    54
}
colas@0
    55
colas@0
    56
function openBlock(id) {
colas@0
    57
    var block = document.getElementById(id);
colas@0
    58
    var blockLink = document.getElementById('blockLink' + id);
colas@0
    59
    openBlockElement(block, blockLink);
colas@0
    60
    return {block:block, blockLink:blockLink};
colas@0
    61
}
colas@0
    62
colas@0
    63
function openBlockElement(block, blockLink) {
colas@0
    64
    block.className = 'foldableBlock foldableBlockOpen';
colas@0
    65
    block.open = true;
colas@0
    66
    blockLink.className = 'blockLink blockLinkOn';
colas@0
    67
}
colas@0
    68
colas@0
    69
function closeBlock(id) {
colas@0
    70
    var block = document.getElementById(id);
colas@0
    71
    var blockLink = document.getElementById('blockLink' + id);
colas@0
    72
    closeBlockElement(block, blockLink);
colas@0
    73
    return {block:block, blockLink:blockLink};
colas@0
    74
}
colas@0
    75
colas@0
    76
function closeBlockElement(block, blockLink) {
colas@0
    77
    block.className = 'foldableBlock foldableBlockClosed';
colas@0
    78
    block.open = false;
colas@0
    79
    blockLink.className = 'blockLink blockLinkOff';
colas@0
    80
}
colas@0
    81
colas@0
    82
function toggleAllOptions(open) {
colas@0
    83
    if (allBlocks == null) {
colas@0
    84
        allBlocks = getElementsByClassName('foldableBlock');
colas@0
    85
    }
colas@0
    86
    if (allBlockLinks == null) {
colas@0
    87
        allBlockLinks = getElementsByClassName('blockLink');
colas@0
    88
    }
colas@0
    89
    var i, ilen=allBlocks.length;
colas@0
    90
    if (open) {
colas@0
    91
        for (i=0; i<ilen; ++i) {
colas@0
    92
            openBlockElement(allBlocks[i], allBlockLinks[i]);
colas@0
    93
        }
colas@0
    94
    } else {
colas@0
    95
        for (i=0; i<ilen; ++i) {
colas@0
    96
            closeBlockElement(allBlocks[i], allBlockLinks[i]);
colas@0
    97
        }
colas@0
    98
    }
colas@0
    99
    lastOpenBlock = null;
colas@0
   100
    lastOpenBlockLink = null;
colas@0
   101
}
colas@0
   102
colas@0
   103
function getElementsByClassName(class_name)
colas@0
   104
{
colas@0
   105
    var all_obj, ret_obj = new Array();
colas@0
   106
    if (document.all)
colas@0
   107
        all_obj=document.all;
colas@0
   108
     else if (document.getElementsByTagName && !document.all)
colas@0
   109
        all_obj=document.getElementsByTagName("*");
colas@0
   110
    var len = all_obj.length;
colas@0
   111
    for (i=0;i<len;++i) {
colas@0
   112
        var myClass = all_obj[i].className;
colas@0
   113
         if (myClass == class_name) {
colas@0
   114
            ret_obj.push(all_obj[i]);
colas@0
   115
        } else {
colas@0
   116
            var classElems = myClass.split(" ");
colas@0
   117
            var elemLen = classElems.length;
colas@0
   118
            for (ii=0; ii<elemLen; ++ii) {
colas@0
   119
                if (classElems[ii] == class_name) {
colas@0
   120
                    ret_obj.push(all_obj[i]);
colas@0
   121
                }
colas@0
   122
            }    
colas@0
   123
        }
colas@0
   124
    }
colas@0
   125
    return ret_obj;
colas@0
   126
}
colas@0
   127
//-->
colas@0
   128