Sha256: 402e99b9b8197bc4d20f068b9ae5d9bbc42c5b85d93042dbe68fb9f041349c79

Contents?: true

Size: 1.63 KB

Versions: 62

Compression:

Stored size: 1.63 KB

Contents

/**
 * Manages the handling of cookies
 * Adapted from {@link http://www.quirksmode.org/js/cookies.html}
 *
 * @namespace WORKAREA.cookie
 */
WORKAREA.registerModule('cookie', (function () {
    'use strict';

    var trimAndSplit = function (string) {
            var subject = $.trim(string),
                suffix = subject.substring(subject.indexOf('=')),
                cookie = subject.replace(suffix, ''),
                value = suffix.substring(1);

            return [cookie, value];
        },

        /**
         * @method
         * @name create
         * @memberof WORKAREA.cookie
         */
        create = function (name, value, days) {
            var date,
                expires;

            if (days) {
                date = new Date();
                date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
                expires = '; expires=' + date.toGMTString();
            } else {
                expires = '';
            }

            document.cookie = name + '=' + value + expires + '; path=/';
        },

        /**
         * @method
         * @name destroy
         * @memberof WORKAREA.cookie
         */
        destroy = function (name) {
            document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/';
        },

        /**
         * @method
         * @name read
         * @memberof WORKAREA.cookie
         */
        read = function (name) {
            return _.fromPairs(
                _.map(document.cookie.split(';'), trimAndSplit)
            )[name] || null;
        };

    return {
        create: create,
        destroy: destroy,
        read: read
    };
}()));

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.4.27 app/assets/javascripts/workarea/core/modules/cookie.js
workarea-core-3.5.4 app/assets/javascripts/workarea/core/modules/cookie.js
workarea-core-3.4.26 app/assets/javascripts/workarea/core/modules/cookie.js
workarea-core-3.5.3 app/assets/javascripts/workarea/core/modules/cookie.js
workarea-core-3.4.25 app/assets/javascripts/workarea/core/modules/cookie.js
workarea-core-3.5.2 app/assets/javascripts/workarea/core/modules/cookie.js
workarea-core-3.4.24 app/assets/javascripts/workarea/core/modules/cookie.js
workarea-core-3.5.1 app/assets/javascripts/workarea/core/modules/cookie.js
workarea-core-3.4.23 app/assets/javascripts/workarea/core/modules/cookie.js
workarea-core-3.4.22 app/assets/javascripts/workarea/core/modules/cookie.js
workarea-core-3.5.0 app/assets/javascripts/workarea/core/modules/cookie.js
workarea-core-3.4.21 app/assets/javascripts/workarea/core/modules/cookie.js
workarea-core-3.5.0.beta.1 app/assets/javascripts/workarea/core/modules/cookie.js
workarea-core-3.4.20 app/assets/javascripts/workarea/core/modules/cookie.js
workarea-core-3.4.19 app/assets/javascripts/workarea/core/modules/cookie.js
workarea-core-3.4.18 app/assets/javascripts/workarea/core/modules/cookie.js
workarea-core-3.4.17 app/assets/javascripts/workarea/core/modules/cookie.js
workarea-core-3.4.16 app/assets/javascripts/workarea/core/modules/cookie.js
workarea-core-3.4.15 app/assets/javascripts/workarea/core/modules/cookie.js
workarea-core-3.4.14 app/assets/javascripts/workarea/core/modules/cookie.js