Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="menu">
  <img src="https://d3ki9tyy5l5ruj.cloudfront.net/obj/3ac85a538c3fc5bb08d0206ede04ae8aa13c20b2/inapp__logo_color_ondark_horizontal.svg" alt="asana" id="asanaLogo" />
</div>
<div class="content">
  <a href="#" class="icon-open">
    <i class="fa fa-bars" aria-hidden="true"></i>
  </a>
  <a href="#" class="icon-close">
    <i class="fa fa-times" aria-hidden="true"></i>
  </a>
  <h5>Add Cookie in collapsible asana-like sidebar using jquery</h5>
  <br /><p>If you use asana, this design will be familiar. The idea behind this pen is to mimmic the todo app's collapsable sidebar, while retaining the information for future use (or pen refresh).</p>
  <p>As you may have guessed it (or even read it above), I'm using jquery and JavaScript Cookie (v2.1.4) by Klaus Hartl & Fagner Brack to set the user's settings.</p>
  <p>Simply use the console and type... <pre>document.cookie</pre> ... in order to query the cookies. You'll see 'menu-state=open' when open and 'menu-state=closed' when sidebar is collapsed.</p>
<p><b>Refresh the page</b> to see whether your preference sticks!</p>
</div>
              
            
!

CSS

              
                #asanaLogo {
  width:110px;
}
.menu {
  width:240px;
  background:#2E3C54;
  height:100vh;
  position:absolute;
  top:0;
  left:0;
  bottom:0;
  padding:15px 10px 10px 10px;
  color:white;
}
.content {
  position:absolute;
  top:0;
  left:240px;
  bottom:0;
  padding:50px;
}
a.icon-close {
  position:absolute;
  left:-40px;
  top:10px;
  color:white;
  &:hover {
    opacity:.8;
  }
}
.fa-bars {
  color:#898E95;
  border:1px solid #E1E2E4;
  font-size:18px;
  padding:8px;
  position:absolute;
  top:0;
  left:0;
  &:hover {
    background:#EFF0F1;
  }
}
pre {
  background:pink;
  color:#96B38A;
  background:black;
  padding:10px;
  width:250px;
  border-left:5px solid #FF9800;
  font-style:italic;
}
              
            
!

JS

              
                /*!
 * JavaScript Cookie v2.1.4
 * https://github.com/js-cookie/js-cookie
 *
 * Copyright 2006, 2015 Klaus Hartl & Fagner Brack
 * Released under the MIT license
 */
;(function (factory) {
	var registeredInModuleLoader = false;
	if (typeof define === 'function' && define.amd) {
		define(factory);
		registeredInModuleLoader = true;
	}
	if (typeof exports === 'object') {
		module.exports = factory();
		registeredInModuleLoader = true;
	}
	if (!registeredInModuleLoader) {
		var OldCookies = window.Cookies;
		var api = window.Cookies = factory();
		api.noConflict = function () {
			window.Cookies = OldCookies;
			return api;
		};
	}
}(function () {
	function extend () {
		var i = 0;
		var result = {};
		for (; i < arguments.length; i++) {
			var attributes = arguments[ i ];
			for (var key in attributes) {
				result[key] = attributes[key];
			}
		}
		return result;
	}

	function init (converter) {
		function api (key, value, attributes) {
			var result;
			if (typeof document === 'undefined') {
				return;
			}

			// Write

			if (arguments.length > 1) {
				attributes = extend({
					path: '/'
				}, api.defaults, attributes);

				if (typeof attributes.expires === 'number') {
					var expires = new Date();
					expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5);
					attributes.expires = expires;
				}

				// We're using "expires" because "max-age" is not supported by IE
				attributes.expires = attributes.expires ? attributes.expires.toUTCString() : '';

				try {
					result = JSON.stringify(value);
					if (/^[\{\[]/.test(result)) {
						value = result;
					}
				} catch (e) {}

				if (!converter.write) {
					value = encodeURIComponent(String(value))
						.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
				} else {
					value = converter.write(value, key);
				}

				key = encodeURIComponent(String(key));
				key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent);
				key = key.replace(/[\(\)]/g, escape);

				var stringifiedAttributes = '';

				for (var attributeName in attributes) {
					if (!attributes[attributeName]) {
						continue;
					}
					stringifiedAttributes += '; ' + attributeName;
					if (attributes[attributeName] === true) {
						continue;
					}
					stringifiedAttributes += '=' + attributes[attributeName];
				}
				return (document.cookie = key + '=' + value + stringifiedAttributes);
			}

			// Read

			if (!key) {
				result = {};
			}

			// To prevent the for loop in the first place assign an empty array
			// in case there are no cookies at all. Also prevents odd result when
			// calling "get()"
			var cookies = document.cookie ? document.cookie.split('; ') : [];
			var rdecode = /(%[0-9A-Z]{2})+/g;
			var i = 0;

			for (; i < cookies.length; i++) {
				var parts = cookies[i].split('=');
				var cookie = parts.slice(1).join('=');

				if (cookie.charAt(0) === '"') {
					cookie = cookie.slice(1, -1);
				}

				try {
					var name = parts[0].replace(rdecode, decodeURIComponent);
					cookie = converter.read ?
						converter.read(cookie, name) : converter(cookie, name) ||
						cookie.replace(rdecode, decodeURIComponent);

					if (this.json) {
						try {
							cookie = JSON.parse(cookie);
						} catch (e) {}
					}

					if (key === name) {
						result = cookie;
						break;
					}

					if (!key) {
						result[name] = cookie;
					}
				} catch (e) {}
			}

			return result;
		}

		api.set = api;
		api.get = function (key) {
			return api.call(api, key);
		};
		api.getJSON = function () {
			return api.apply({
				json: true
			}, [].slice.call(arguments));
		};
		api.defaults = {};

		api.remove = function (key, attributes) {
			api(key, '', extend(attributes, {
				expires: -1
			}));
		};

		api.withConverter = init;

		return api;
	}

	return init(function () {});
}));

$(document).ready(function() {
    $('.icon-open').click(function() {
        $('.menu').css("left","0px");
        $('.content').css("left","240px");
        $('.icon-close').css("display","block");
       $('.icon-open').css("display","none");
        Cookies.set('menu-state', 'open');
    });

    $('.icon-close').click(function() {
        $('.menu').css("left","-240px");
        $('.content').css("left","0px");
        $('.icon-open').css("display","block");
      $('.icon-close').css("display","none");
        Cookies.set('menu-state', 'closed');
    });

    // Open menu (without animation) if it was open last time
    if (Cookies.get('menu-state') === 'open') {
        $('.menu').css("left","0px");
        $('.content').css("left","240px");
       $('.icon-open').css("display","none");
      $('.icon-close').css("display","block");
    } else {
        $('.menu').css("left","-240px");
        $('.content').css("left","0px");
       $('.icon-close').css("display","none");
      $('.icon-open').css("display","block");
    };
});
              
            
!
999px

Console