|
From af930278a5c77170a332fd677e3723d2e1ea15fd Mon Sep 17 00:00:00 2001 |
|
From: profelis <system.grand@gmail.com> |
|
Date: Wed, 12 Dec 2012 17:50:26 +0200 |
|
Subject: [PATCH] SharedObject (js.Storage, size) |
|
|
|
--- |
|
jeash/net/SharedObject.hx | 20 ++++++++++++++++---- |
|
1 file changed, 16 insertions(+), 4 deletions(-) |
|
|
|
diff --git a/jeash/net/SharedObject.hx b/jeash/net/SharedObject.hx |
|
index ffc8834..0aac40f 100644 |
|
--- a/jeash/net/SharedObject.hx |
|
+++ b/jeash/net/SharedObject.hx |
|
@@ -32,9 +32,18 @@ import jeash.net.SharedObjectFlushedStatus; |
|
import haxe.Serializer; |
|
import haxe.Unserializer; |
|
|
|
+import js.Storage; |
|
+ |
|
class SharedObject extends EventDispatcher { |
|
var jeashKey:String; |
|
- public var data:Dynamic; |
|
+ public var data(default, null):Dynamic; |
|
+ public var size(get_size, never):Int; |
|
+ |
|
+ function get_size() |
|
+ { |
|
+ var d = Serializer.run(data); |
|
+ return haxe.io.Bytes.ofString(d).length; |
|
+ } |
|
|
|
function new() super() |
|
|
|
@@ -52,12 +61,15 @@ class SharedObject extends EventDispatcher { |
|
return SharedObjectFlushedStatus.FLUSHED; |
|
} |
|
|
|
- static function jeashGetLocalStorage ():Dynamic return untyped js.Lib.window.localStorage |
|
+ static function jeashGetLocalStorage ():Storage { |
|
+ var res = Storage.getLocal(); |
|
+ if (res == null) throw new jeash.errors.Error("SharedObject not supported"); |
|
+ return res; |
|
+ } |
|
|
|
static public function getLocal(name : String, ?localPath : String, secure : Bool = false /* note: unsupported */) { |
|
|
|
- var url = js.Lib.window.location.href; |
|
- if (localPath == null) localPath = url; |
|
+ if (localPath == null) localPath = js.Lib.window.location.href; |
|
|
|
var so = new SharedObject(); |
|
so.jeashKey = localPath + ":" + name; |
|
-- |
|
1.7.10.2 (Apple Git-33) |
|
|