Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The jQuery cookie plugin is very easy to use. Essentially all you need to do use set a flag via a cookie when the toggle is used.</p> <p>To set a value site-wide, a simple statement like this works:</p> <pre><code>$.cookie("currentToggle", "on", {path: "/"}); </code></pre> <p>And then to get the value when you need it, use:</p> <pre><code>var currentState = $.cookie("currentToggle"); </code></pre> <p>I'm not sure exactly how you plan to use it the toggle, but let's say for example's sake, you need to track the state across multiple pages. You could easily set a cookie when the toggle fires, keeping track of which state it's in (on/off, etc.). During other page loads, a common script could check for the cookie and based on the flag, set the toggle. This would give the appearance the site is 'remembering' the previous state across pages.</p> <p>Just a sample use anyway. Hope this helps.</p> <p>jQuery Cookie Plugin: <a href="http://www.stilbuero.de/2006/09/17/cookie-plugin-for-jquery/" rel="noreferrer">http://www.stilbuero.de/2006/09/17/cookie-plugin-for-jquery/</a></p> <p><strong>Edit to provide implementation sample:</strong></p> <p>Here is a sample implementation that works. Requires jQuery and jQuery cookie plugin be referenced, and one css definition. Works across multiple pages when all scripts and CSS are defined on each page.</p> <p>Javascript:</p> <pre><code>$(document).ready(function() { var button = $('#hideButton'); //check the cookie when the page loads if ($.cookie('currentToggle') === 'hidden') { togglePanel(button, false); } else { togglePanel(button, true); } //handle the clicking of the show/hide toggle button button.click(function() { //toggle the panel as required, base on current state if (button.text() === "+Show") { togglePanel($(this), true); } else { togglePanel($(this), false); } }); }); function togglePanel(button, show) { var panel = $('#panel'); if (show) { panel.removeClass('hidden'); button.text('-Hide'); $.cookie('currentToggle', '', { path: '/' }); } else { panel.addClass('hidden'); button.text('+Show'); $.cookie('currentToggle', 'hidden', { path: '/' }); } } </code></pre> <p>CSS:</p> <pre><code>.hidden { display: none; } </code></pre> <p>Markup:</p> <pre><code>&lt;a id="hideButton" href="javascript:;"&gt;-Hide&lt;/a&gt; &lt;div id="panel"&gt; &lt;p&gt;Hello World&lt;/p&gt; &lt;/div&gt; </code></pre> <p>There are likely many more efficient ways to implement it, but for a quick proof of concept the above works well.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload