code style updates
This commit is contained in:
parent
f54e01e54f
commit
7c6a34c743
5 changed files with 670 additions and 688 deletions
202
src/add/array.js
202
src/add/array.js
|
|
@ -2,61 +2,52 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
// extend Array, String, Number, Math
|
||||
(function() {
|
||||
|
||||
gapp.register('add.array');
|
||||
gapp.register('add.array');
|
||||
|
||||
let AP = {};
|
||||
let AP = {};
|
||||
|
||||
/** ******************************************************************
|
||||
* Array prototype helpers
|
||||
******************************************************************* */
|
||||
|
||||
if (!AP.flat) {
|
||||
if (!AP.flat) {
|
||||
AP.flat = function() {
|
||||
return [].concat.apply([], this);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
AP.equals = function(arr) {
|
||||
AP.equals = function(arr) {
|
||||
if (!arr) return false;
|
||||
if (arr.length !== this.length) return false;
|
||||
for (let i=0; i<this.length; i++) {
|
||||
for (let i = 0; i < this.length; i++) {
|
||||
if (arr[i] !== this[i]) return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
};
|
||||
|
||||
AP.peek = function() {
|
||||
return this[this.length-1];
|
||||
};
|
||||
AP.peek = function() {
|
||||
return this[this.length - 1];
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* allow chaining of push() calls
|
||||
*
|
||||
* @param v
|
||||
* @returns {Array}
|
||||
*/
|
||||
AP.append = function(v, flat) {
|
||||
AP.append = function(v, flat) {
|
||||
if (flat) {
|
||||
return this.appendAll(v);
|
||||
} else {
|
||||
this.push(v);
|
||||
return this;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* append all array elements to this array
|
||||
*
|
||||
* @param {Array} arr
|
||||
* @returns {Array}
|
||||
*/
|
||||
AP.appendAll = function(arr) {
|
||||
AP.appendAll = function(arr) {
|
||||
if (arr && arr.length > 0) {
|
||||
// avoid hitting stack limits
|
||||
if (arr.length > 10000) {
|
||||
for (let i=0, il=arr.length; i<il; i++) {
|
||||
for (let i = 0, il = arr.length; i < il; i++) {
|
||||
this.push(arr[i]);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -65,41 +56,39 @@
|
|||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
};
|
||||
|
||||
AP.addOnce = function(val) {
|
||||
AP.addOnce = function(val) {
|
||||
if (!this.contains(val)) {
|
||||
this.push(val);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* shallow cloning with clone(arg) call on each new element
|
||||
*
|
||||
* @param {Array} [arg]
|
||||
* @returns {Array}
|
||||
*/
|
||||
AP.clone = function(arg) {
|
||||
AP.clone = function(arg) {
|
||||
var na = this.slice(),
|
||||
ln = na.length,
|
||||
i = 0;
|
||||
while (i < ln) na[i] = na[i++].clone(arg);
|
||||
return na;
|
||||
};
|
||||
};
|
||||
|
||||
AP.xray = function(arg) {
|
||||
const na = [], ln = this.length;
|
||||
for (let i=0; i<ln; i++) {
|
||||
AP.xray = function(arg) {
|
||||
const na = [],
|
||||
ln = this.length;
|
||||
for (let i = 0; i < ln; i++) {
|
||||
na.push(this[i].xray(arg));
|
||||
}
|
||||
return na;
|
||||
};
|
||||
};
|
||||
|
||||
AP.xout = function(label, inset) {
|
||||
AP.xout = function(label, inset) {
|
||||
if (label) console.log(`${label} [${this.length}]`);
|
||||
if (!inset) inset = ' ';
|
||||
this.forEach((el,i) => {
|
||||
this.forEach((el, i) => {
|
||||
if (el.xout) {
|
||||
el.xout(null, inset + i + inset);
|
||||
} else if (el.xray) {
|
||||
|
|
@ -112,91 +101,89 @@
|
|||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* remove and return element from array, if present
|
||||
*
|
||||
* @param val
|
||||
* @returns {*}
|
||||
*/
|
||||
AP.remove = function(val) {
|
||||
AP.remove = function(val) {
|
||||
var idx = this.indexOf(val);
|
||||
if (idx >= 0) return this.splice(idx,1);
|
||||
if (idx >= 0) return this.splice(idx, 1);
|
||||
return null;
|
||||
};
|
||||
};
|
||||
|
||||
AP.removeAll = function(array) {
|
||||
for (let i=0, il=array.length; i<il; i++) {
|
||||
AP.removeAll = function(array) {
|
||||
for (let i = 0, il = array.length; i < il; i++) {
|
||||
this.remove(array[i]);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* return last array element if array length > 0
|
||||
*
|
||||
* @returns {*}
|
||||
*/
|
||||
AP.last = function() {
|
||||
AP.last = function() {
|
||||
if (this.length === 0) return null;
|
||||
return this[this.length-1];
|
||||
};
|
||||
return this[this.length - 1];
|
||||
};
|
||||
|
||||
AP.contains = function(val) {
|
||||
AP.contains = function(val) {
|
||||
return this.indexOf(val) >= 0;
|
||||
};
|
||||
};
|
||||
|
||||
AP.toFloat32 = function() {
|
||||
var i = 0, f32 = new Float32Array(this.length);
|
||||
AP.toFloat32 = function() {
|
||||
var i = 0,
|
||||
f32 = new Float32Array(this.length);
|
||||
while (i < this.length) {
|
||||
f32[i] = this[i++];
|
||||
}
|
||||
return f32;
|
||||
};
|
||||
};
|
||||
|
||||
AP.forEachPair = function(fn, incr) {
|
||||
AP.forEachPair = function(fn, incr) {
|
||||
var scope = this,
|
||||
idx = 0,
|
||||
inc = incr || 2,
|
||||
len = scope.length;
|
||||
while (idx < len) {
|
||||
fn(scope[idx], scope[(idx+1)%len], idx);
|
||||
fn(scope[idx], scope[(idx + 1) % len], idx);
|
||||
idx += inc;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
AP.show = function(fn,f) {
|
||||
f = f || function(v) { console.log(v) };
|
||||
AP.show = function(fn, f) {
|
||||
f = f || function(v) {
|
||||
console.log(v)
|
||||
};
|
||||
this.forEach(function(av) {
|
||||
f(av[fn]());
|
||||
})
|
||||
};
|
||||
};
|
||||
|
||||
AP.uniq = function() {
|
||||
return this.slice().sort().filter((x, i, a) => !i || x != a[i-1]);
|
||||
};
|
||||
AP.uniq = function() {
|
||||
return this.slice().sort().filter((x, i, a) => !i || x != a[i - 1]);
|
||||
};
|
||||
|
||||
AP.hasNaN = function() {
|
||||
AP.hasNaN = function() {
|
||||
return this.filter(v => isNaN(v)).length > 0;
|
||||
};
|
||||
};
|
||||
|
||||
// turn array into arrays of specified size
|
||||
AP.group = function(size) {
|
||||
// turn array into arrays of specified size
|
||||
AP.group = function(size) {
|
||||
let na = new Array(Math.ceil(this.length / size));
|
||||
let nai = 0;
|
||||
for (let i=0; i<this.length; i += size) {
|
||||
for (let i = 0; i < this.length; i += size) {
|
||||
let grp = new Array(size);
|
||||
for (let j=0; j<size; j++) {
|
||||
grp[j] = this[i+j];
|
||||
for (let j = 0; j < size; j++) {
|
||||
grp[j] = this[i + j];
|
||||
}
|
||||
na[nai++] = grp;
|
||||
}
|
||||
return na;
|
||||
};
|
||||
};
|
||||
|
||||
// wrap a function and unroll the first parameter into
|
||||
// successive function calls if it is an array
|
||||
Array.handle = function(fn) {
|
||||
// wrap a function and unroll the first parameter into
|
||||
// successive function calls if it is an array
|
||||
Array.handle = function(fn) {
|
||||
return function() {
|
||||
let args = [...arguments];
|
||||
let val = args.shift();
|
||||
|
|
@ -210,50 +197,41 @@
|
|||
return fn(val, ...args);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
for (let i in AP) {
|
||||
for (let i in AP) {
|
||||
Object.defineProperty(Array.prototype, i, {
|
||||
value: AP[i],
|
||||
enumerable: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/** ******************************************************************
|
||||
* String prototype helpers
|
||||
******************************************************************* */
|
||||
|
||||
String.prototype.reverse = function() {
|
||||
String.prototype.reverse = function() {
|
||||
return this.split('').reverse().join('');
|
||||
};
|
||||
};
|
||||
|
||||
/** ******************************************************************
|
||||
* Object static helpers
|
||||
******************************************************************* */
|
||||
|
||||
Object.clone = function(o) {
|
||||
Object.clone = function(o) {
|
||||
return o ? JSON.parse(JSON.stringify(o)) : o;
|
||||
};
|
||||
};
|
||||
|
||||
Object.toArray = function(o) {
|
||||
Object.toArray = function(o) {
|
||||
let ret = [];
|
||||
for (let [key,value] of Object.entries(o)) {
|
||||
ret.push({key, value});
|
||||
for (let [key, value] of Object.entries(o)) {
|
||||
ret.push({
|
||||
key,
|
||||
value
|
||||
});
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
};
|
||||
|
||||
Math.bound = function(val,min,max) {
|
||||
return Math.max(min,Math.min(max,val));
|
||||
};
|
||||
Math.bound = function(val, min, max) {
|
||||
return Math.max(min, Math.min(max, val));
|
||||
};
|
||||
|
||||
/** ******************************************************************
|
||||
* Number static helpers
|
||||
******************************************************************* */
|
||||
|
||||
Number.prototype.round = function(digits) {
|
||||
const pow = Math.pow(10,digits || 3);
|
||||
Number.prototype.round = function(digits) {
|
||||
const pow = Math.pow(10, digits || 3);
|
||||
return Math.round(this.valueOf() * pow) / pow;
|
||||
};
|
||||
};
|
||||
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
if (!self.ArrayWriter) {
|
||||
gapp.register('add.class');
|
||||
}
|
||||
(function() {
|
||||
|
||||
if (self.ArrayWriter) return;
|
||||
|
||||
gapp.register('add.class');
|
||||
|
||||
self.ArrayWriter = class ArrayWriter {
|
||||
constructor() {
|
||||
|
|
@ -171,3 +173,5 @@ self.DataReader = class DataReader {
|
|||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -4,16 +4,16 @@
|
|||
|
||||
(function() {
|
||||
|
||||
// dep: ext.three
|
||||
// dep: ext.three-bgu
|
||||
// dep: ext.three-svg
|
||||
gapp.register('add.three');
|
||||
// dep: ext.three
|
||||
// dep: ext.three-bgu
|
||||
// dep: ext.three-svg
|
||||
gapp.register('add.three');
|
||||
|
||||
let MP = THREE.Mesh.prototype,
|
||||
let MP = THREE.Mesh.prototype,
|
||||
XP = THREE.Box3.prototype,
|
||||
BP = THREE.BufferGeometry.prototype;
|
||||
|
||||
THREE.computeFaceNormal = function(vA,vB,vC) {
|
||||
THREE.computeFaceNormal = function(vA,vB,vC) {
|
||||
const ab = new THREE.Vector3();
|
||||
const cb = new THREE.Vector3();
|
||||
cb.subVectors( vC, vB );
|
||||
|
|
@ -21,9 +21,9 @@
|
|||
cb.cross( ab );
|
||||
cb.normalize();
|
||||
return cb;
|
||||
};
|
||||
};
|
||||
|
||||
THREE.dispose = function(obj) {
|
||||
THREE.dispose = function(obj) {
|
||||
if (!obj) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -38,10 +38,10 @@
|
|||
THREE.dispose(c);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// add .dim and .mid getters to Box3
|
||||
Object.defineProperties(XP, {
|
||||
// add .dim and .mid getters to Box3
|
||||
Object.defineProperties(XP, {
|
||||
dim: {
|
||||
get: function() {
|
||||
return this.max.clone().sub(this.min);
|
||||
|
|
@ -52,27 +52,27 @@
|
|||
return this.dim.clone().multiplyScalar(0.5).add(this.min);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
MP.getBoundingBox = function(update) {
|
||||
MP.getBoundingBox = function(update) {
|
||||
return this.geometry.getBoundingBox(update);
|
||||
};
|
||||
};
|
||||
|
||||
MP.mirrorX = function() {
|
||||
MP.mirrorX = function() {
|
||||
return this.mirror(0);
|
||||
};
|
||||
};
|
||||
|
||||
MP.mirrorY = function() {
|
||||
MP.mirrorY = function() {
|
||||
return this.mirror(1);
|
||||
};
|
||||
};
|
||||
|
||||
MP.mirrorZ = function() {
|
||||
MP.mirrorZ = function() {
|
||||
return this.mirror(2);
|
||||
};
|
||||
};
|
||||
|
||||
// fast mirror of vertices given axis array offset
|
||||
// array elements are repeating [x,y,z,x,y,z,...]
|
||||
MP.mirror = function(start) {
|
||||
// fast mirror of vertices given axis array offset
|
||||
// array elements are repeating [x,y,z,x,y,z,...]
|
||||
MP.mirror = function(start) {
|
||||
let i,
|
||||
geo = this.geometry,
|
||||
at = geo.attributes,
|
||||
|
|
@ -84,18 +84,18 @@
|
|||
}
|
||||
geo.computeVertexNormals();
|
||||
return this;
|
||||
};
|
||||
};
|
||||
|
||||
// return cached or refreshed (when update = true) bounding box
|
||||
BP.getBoundingBox = function(update) {
|
||||
// return cached or refreshed (when update = true) bounding box
|
||||
BP.getBoundingBox = function(update) {
|
||||
if (update || !this.boundingBox) {
|
||||
this.boundingBox = null;
|
||||
this.computeBoundingBox();
|
||||
}
|
||||
return this.boundingBox;
|
||||
};
|
||||
};
|
||||
|
||||
BP.moveMesh = function(x = 0, y = 0, z = 0) {
|
||||
BP.moveMesh = function(x = 0, y = 0, z = 0) {
|
||||
let gap = this.attributes.position,
|
||||
pa = gap.array;
|
||||
for (let i=0; i < pa.length; i += 3) {
|
||||
|
|
@ -105,28 +105,28 @@
|
|||
}
|
||||
gap.needsUpdate = true;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
BP.shallowClone = function() {
|
||||
BP.shallowClone = function() {
|
||||
let geo = new THREE.BufferGeometry();
|
||||
for (let [k, v] of Object.entries(this.attributes)) {
|
||||
geo.setAttribute(k, new THREE.BufferAttribute(v.array, v.itemSize));
|
||||
}
|
||||
return geo;
|
||||
};
|
||||
};
|
||||
|
||||
THREE.Object3D.prototype.newGroup = function() {
|
||||
THREE.Object3D.prototype.newGroup = function() {
|
||||
let group = new THREE.Group();
|
||||
this.add(group);
|
||||
return group;
|
||||
};
|
||||
};
|
||||
|
||||
THREE.Object3D.prototype.removeAll = function() {
|
||||
THREE.Object3D.prototype.removeAll = function() {
|
||||
this.children.slice().forEach(function (c) {
|
||||
c.parent = undefined;
|
||||
c.dispatchEvent( { type: 'removed' } );
|
||||
});
|
||||
this.children = [];
|
||||
};
|
||||
};
|
||||
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -4,34 +4,34 @@
|
|||
|
||||
(function() {
|
||||
|
||||
gapp.register('data.index');
|
||||
gapp.register('data.index');
|
||||
|
||||
let data = self.data = self.data || {};
|
||||
if (data.Index) return;
|
||||
let data = self.data = self.data || {};
|
||||
if (data.Index) return;
|
||||
|
||||
data.Index = IDBStore;
|
||||
data.Index = IDBStore;
|
||||
|
||||
data.open = function() {
|
||||
data.open = function() {
|
||||
return new IDBStore(...arguments);
|
||||
};
|
||||
};
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API
|
||||
|
||||
let IDB, IRR, local = null;
|
||||
let IDB, IRR, local = null;
|
||||
|
||||
try {
|
||||
try {
|
||||
IDB = self.indexedDB || self.mozIndexedDB || self.webkitIndexedDB || self.msIndexedDB;
|
||||
IRR = self.IDBKeyRange;
|
||||
} catch (e) {
|
||||
} catch (e) {
|
||||
console.log("in private or restricted browsing mode. database storage blocked. application may not function.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @param {String} dbname
|
||||
* @param {number} [version]
|
||||
* @constructor
|
||||
*/
|
||||
function IDBStore(dbname, options = {}) {
|
||||
function IDBStore(dbname, options = {}) {
|
||||
this.db = null;
|
||||
this.name = dbname;
|
||||
this.stores = options.stores || [ dbname ];
|
||||
|
|
@ -40,28 +40,28 @@
|
|||
this.idle = [];
|
||||
this.initCalled = false;
|
||||
this.created = {};
|
||||
}
|
||||
}
|
||||
|
||||
IDBStore.delete = function(dbname) {
|
||||
IDBStore.delete = function(dbname) {
|
||||
IDB.deleteDatabase(dbname);
|
||||
};
|
||||
};
|
||||
|
||||
let SP = IDBStore.prototype;
|
||||
let SP = IDBStore.prototype;
|
||||
|
||||
/** ******************************************************************
|
||||
/** ******************************************************************
|
||||
* indexedDB implementation
|
||||
******************************************************************* */
|
||||
|
||||
SP.onIdle = function(fn) {
|
||||
SP.onIdle = function(fn) {
|
||||
if (this.queue.length) {
|
||||
this.idle.push(fn);
|
||||
} else {
|
||||
fn();
|
||||
}
|
||||
return this;
|
||||
};
|
||||
};
|
||||
|
||||
SP.promise = function(store) {
|
||||
SP.promise = function(store) {
|
||||
let db = this;
|
||||
let pc = {
|
||||
iterate: (opt = {}) => new Promise(function(resolve, reject) {
|
||||
|
|
@ -108,9 +108,9 @@
|
|||
},
|
||||
};
|
||||
return pc;
|
||||
}
|
||||
}
|
||||
|
||||
SP.keys = function(callback, lower, upper, store = this.current) {
|
||||
SP.keys = function(callback, lower, upper, store = this.current) {
|
||||
if (!this.db) {
|
||||
this.init();
|
||||
return this.queue.push(["keys", callback, lower, upper, store]);
|
||||
|
|
@ -123,9 +123,9 @@
|
|||
out.push(k);
|
||||
}
|
||||
}, lower, upper, true, store);
|
||||
};
|
||||
};
|
||||
|
||||
SP.iterate = function(callback, lower, upper, nullterm, store = this.current) {
|
||||
SP.iterate = function(callback, lower, upper, nullterm, store = this.current) {
|
||||
if (!this.db) {
|
||||
this.init();
|
||||
return this.queue.push(["iterate", callback, lower, upper, nullterm, store]);
|
||||
|
|
@ -146,20 +146,20 @@
|
|||
callback(null);
|
||||
}
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
SP.deleteStore = function() {
|
||||
SP.deleteStore = function() {
|
||||
if (this.initCalled) throw "cannot delete ObjectStore after init() called";
|
||||
this.version = Number.MAX_SAFE_INTEGER || Number.MAX_VALUE;
|
||||
return this.init(true);
|
||||
};
|
||||
};
|
||||
|
||||
SP.use = function(store) {
|
||||
SP.use = function(store) {
|
||||
this.current = store;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
SP.init = function(options = {}) {
|
||||
SP.init = function(options = {}) {
|
||||
if (this.initCalled) return;
|
||||
|
||||
let storage = this,
|
||||
|
|
@ -218,9 +218,9 @@
|
|||
|
||||
this.initCalled = true;
|
||||
return this;
|
||||
};
|
||||
};
|
||||
|
||||
SP.runQueue = function() {
|
||||
SP.runQueue = function() {
|
||||
if (this.queue.length > 0) {
|
||||
let i = 0, q = this.queue, e;
|
||||
while (i < q.length) {
|
||||
|
|
@ -239,9 +239,9 @@
|
|||
while (this.idle.length) {
|
||||
this.idle.shift()();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
SP.put = function(key, value, callback, store = this.current) {
|
||||
SP.put = function(key, value, callback, store = this.current) {
|
||||
if (local) {
|
||||
local[key] = value;
|
||||
if (callback) callback(true);
|
||||
|
|
@ -263,9 +263,9 @@
|
|||
console.log(e);
|
||||
if (callback) callback(false);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
SP.get = function(key, callback, store = this.current) {
|
||||
SP.get = function(key, callback, store = this.current) {
|
||||
if (local) {
|
||||
if (callback) callback(local[key]);
|
||||
return;
|
||||
|
|
@ -286,9 +286,9 @@
|
|||
console.log(e);
|
||||
if (callback) callback(null);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
SP.remove = function(key, callback, store = this.current) {
|
||||
SP.remove = function(key, callback, store = this.current) {
|
||||
if (local) {
|
||||
delete local[key];
|
||||
if (callback) callback(true);
|
||||
|
|
@ -310,9 +310,9 @@
|
|||
console.log(e);
|
||||
if (callback) callback(false);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
SP.clear = function(key, store = this.current) {
|
||||
SP.clear = function(key, store = this.current) {
|
||||
if (!this.db) {
|
||||
this.init();
|
||||
return this.queue.push(['clear', store]);
|
||||
|
|
@ -320,6 +320,6 @@
|
|||
this.db
|
||||
.transaction(store, "readwrite")
|
||||
.objectStore(store).clear();
|
||||
};
|
||||
};
|
||||
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -4,46 +4,46 @@
|
|||
|
||||
(function() {
|
||||
|
||||
gapp.register('data.local');
|
||||
gapp.register('data.local');
|
||||
|
||||
let data = self.data = self.data || {};
|
||||
if (data.Local) return;
|
||||
let data = self.data = self.data || {};
|
||||
if (data.Local) return;
|
||||
|
||||
function Local() {
|
||||
function Local() {
|
||||
this.__data__ = {};
|
||||
this.__mem__ = true;
|
||||
}
|
||||
}
|
||||
|
||||
var LS = Local.prototype;
|
||||
var LS = Local.prototype;
|
||||
|
||||
LS.getItem = function(key) {
|
||||
LS.getItem = function(key) {
|
||||
return this[key];
|
||||
};
|
||||
};
|
||||
|
||||
LS.setItem = function(key, val) {
|
||||
LS.setItem = function(key, val) {
|
||||
this.__data__[key] = val;
|
||||
this[key] = val;
|
||||
};
|
||||
};
|
||||
|
||||
LS.removeItem = function(key) {
|
||||
LS.removeItem = function(key) {
|
||||
delete this.__data__[key];
|
||||
};
|
||||
};
|
||||
|
||||
LS.clear = function() {
|
||||
LS.clear = function() {
|
||||
this.__data__ = {};
|
||||
};
|
||||
};
|
||||
|
||||
try {
|
||||
try {
|
||||
let local = data.Local = self.localStorage;
|
||||
let testkey = '__test';
|
||||
local.setItem(testkey, 1);
|
||||
local.getItem(testkey);
|
||||
local.removeItem(testkey);
|
||||
} catch (e) {
|
||||
} catch (e) {
|
||||
data.Local = new Local();
|
||||
let msg = "in private or restricted browsing mode. local storage blocked. application may not function properly.";
|
||||
console.log(msg);
|
||||
alert(msg);
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
|
|||
Loading…
Reference in a new issue