UNPKG

cobuild-angular-stack

Version:

Base stack angular sass jade gulp

79 lines (67 loc) 2.36 kB
(function () { console.log("Loading localStorage pollyfill"); function isSupported() { var item = 'localStoragePollyfill'; try { localStorage.setItem(item, item); localStorage.removeItem(item); return true; } catch (e) { return false; } } function createCookie(name, value, days) { if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); var expires = "; expires=" + date.toGMTString(); } else var expires = ""; document.cookie = name + "=" + value + expires + "; path=/"; console.log(document.cookie); } function readCookie(name) { var nameEQ = 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 c.substring(nameEQ.length, c.length); } return null; } function eraseCookie(name) { createCookie(name, "", -1); } function deleteAllCookies() { var cookies = document.cookie.split(";"); for (var i = 0; i < cookies.length; i++) { var cookie = cookies[i]; var eqPos = cookie.indexOf("="); var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie; eraseCookie(name); } } if (!isSupported()) { try { Storage.prototype._data = {}; Storage.prototype.setItem = function (id, val) { //return this._data[id] = String(val); return createCookie(id, val); }; Storage.prototype.getItem = function (id) { //return this._data.hasOwnProperty(id) ? this._data[id] : null; return readCookie(id); }, Storage.prototype.removeItem = function (id) { //return delete this._data[id]; eraseCookie(id); }, Storage.prototype.clear = function () { return this._data = {}; } } catch (e) { console.error('localStorage pollyfill error: ', e); } } }());