You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2013/06/21 09:35:02 UTC
js commit: [WindowsPhone] Remove DOMStorage Shim in WP8
Updated Branches:
refs/heads/master af24bb7d1 -> 0195db0c9
[WindowsPhone] Remove DOMStorage Shim in WP8
Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/0195db0c
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/0195db0c
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/0195db0c
Branch: refs/heads/master
Commit: 0195db0c9801fd202db3e5fa2940ee963c199ca0
Parents: af24bb7
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Fri Jun 21 00:34:25 2013 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Fri Jun 21 00:34:25 2013 -0700
----------------------------------------------------------------------
.../windowsphone/DOMStorage/plugininit.js | 140 ++++++-------------
1 file changed, 43 insertions(+), 97 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/0195db0c/lib/windowsphone/plugin/windowsphone/DOMStorage/plugininit.js
----------------------------------------------------------------------
diff --git a/lib/windowsphone/plugin/windowsphone/DOMStorage/plugininit.js b/lib/windowsphone/plugin/windowsphone/DOMStorage/plugininit.js
index c546c0f..c8bd777 100644
--- a/lib/windowsphone/plugin/windowsphone/DOMStorage/plugininit.js
+++ b/lib/windowsphone/plugin/windowsphone/DOMStorage/plugininit.js
@@ -19,164 +19,112 @@
*
*/
-(function(win,doc) {
-
+(function(win, doc) {
var docDomain = null;
try {
docDomain = doc.domain;
-} catch (err) {
- //console.log("caught exception trying to access document.domain");
-}
-
-// conditionally patch the window.localStorage and window.sessionStorage objects
-if (!docDomain || docDomain.length === 0) {
-
+} catch (err) {}
+var isIE10 = navigator.userAgent.toUpperCase().indexOf('MSIE 10') > -1;
+if (!isIE10 && (!docDomain || docDomain.length === 0) ) {
var DOMStorage = function(type) {
- // default type is local
- if(type == "sessionStorage") {
+ if (type == "sessionStorage") {
this._type = type;
}
- Object.defineProperty( this, "length", {
+ Object.defineProperty(this, "length", {
configurable: true,
- get: function(){ return this.getLength(); }
+ get: function() {
+ return this.getLength();
+ }
});
};
-
DOMStorage.prototype = {
- _type:"localStorage",
- _result:null,
- keys:null,
-
- onResult:function(key,valueStr) {
- if(!this.keys) {
+ _type: "localStorage",
+ _result: null,
+ keys: null,
+ onResult: function(key, valueStr) {
+ if (!this.keys) {
this.keys = [];
}
this._result = valueStr;
},
-
- onKeysChanged:function(jsonKeys) {
+ onKeysChanged: function(jsonKeys) {
this.keys = JSON.parse(jsonKeys);
-
var key;
- for(var n = 0,len = this.keys.length; n < len; n++) {
+ for (var n = 0, len = this.keys.length; n < len; n++) {
key = this.keys[n];
- if(!this.hasOwnProperty(key)) {
- Object.defineProperty( this, key, {
+ if (!this.hasOwnProperty(key)) {
+ Object.defineProperty(this, key, {
configurable: true,
- get: function(){ return this.getItem(key); },
- set: function(val){ return this.setItem(key,val); }
+ get: function() {
+ return this.getItem(key);
+ },
+ set: function(val) {
+ return this.setItem(key, val);
+ }
});
}
}
-
},
-
- initialize:function() {
+ initialize: function() {
window.external.Notify("DOMStorage/" + this._type + "/load/keys");
},
-
- /*
- The length attribute must return the number of key/value pairs currently present
- in the list associated with the object.
- */
- getLength:function() {
- if(!this.keys) {
+ getLength: function() {
+ if (!this.keys) {
this.initialize();
}
return this.keys.length;
},
-
- /*
- The key(n) method must return the name of the nth key in the list.
- The order of keys is user-agent defined, but must be consistent within an object so long as the number of keys doesn't change.
- (Thus, adding or removing a key may change the order of the keys, but merely changing the value of an existing key must not.)
- If n is greater than or equal to the number of key/value pairs in the object, then this method must return null.
- */
- key:function(n) {
- if(!this.keys) {
+ key: function(n) {
+ if (!this.keys) {
this.initialize();
}
-
- if(n >= this.keys.length) {
+ if (n >= this.keys.length) {
return null;
} else {
return this.keys[n];
}
},
-
- /*
- The getItem(key) method must return the current value associated with the given key.
- If the given key does not exist in the list associated with the object then this method must return null.
- */
- getItem:function(key) {
- if(!this.keys) {
+ getItem: function(key) {
+ if (!this.keys) {
this.initialize();
}
-
var retVal = null;
- if(this.keys.indexOf(key) > -1) {
+ if (this.keys.indexOf(key) > -1) {
window.external.Notify("DOMStorage/" + this._type + "/get/" + key);
retVal = window.unescape(decodeURIComponent(this._result));
this._result = null;
}
return retVal;
},
- /*
- The setItem(key, value) method must first check if a key/value pair with the given key already exists
- in the list associated with the object.
- If it does not, then a new key/value pair must be added to the list, with the given key and with its value set to value.
- If the given key does exist in the list, then it must have its value updated to value.
- If it couldn't set the new value, the method must raise an QUOTA_EXCEEDED_ERR exception.
- (Setting could fail if, e.g., the user has disabled storage for the site, or if the quota has been exceeded.)
- */
- setItem:function(key,value) {
- if(!this.keys) {
+ setItem: function(key, value) {
+ if (!this.keys) {
this.initialize();
}
window.external.Notify("DOMStorage/" + this._type + "/set/" + key + "/" + encodeURIComponent(window.escape(value)));
},
-
- /*
- The removeItem(key) method must cause the key/value pair with the given key to be removed from the list
- associated with the object, if it exists.
- If no item with that key exists, the method must do nothing.
- */
- removeItem:function(key) {
- if(!this.keys) {
+ removeItem: function(key) {
+ if (!this.keys) {
this.initialize();
}
var index = this.keys.indexOf(key);
- if(index > -1) {
- this.keys.splice(index,1);
- // TODO: need sanity check for keys ? like 'clear','setItem', ...
+ if (index > -1) {
+ this.keys.splice(index, 1);
window.external.Notify("DOMStorage/" + this._type + "/remove/" + key);
delete this[key];
}
},
-
- /*
- The clear() method must atomically cause the list associated with the object to be emptied of all
- key/value pairs, if there are any.
- If there are none, then the method must do nothing.
- */
- clear:function() {
- if(!this.keys) {
+ clear: function() {
+ if (!this.keys) {
this.initialize();
}
-
- for(var n=0,len=this.keys.length; n < len;n++) {
- // TODO: do we need a sanity check for keys ? like 'clear','setItem', ...
+ for (var n = 0, len = this.keys.length; n < len; n++) {
delete this[this.keys[n]];
}
this.keys = [];
window.external.Notify("DOMStorage/" + this._type + "/clear/");
}
};
-
- // initialize DOMStorage
-
if (typeof window.localStorage === "undefined") {
-
Object.defineProperty(window, "localStorage", {
writable: false,
configurable: false,
@@ -184,7 +132,6 @@ if (!docDomain || docDomain.length === 0) {
});
window.localStorage.initialize();
}
-
if (typeof window.sessionStorage === "undefined") {
Object.defineProperty(window, "sessionStorage", {
writable: false,
@@ -194,7 +141,6 @@ if (!docDomain || docDomain.length === 0) {
window.sessionStorage.initialize();
}
}
-
})(window, document);
-module.exports = null;
+module.exports = null;
\ No newline at end of file