From e44a7e37b6c7b5961adaffc62b9042b8d442938e Mon Sep 17 00:00:00 2001 From: mensonge Date: Thu, 13 Nov 2008 09:49:11 +0000 Subject: New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f --- includes/js/dojox/storage/FlashStorageProvider.js | 346 ++++++++++++++++++++++ 1 file changed, 346 insertions(+) create mode 100644 includes/js/dojox/storage/FlashStorageProvider.js (limited to 'includes/js/dojox/storage/FlashStorageProvider.js') diff --git a/includes/js/dojox/storage/FlashStorageProvider.js b/includes/js/dojox/storage/FlashStorageProvider.js new file mode 100644 index 0000000..42cd7dc --- /dev/null +++ b/includes/js/dojox/storage/FlashStorageProvider.js @@ -0,0 +1,346 @@ +if(!dojo._hasResource["dojox.storage.FlashStorageProvider"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.storage.FlashStorageProvider"] = true; +dojo.provide("dojox.storage.FlashStorageProvider"); + +dojo.require("dojox.flash"); +dojo.require("dojox.storage.manager"); +dojo.require("dojox.storage.Provider"); + +// summary: +// Storage provider that uses features in Flash to achieve permanent +// storage +// description: +// Authors of this storage provider- +// Brad Neuberg, bkn3@columbia.edu +dojo.declare("dojox.storage.FlashStorageProvider", dojox.storage.Provider, { + initialized: false, + + _available: null, + _statusHandler: null, + _flashReady: false, + _pageReady: false, + + initialize: function(){ + //console.debug("FlashStorageProvider.initialize"); + if(dojo.config["disableFlashStorage"] == true){ + return; + } + + // initialize our Flash + dojox.flash.addLoadedListener(dojo.hitch(this, function(){ + //console.debug("flashReady"); + // indicate our Flash subsystem is now loaded + this._flashReady = true; + if(this._flashReady && this._pageReady){ + this._loaded(); + } + })); + var swfLoc = dojo.moduleUrl("dojox", "storage/Storage.swf").toString(); + dojox.flash.setSwf(swfLoc, false); + + // wait till page is finished loading + dojo.connect(dojo, "loaded", this, function(){ + //console.debug("pageReady"); + this._pageReady = true; + if(this._flashReady && this._pageReady){ + this._loaded(); + } + }); + }, + + // Set a new value for the flush delay timer. + // Possible values: + // 0 : Perform the flush synchronously after each "put" request + // > 0 : Wait until 'newDelay' ms have passed without any "put" request to flush + // -1 : Do not automatically flush + setFlushDelay: function(newDelay){ + if(newDelay === null || typeof newDelay === "undefined" || isNaN(newDelay)){ + throw new Error("Invalid argunment: " + newDelay); + } + + dojox.flash.comm.setFlushDelay(String(newDelay)); + }, + + getFlushDelay: function(){ + return Number(dojox.flash.comm.getFlushDelay()); + }, + + flush: function(namespace){ + //FIXME: is this test necessary? Just use !namespace + if(namespace == null || typeof namespace == "undefined"){ + namespace = dojox.storage.DEFAULT_NAMESPACE; + } + dojox.flash.comm.flush(namespace); + }, + + isAvailable: function(){ + return (this._available = !dojo.config["disableFlashStorage"]); + }, + + put: function(key, value, resultsHandler, namespace){ + if(!this.isValidKey(key)){ + throw new Error("Invalid key given: " + key); + } + + if(!namespace){ + namespace = dojox.storage.DEFAULT_NAMESPACE; + } + + if(!this.isValidKey(namespace)){ + throw new Error("Invalid namespace given: " + namespace); + } + + this._statusHandler = resultsHandler; + + // serialize the value; + // handle strings differently so they have better performance + if(dojo.isString(value)){ + value = "string:" + value; + }else{ + value = dojo.toJson(value); + } + + dojox.flash.comm.put(key, value, namespace); + }, + + putMultiple: function(keys, values, resultsHandler, namespace){ + if(!this.isValidKeyArray(keys) || ! values instanceof Array + || keys.length != values.length){ + throw new Error("Invalid arguments: keys = [" + keys + "], values = [" + values + "]"); + } + + if(!namespace){ + namespace = dojox.storage.DEFAULT_NAMESPACE; + } + + if(!this.isValidKey(namespace)){ + throw new Error("Invalid namespace given: " + namespace); + } + + this._statusHandler = resultsHandler; + + // Convert the arguments on strings we can pass along to Flash + var metaKey = keys.join(","); + var lengths = []; + for(var i=0;i