src/hft/scripts/misc/cookies.js
function(name, opt_path) {
    var path = opt_path || "/";

    /**
     * Sets the cookie
     * @param {string} value value for cookie
     * @param {number?} opt_days number of days until cookie
     *        expires. Default = none
     */
    this.set = function(value, opt_days) {
      if (value === undefined) {
        this.erase();
        return;
      }
      // Cordova/Phonegap doesn't support cookies so use localStorage?
      if (window.hftSettings && window.hftSettings.inApp) {
        window.localStorage.setItem(name, value);
        return;
      }
      var expires = "";
      opt_days = opt_days || 9999;
      var date = new Date();
      date.setTime(Date.now() + Math.floor(opt_days * 24 * 60 * 60 * 1000));  // > 32bits. Don't use | 0
      expires = "; expires=" + date.toGMTString();
      var cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + expires + "; path=" + path;
      document.cookie = cookie;
    };

    /**
     * Gets the value of the cookie
     * @return {string?} value of cookie
     */
    this.get = function() {
      // Cordova/Phonegap doesn't support cookies so use localStorage?
      if (window.hftSettings && window.hftSettings.inApp) {
        return window.localStorage.getItem(name);
      }

      var nameEQ = encodeURIComponent(name) + "=";
      var ca = document.cookie.split(';');
      for (var i = 0; i < ca.length; ++i) {
        var c = ca[i];
        while (c.charAt(0) === ' ') {
          c = c.substring(1, c.length);
        }
        if (c.indexOf(nameEQ) === 0) {
          return decodeURIComponent(c.substring(nameEQ.length, c.length));
        }
      }
    };

    /**
     * Erases the cookie.
     */
    this.erase = function() {
      if (window.hftSettings && window.hftSettings.inApp) {
        return window.localStorage.removeItem(name);
      }
      document.cookie = this.set(" ", -1);
    };
  }
function(name, opt_path) {
    var path = opt_path || "/";

    /**
     * Sets the cookie
     * @param {string} value value for cookie
     * @param {number?} opt_days number of days until cookie
     *        expires. Default = none
     */
    this.set = function(value, opt_days) {
      if (value === undefined) {
        this.erase();
        return;
      }
      // Cordova/Phonegap doesn't support cookies so use localStorage?
      if (window.hftSettings && window.hftSettings.inApp) {
        window.localStorage.setItem(name, value);
        return;
      }
      var expires = "";
      opt_days = opt_days || 9999;
      var date = new Date();
      date.setTime(Date.now() + Math.floor(opt_days * 24 * 60 * 60 * 1000));  // > 32bits. Don't use | 0
      expires = "; expires=" + date.toGMTString();
      var cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + expires + "; path=" + path;
      document.cookie = cookie;
    };

    /**
     * Gets the value of the cookie
     * @return {string?} value of cookie
     */
    this.get = function() {
      // Cordova/Phonegap doesn't support cookies so use localStorage?
      if (window.hftSettings && window.hftSettings.inApp) {
        return window.localStorage.getItem(name);
      }

      var nameEQ = encodeURIComponent(name) + "=";
      var ca = document.cookie.split(';');
      for (var i = 0; i < ca.length; ++i) {
        var c = ca[i];
        while (c.charAt(0) === ' ') {
          c = c.substring(1, c.length);
        }
        if (c.indexOf(nameEQ) === 0) {
          return decodeURIComponent(c.substring(nameEQ.length, c.length));
        }
      }
    };

    /**
     * Erases the cookie.
     */
    this.erase = function() {
      if (window.hftSettings && window.hftSettings.inApp) {
        return window.localStorage.removeItem(name);
      }
      document.cookie = this.set(" ", -1);
    };
  }
function ( name , opt_path ) { var path = opt_path || "/" ; /**
     * Sets the cookie
     * @param {string} value value for cookie
     * @param {number?} opt_days number of days until cookie
     *        expires. Default = none
     */ this . set = function ( value , opt_days ) { if ( value === undefined ) { this . erase ( ) ; return ; } // Cordova/Phonegap doesn't support cookies so use localStorage? if ( window . hftSettings && window . hftSettings . inApp ) { window . localStorage . setItem ( name , value ) ; return ; } var expires = "" ; opt_days = opt_days || 9999 ; var date = new Date ( ) ; date . setTime ( Date . now ( ) + Math . floor ( opt_days * 24 * 60 * 60 * 1000 ) ) ; // > 32bits. Don't use | 0 expires = "; expires=" + date . toGMTString ( ) ; var cookie = encodeURIComponent ( name ) + "=" + encodeURIComponent ( value ) + expires + "; path=" + path ; document . cookie = cookie ; } ; /**
     * Gets the value of the cookie
     * @return {string?} value of cookie
     */ this . get = function ( ) { // Cordova/Phonegap doesn't support cookies so use localStorage? if ( window . hftSettings && window . hftSettings . inApp ) { return window . localStorage . getItem ( name ) ; } var nameEQ = encodeURIComponent ( name ) + "=" ; var ca = document . cookie . split ( ';' ) ; for ( var i = 0 ; i < ca . length ; ++ i ) { var c = ca [ i ] ; while ( c . charAt ( 0 ) === ' ' ) { c = c . substring ( 1 , c . length ) ; } if ( c . indexOf ( nameEQ ) === 0 ) { return decodeURIComponent ( c . substring ( nameEQ . length , c . length ) ) ; } } } ; /**
     * Erases the cookie.
     */ this . erase = function ( ) { if ( window . hftSettings && window . hftSettings . inApp ) { return window . localStorage . removeItem ( name ) ; } document . cookie = this . set ( " " , - 1 ) ; } ; }
Represents a cookie.

This is an object, that way you set the name just once so
calling set or get you don't have to worry about getting the
name wrong.

@example
var fooCookie = new Cookie("foo");
var value = fooCookie.get();
fooCookie.set(newValue);
fooCookie.erase();

@constructor
@alias Cookie
@param {string} name of cookie
@param {string?} opt_path path for cookie. Default "/"
Represents a cookie .