Sha256: 304c94e2f65a694f0222ef8febf8200228fa0b5eb5012e22a2f2ca99a85d655f

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

include('json.js');

/**
 * Stores/retrieves an object in localStorage (if available) otherwise as cookie
 * 
 * @author rsaccon
 * @param {string} key
 * @param {object} value 
 * @param {string} path 
 * @returns {object}
 */ 
uki.localStore = function(key, value, path) {
    if (('localStorage' in window) && window.localStorage !== null) {
        var name = "prefs";
        if (value === undefined) {
            return localStorage[key];
        } else {
            localStorage[key] = value; 
        };
    } else { 
        if (value === undefined) { 
            var result;
            if (result = new RegExp("(?:^|; )" +key+ "=([^;]*)").exec(document.cookie)) {
                return uki.parseJSON(unescape(result[1]));
            } else return false;
        } else {
            var date = new Date(); 
            // set expiration to far-future (one year)
            date.setTime(date.getTime()+(365*24*60*60*1000));
            document.cookie = [
                key , '=' , escape(uki.stringifyJSON(value)),
                '; expires=', date.toUTCString(),
                '; path=', path || '/'
            ].join("");
        }
    } 
};

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
uki-1.1.4 frameworks/uki/src/uki-data/localStore.js
uki-1.1.3 frameworks/uki/src/uki-data/localStore.js
uki-1.1.2 frameworks/uki/src/uki-data/localStore.js