lib/TWiki/Configure/JS.pm
changeset 0 414e01d06fd5
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lib/TWiki/Configure/JS.pm	Sat Jan 26 15:50:53 2008 +0100
     1.3 @@ -0,0 +1,128 @@
     1.4 +package TWiki::Configure::JS;
     1.5 +
     1.6 +use strict;
     1.7 +
     1.8 +use vars qw( $js1 $js2 );
     1.9 +
    1.10 +sub js1 {
    1.11 +    local $/ = undef;
    1.12 +    return <DATA>;
    1.13 +}
    1.14 +
    1.15 +sub js2 {
    1.16 +    return <<'HERE';
    1.17 +//<!--
    1.18 +document.write("<style type='text/css'>");
    1.19 +document.write(".foldableBlockClosed {display:none;}");
    1.20 +document.write("<\/style>");
    1.21 +//-->
    1.22 +HERE
    1.23 +}
    1.24 +
    1.25 +1;
    1.26 +__DATA__
    1.27 +//<!--
    1.28 +
    1.29 +var lastOpenBlock = null;
    1.30 +var lastOpenBlockLink = null;
    1.31 +var allBlocks = null; // array of all foldable blocks
    1.32 +var allBlockLinks = null; // array of all foldable block links (headers)
    1.33 +
    1.34 +function foldBlock(id) {
    1.35 +    var shouldClose = false;
    1.36 +    var block = null;
    1.37 +    if (lastOpenBlock == null) {
    1.38 +        block = document.getElementById(id);
    1.39 +        if (block.open) {
    1.40 +            shouldClose = true;
    1.41 +        }
    1.42 +    }
    1.43 +    if (shouldClose) {
    1.44 +        closeBlock(id);
    1.45 +    } else {
    1.46 +        var o = openBlock(id);
    1.47 +        if (lastOpenBlock != null) {
    1.48 +            closeBlockElement(lastOpenBlock, lastOpenBlockLink);
    1.49 +        }
    1.50 +    }
    1.51 +    if (o && o.block) {
    1.52 +        lastOpenBlock = (lastOpenBlock == o.block) ? null : o.block;
    1.53 +    }
    1.54 +    if (o && o.blockLink) {
    1.55 +        lastOpenBlockLink = (lastOpenBlockLink == o.blockLink) ? null : o.blockLink;
    1.56 +    }
    1.57 +}
    1.58 +
    1.59 +function openBlock(id) {
    1.60 +    var block = document.getElementById(id);
    1.61 +    var blockLink = document.getElementById('blockLink' + id);
    1.62 +    openBlockElement(block, blockLink);
    1.63 +    return {block:block, blockLink:blockLink};
    1.64 +}
    1.65 +
    1.66 +function openBlockElement(block, blockLink) {
    1.67 +    block.className = 'foldableBlock foldableBlockOpen';
    1.68 +    block.open = true;
    1.69 +    blockLink.className = 'blockLink blockLinkOn';
    1.70 +}
    1.71 +
    1.72 +function closeBlock(id) {
    1.73 +    var block = document.getElementById(id);
    1.74 +    var blockLink = document.getElementById('blockLink' + id);
    1.75 +    closeBlockElement(block, blockLink);
    1.76 +    return {block:block, blockLink:blockLink};
    1.77 +}
    1.78 +
    1.79 +function closeBlockElement(block, blockLink) {
    1.80 +    block.className = 'foldableBlock foldableBlockClosed';
    1.81 +    block.open = false;
    1.82 +    blockLink.className = 'blockLink blockLinkOff';
    1.83 +}
    1.84 +
    1.85 +function toggleAllOptions(open) {
    1.86 +    if (allBlocks == null) {
    1.87 +        allBlocks = getElementsByClassName('foldableBlock');
    1.88 +    }
    1.89 +    if (allBlockLinks == null) {
    1.90 +        allBlockLinks = getElementsByClassName('blockLink');
    1.91 +    }
    1.92 +    var i, ilen=allBlocks.length;
    1.93 +    if (open) {
    1.94 +        for (i=0; i<ilen; ++i) {
    1.95 +            openBlockElement(allBlocks[i], allBlockLinks[i]);
    1.96 +        }
    1.97 +    } else {
    1.98 +        for (i=0; i<ilen; ++i) {
    1.99 +            closeBlockElement(allBlocks[i], allBlockLinks[i]);
   1.100 +        }
   1.101 +    }
   1.102 +    lastOpenBlock = null;
   1.103 +    lastOpenBlockLink = null;
   1.104 +}
   1.105 +
   1.106 +function getElementsByClassName(class_name)
   1.107 +{
   1.108 +    var all_obj, ret_obj = new Array();
   1.109 +    if (document.all)
   1.110 +        all_obj=document.all;
   1.111 +     else if (document.getElementsByTagName && !document.all)
   1.112 +        all_obj=document.getElementsByTagName("*");
   1.113 +    var len = all_obj.length;
   1.114 +    for (i=0;i<len;++i) {
   1.115 +        var myClass = all_obj[i].className;
   1.116 +         if (myClass == class_name) {
   1.117 +            ret_obj.push(all_obj[i]);
   1.118 +        } else {
   1.119 +            var classElems = myClass.split(" ");
   1.120 +            var elemLen = classElems.length;
   1.121 +            for (ii=0; ii<elemLen; ++ii) {
   1.122 +                if (classElems[ii] == class_name) {
   1.123 +                    ret_obj.push(all_obj[i]);
   1.124 +                }
   1.125 +            }    
   1.126 +        }
   1.127 +    }
   1.128 +    return ret_obj;
   1.129 +}
   1.130 +//-->
   1.131 +