diff options
author | Andreas Gohr <andi@splitbrain.org> | 2012-06-30 12:03:59 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2012-06-30 12:03:59 +0200 |
commit | 688c5219ce1f6bf1dbda6e733bec881baaa24025 (patch) | |
tree | fa6440c1f772abb06e21c1a2fc4189347ec5c456 /lib/scripts/page.js | |
parent | 0c06a181819249c6a4a2a6c60e13f739df1f2253 (diff) | |
download | rpg-688c5219ce1f6bf1dbda6e733bec881baaa24025.tar.gz rpg-688c5219ce1f6bf1dbda6e733bec881baaa24025.tar.bz2 |
fixed the toc/sidebar toggling script for real
Diffstat (limited to 'lib/scripts/page.js')
-rw-r--r-- | lib/scripts/page.js | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/lib/scripts/page.js b/lib/scripts/page.js index 74dec37fb..78943be7a 100644 --- a/lib/scripts/page.js +++ b/lib/scripts/page.js @@ -102,7 +102,7 @@ dw_page = { * @param selector handle What should be clicked to toggle * @param selector content This element will be toggled */ - makeToggle: function(handle, content){ + makeToggle: function(handle, content, state){ var $handle, $content, $clicky, $child, setClicky; $handle = jQuery(handle); if(!$handle.length) return; @@ -125,32 +125,44 @@ dw_page = { } }; - // the state indicator - $clicky = jQuery(document.createElement('strong')); + $handle[0].setState = function(state){ + var hidden; + if(!state) state = 1; - // click function - $handle.css('cursor','pointer') - .click(function () { - var hidden; + // Assert that content instantly takes the whole space + $content.css('height', $content.height()).show(); - // Assert that content instantly takes the whole space - $content.css('height', $content.height()).show(); + // stop any running animation + $child.stop(true, true); - // stop any running animation and get current state - hidden = $child.stop(true, true).is(':hidden'); + // was a state given or do we toggle? + if(state === -1) { + hidden = false; + } else if(state === 1) { + hidden = true; + } else { + hidden = $child.is(':hidden'); + } - // update the state - setClicky(!hidden); + // update the state + setClicky(!hidden); - // Start animation and assure that $toc is hidden/visible - $child.dw_toggle(hidden, function () { - $content.toggle(hidden); - }); - }) + // Start animation and assure that $toc is hidden/visible + $child.dw_toggle(hidden, function () { + $content.toggle(hidden); + }); + }; + + // the state indicator + $clicky = jQuery(document.createElement('strong')); + + // click function + $handle.css('cursor','pointer') + .click($handle[0].setState) .prepend($clicky); // initial state - setClicky(); + $handle[0].setState(state); } }; |