diff options
Diffstat (limited to 'lib/scripts/behaviour.js')
-rw-r--r-- | lib/scripts/behaviour.js | 56 |
1 files changed, 52 insertions, 4 deletions
diff --git a/lib/scripts/behaviour.js b/lib/scripts/behaviour.js index 62c20eb0f..dd7676432 100644 --- a/lib/scripts/behaviour.js +++ b/lib/scripts/behaviour.js @@ -8,7 +8,6 @@ * automatically whenever a certain object is in the DOM or a certain CSS * class was found */ - var dw_behaviour = { init: function(){ @@ -18,15 +17,16 @@ var dw_behaviour = { dw_behaviour.removeHighlightOnClick(); dw_behaviour.quickSelect(); dw_behaviour.checkWindowsShares(); + dw_behaviour.initTocToggle(); }, /** * Looks for an element with the ID scroll__here at scrolls to it */ scrollToMarker: function(){ - var obj = jQuery('#scroll__here'); - if(obj.length) { - obj[0].scrollIntoView(); + var $obj = jQuery('#scroll__here'); + if($obj.length) { + $obj[0].scrollIntoView(); } }, @@ -90,8 +90,56 @@ var dw_behaviour = { jQuery('a.windows').live('click', function(){ alert(LANG.nosmblinks); }); + }, + + /** + * Adds the toggle switch to the TOC + */ + initTocToggle: function() { + var $header = jQuery('#toc__header'); + if(!$header.length) return; + var $toc = jQuery('#toc__inside'); + + var $clicky = jQuery(document.createElement('span')) + .attr('id','toc__toggle') + .css('cursor','pointer') + .click(function(){ + $toc.slideToggle(); + setClicky(); + }); + $header.prepend($clicky); + + var setClicky = function(){ + if($toc.css('display') == 'none'){ + $clicky.html('<span>+</span>'); + $clicky[0].className = 'toc_open'; + }else{ + $clicky.html('<span>−</span>'); + $clicky[0].className = 'toc_close'; + } + }; + + setClicky(); } }; +jQuery.fn.dw_hide = function(fn) { + return this.slideUp('fast', fn); +}; + +jQuery.fn.dw_show = function() { + return this.slideDown('fast'); +}; + +jQuery.fn.dw_toggle = function(bool) { + return this.each(function() { + var $this = jQuery(this); + if (typeof bool === 'undefined') { + bool = $this.is(':hidden'); + } + $this[bool ? "dw_show" : "dw_hide" ](); + }); +}; + jQuery(dw_behaviour.init); |