[OpenLayers-Commits] r7328 - in sandbox/tschaub/olon/examples: . persist

commits at openlayers.org commits at openlayers.org
Fri Jun 6 16:20:13 EDT 2008


Author: tschaub
Date: 2008-06-06 16:20:12 -0400 (Fri, 06 Jun 2008)
New Revision: 7328

Added:
   sandbox/tschaub/olon/examples/persist/
   sandbox/tschaub/olon/examples/persist/persist.js
   sandbox/tschaub/olon/examples/persist/persist.swf
Modified:
   sandbox/tschaub/olon/examples/olon.html
Log:
updated example

Modified: sandbox/tschaub/olon/examples/olon.html
===================================================================
--- sandbox/tschaub/olon/examples/olon.html	2008-06-06 20:19:23 UTC (rev 7327)
+++ sandbox/tschaub/olon/examples/olon.html	2008-06-06 20:20:12 UTC (rev 7328)
@@ -1,131 +1,102 @@
 <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
+    <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
+    <link rel="stylesheet" href="style.css" type="text/css" />
     <style type="text/css">
-        #map {
-            width: 400px;
-            height: 400px;
-            border: 1px solid gray;
-        }
-        #col {
-            position: absolute;
-            top: 1.75em;
-            left: 425px;
-        }
         #output {
-            width: 400px;
-            height: 350px;
+            width: 512px;
+            height: 150px;
         }
-        p {
-            margin: 1em 0;
-            width: 800px;
-        }
     </style>
     <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAeDjUod8ItM9dBg5_lz0esxTk5UTxNMOJaMwpeYJby65YwI0-cxSmHf2_ZfIP7bDb_moMph5qZy25YA" type="text/javascript"></script>
-    <!--
-    <script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script>
-    -->
     <script src="../lib/OpenLayers.js"></script>
+    <script src="persist/persist.js"></script>
     <script type="text/javascript">
-        var lon = 5;
-        var lat = 40;
-        var zoom = 5;
-        var map, controls, panel, switcher;
+        var map, panel, switcher, store;
 
-        function init(){
+        function init() {
+            store = new Persist.Store("OLON Example");
             var options = {
                 projection: "EPSG:900913",
                 units: "m",
                 maxResolution: 156543.0339,
                 maxExtent: new OpenLayers.Bounds(-20037508, -20037508,
-                                                 20037508, 20037508.34)
+                                                 20037508, 20037508)
             };
             map = new OpenLayers.Map('map', options);
+            restoreState(initMap);
+        }
+        
+        function initMap() {
 
-            if(!restoreState()) {
-    
-                // create Google Mercator layers
-                var gmap = new OpenLayers.Layer.Google(
-                    "Google Streets",
-                    {'sphericalMercator': true}
-                );
-    
-                // create WMS layer
-                var wms = new OpenLayers.Layer.WMS(
-                    "World Map",
-                    "http://world.freemap.in/tiles/",
-                    {'layers': 'factbook-overlay', 'format':'png'},
-                    {
-                        'reproject': false, 'opacity': 0.4,
-                        'isBaseLayer': false,'wrapDateLine': true
-                    }
-                );
-    
-                // create a vector layer for drawing
-                var vector = new OpenLayers.Layer.Vector("Editable Vectors");
-                
-                map.addLayers([gmap, wms, vector]);
-                panel = new OpenLayers.Control.EditingToolbar(vector);
-                map.addControl(panel);
-                switcher = new OpenLayers.Control.LayerSwitcher();
-                map.addControl(switcher);
-                map.zoomToMaxExtent();
-            }
+            // create Google Mercator layers
+            var gmap = new OpenLayers.Layer.Google(
+                "Google Streets",
+                {'sphericalMercator': true}
+            );
 
+            // create WMS layer
+            var wms = new OpenLayers.Layer.WMS(
+                "World Map",
+                "http://world.freemap.in/tiles/",
+                {'layers': 'factbook-overlay', 'format':'png'},
+                {
+                    'reproject': false, 'opacity': 0.4,
+                    'isBaseLayer': false,'wrapDateLine': true
+                }
+            );
+
+            // create a vector layer for drawing
+            var vector = new OpenLayers.Layer.Vector("Editable Vectors");
+            
+            map.addLayers([gmap, wms, vector]);
+            panel = new OpenLayers.Control.EditingToolbar(vector);
+            // this should be in EditingToolbar
+            panel.defaultControl = panel.controls[0];
+            map.addControl(panel);
+            switcher = new OpenLayers.Control.LayerSwitcher();
+            map.addControl(switcher);
+            map.zoomToMaxExtent();
         }
         
         var olon = new OpenLayers.Format.OLON();
         
         function saveState() {
-            var str = olon.write(map);
-            if(str.length < 3950) {
-                createCookie("olmap", str, 10);
-                document.getElementById('output').value = "saved:\n\n" + str;
-            } else {
-                document.getElementById('output').value = "too long:\n\n" + str;
-            }
+            panel.deactivate();
+            store.set("olon", olon.write(map), function(ok, str) {
+                if(ok) {
+                    report("saved:\n\n" + str);
+                } else {
+                    report("failed to save map");
+                }
+            });
+            panel.activate();
         }
-        function restoreState() {
-            var restored = false;
-            var str = readCookie("olmap");
-            if(str) {
-                deserializeMap(str);
-                restored = true;
-                document.getElementById('output').value = "restored:\n\n" + str;
-            } else {
-                document.getElementById('output').value = 'no state saved';
-            }
-            return restored;
-        }
-
-        function createCookie(name, value, days) {
-            var expires = "";
-            if(days) {
-                var date = new Date();
-                date.setTime(date.getTime()+(days*24*60*60*1000));
-                expires = "; expires="+date.toGMTString();
-            }
-            document.cookie = name + "=" + value + expires + "; path=/";
-        }
-        function readCookie(name) {
-            var value = null;
-            var nameEQ = name + "=";
-            var ca = document.cookie.split(';');
-            for(var i=0; i<ca.length; i++) {
-                var c = ca[i].replace(/^s+/, '');
-                if(c.indexOf(nameEQ) == 0) {
-                    value = c.substring(nameEQ.length, c.length);
-                    break;
+        function restoreState(failure) {
+            store.get("olon", function(ok, str) {
+                if(ok && str) {
+                    if(typeof str == "object") {
+                        str = str.value;
+                    }
+                    deserializeMap(str);
+                    report("restored:\n\n" + str);
+                } else {
+                    report("no state saved");
+                    if(failure) {
+                        failure();
+                    }
                 }
-            }
-            return value;
+            });
         }
-        function eraseCookie(name) {
-            createCookie(name,"",-1);
+        
+        function report(msg) {
+            document.getElementById('output').value = msg;
         }
 
         function serializeMap() {
-            var str = olon.write(map, true);
-            document.getElementById('output').value = str;
+            panel.deactivate();
+            report(olon.write(map, true));
+            panel.activate();
         }
 
         function clearMap() {
@@ -151,6 +122,8 @@
             // hack to reset the editing toolbar
             var vector = map.layers[2];
             panel = new OpenLayers.Control.EditingToolbar(vector);
+            // this should be in EditingToolbar
+            panel.defaultControl = panel.controls[0];
             map.addControl(panel);
 
             if(!switcher) {
@@ -158,9 +131,11 @@
                 map.addControl(switcher);
             }
         }
+
         function clearSaved() {
-            eraseCookie("olmap");
-            document.getElementById('output').value = "cookie erased";
+            store.remove("olon", function(ok, val) {
+                report("store cleared");
+            });
         }
         function clearFeatures() {
             var vector = map.layers[2];
@@ -169,9 +144,9 @@
     </script>
   </head>
   <body onload="init()">
-    <h3>OpenLayers Object Notation</h3>
-    <div id="map"></div>
-    <div id="col">
+    <h1 id="title">OpenLayers Object Notation</h1>
+    <div id="map" class="smallmap"></div>
+    <div>
         <a href="javascript: void saveState();">save state</a> |
         <a href="javascript: void restoreState();">restore state</a> |
         <a href="javascript: void clearSaved();">clear saved state</a><br />
@@ -179,11 +154,13 @@
         <a href="javascript: void serializeMap();">serialize map</a> |
         <a href="javascript: void clearFeatures();">clear features</a><br />
     </div>
-    <p>This example show how a map can be serialized using OpenLayers Object Notation.
-    The serialized map can be saved somewhere (like a cookie if it's under 4KB), and
-    deserialized to restore the state of a map.  Serializing features on a vector layer
-    is possible, but creates a string that is typically too large for cookie storage</p>
-    <p>Navigate to some location, turn layers on/off, click save state.  Close this page
-    and reopen it (or just refresh) to see the state restored.</p>
+    <div id="docs">
+        <p>This example show how a map can be serialized using OpenLayers
+        Object Notation. The serialized map can be saved somewhere, and
+        deserialized to restore the state of a map.</p>
+        <p>Navigate to some location, turn layers on/off, click save state.
+        Close this page and reopen it (or just refresh) to see the state
+        restored.</p>
+    </div>
   </body>
 </html>

Added: sandbox/tschaub/olon/examples/persist/persist.js
===================================================================
--- sandbox/tschaub/olon/examples/persist/persist.js	                        (rev 0)
+++ sandbox/tschaub/olon/examples/persist/persist.js	2008-06-06 20:20:12 UTC (rev 7328)
@@ -0,0 +1,110 @@
+//
+// Copyright (c) 2008 Paul Duncan (paul at pablotron.org)
+// 
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+// 
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+(function(){if(window.google&&google.gears){return;}
+var factory=null;if(typeof GearsFactory!='undefined'){factory=new GearsFactory();}else{try{factory=new ActiveXObject('Gears.Factory');if(factory.getBuildInfo().indexOf('ie_mobile')!=-1){factory.privateSetGlobalObject(this);}}catch(e){if((typeof navigator.mimeTypes!='undefined')&&navigator.mimeTypes["application/x-googlegears"]){factory=document.createElement("object");factory.style.display="none";factory.width=0;factory.height=0;factory.type="application/x-googlegears";document.documentElement.appendChild(factory);}}}
+if(!factory){return;}
+if(!window.google){google={};}
+if(!google.gears){google.gears={factory:factory};}})();if(typeof deconcept=="undefined")var deconcept=new Object();if(typeof deconcept.util=="undefined")deconcept.util=new Object();if(typeof deconcept.SWFObjectUtil=="undefined")deconcept.SWFObjectUtil=new Object();deconcept.SWFObject=function(swf,id,w,h,ver,c,quality,xiRedirectUrl,redirectUrl,detectKey){if(!document.getElementById){return;}
+this.DETECT_KEY=detectKey?detectKey:'detectflash';this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(swf){this.setAttribute('swf',swf);}
+if(id){this.setAttribute('id',id);}
+if(w){this.setAttribute('width',w);}
+if(h){this.setAttribute('height',h);}
+if(ver){this.setAttribute('version',new deconcept.PlayerVersion(ver.toString().split(".")));}
+this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}
+if(c){this.addParam('bgcolor',c);}
+var q=quality?quality:'high';this.addParam('quality',q);this.setAttribute('useExpressInstall',false);this.setAttribute('doExpressInstall',false);var xir=(xiRedirectUrl)?xiRedirectUrl:window.location;this.setAttribute('xiRedirectUrl',xir);this.setAttribute('redirectUrl','');if(redirectUrl){this.setAttribute('redirectUrl',redirectUrl);}}
+deconcept.SWFObject.prototype={useExpressInstall:function(path){this.xiSWFPath=!path?"expressinstall.swf":path;this.setAttribute('useExpressInstall',true);},setAttribute:function(name,value){this.attributes[name]=value;},getAttribute:function(name){return this.attributes[name];},addParam:function(name,value){this.params[name]=value;},getParams:function(){return this.params;},addVariable:function(name,value){this.variables[name]=value;},getVariable:function(name){return this.variables[name];},getVariables:function(){return this.variables;},getVariablePairs:function(){var variablePairs=new Array();var key;var variables=this.getVariables();for(key in variables){variablePairs.push(key+"="+variables[key]);}
+return variablePairs;},getSWFHTML:function(){var swfNode="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute('swf',this.xiSWFPath);}
+swfNode='<embed type="application/x-shockwave-flash" src="'+this.getAttribute('swf')+'" width="'+this.getAttribute('width')+'" height="'+this.getAttribute('height')+'"';swfNode+=' id="'+this.getAttribute('id')+'" name="'+this.getAttribute('id')+'" ';var params=this.getParams();for(var key in params){swfNode+=[key]+'="'+params[key]+'" ';}
+var pairs=this.getVariablePairs().join("&");if(pairs.length>0){swfNode+='flashvars="'+pairs+'"';}
+swfNode+='/>';}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute('swf',this.xiSWFPath);}
+swfNode='<object id="'+this.getAttribute('id')+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+this.getAttribute('width')+'" height="'+this.getAttribute('height')+'">';swfNode+='<param name="movie" value="'+this.getAttribute('swf')+'" />';var params=this.getParams();for(var key in params){swfNode+='<param name="'+key+'" value="'+params[key]+'" />';}
+var pairs=this.getVariablePairs().join("&");if(pairs.length>0){swfNode+='<param name="flashvars" value="'+pairs+'" />';}
+swfNode+="</object>";}
+return swfNode;},write:function(elementId){if(this.getAttribute('useExpressInstall')){var expressInstallReqVer=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(expressInstallReqVer)&&!this.installedVer.versionIsValid(this.getAttribute('version'))){this.setAttribute('doExpressInstall',true);this.addVariable("MMredirectURL",escape(this.getAttribute('xiRedirectUrl')));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}
+if(this.skipDetect||this.getAttribute('doExpressInstall')||this.installedVer.versionIsValid(this.getAttribute('version'))){var n=(typeof elementId=='string')?document.getElementById(elementId):elementId;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute('redirectUrl')!=""){document.location.replace(this.getAttribute('redirectUrl'));}}
+return false;}}
+deconcept.SWFObjectUtil.getPlayerVersion=function(){var PlayerVersion=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){PlayerVersion=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");PlayerVersion=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(PlayerVersion.major==6){return PlayerVersion;}}
+try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}
+if(axo!=null){PlayerVersion=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}
+return PlayerVersion;}
+deconcept.PlayerVersion=function(arrVersion){this.major=arrVersion[0]!=null?parseInt(arrVersion[0]):0;this.minor=arrVersion[1]!=null?parseInt(arrVersion[1]):0;this.rev=arrVersion[2]!=null?parseInt(arrVersion[2]):0;}
+deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major)return false;if(this.major>fv.major)return true;if(this.minor<fv.minor)return false;if(this.minor>fv.minor)return true;if(this.rev<fv.rev)return false;return true;}
+deconcept.util={getRequestParameter:function(param){var q=document.location.search||document.location.hash;if(q){var pairs=q.substring(1).split("&");for(var i=0;i<pairs.length;i++){if(pairs[i].substring(0,pairs[i].indexOf("="))==param){return pairs[i].substring((pairs[i].indexOf("=")+1));}}}
+return"";}}
+deconcept.SWFObjectUtil.cleanupSWFs=function(){var objects=document.getElementsByTagName("OBJECT");for(var i=0;i<objects.length;i++){objects[i].style.display='none';for(var x in objects[i]){if(typeof objects[i][x]=='function'){objects[i][x]=function(){};}}}}
+if(deconcept.SWFObject.doPrepUnload){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);}
+window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);}
+if(Array.prototype.push==null){Array.prototype.push=function(item){this[this.length]=item;return this.length;}}
+var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;Persist=(function(){var VERSION='0.1.0',P,B,esc,init,empty,ec;ec=(function(){var EPOCH='Thu, 01-Jan-1970 00:00:01 GMT',RATIO=1000*60*60*24,KEYS=['expires','path','domain'],esc=escape,un=unescape,doc=document,me;var get_now=function(){var r=new Date();r.setTime(r.getTime());return r;}
+var cookify=function(c_key,c_val){var i,key,val,r=[],opt=(arguments.length>2)?arguments[2]:{};r.push(esc(c_key)+'='+esc(c_val));for(i=0;i<KEYS.length;i++){key=KEYS[i];if(val=opt[key])
+r.push(key+'='+val);}
+if(opt.secure)
+r.push('secure');return r.join('; ');}
+var alive=function(){var k='__EC_TEST__',v=new Date();v=v.toGMTString();this.set(k,v);this.enabled=(this.remove(k)==v);return this.enabled;}
+me={set:function(key,val){var opt=(arguments.length>2)?arguments[2]:{},now=get_now(),expire_at,cfg={};if(opt.expires){opt.expires*=RATIO;cfg.expires=new Date(now.getTime()+opt.expires);cfg.expires=cfg.expires.toGMTString();}
+var keys=['path','domain','secure'];for(i=0;i<keys.length;i++)
+if(opt[keys[i]])
+cfg[keys[i]]=opt[keys[i]];var r=cookify(key,val,cfg);doc.cookie=r;return val;},has:function(key){key=esc(key);var c=doc.cookie,ofs=c.indexOf(key+'='),len=ofs+key.length+1,sub=c.substring(0,key.length);return((!ofs&&key!=sub)||ofs<0)?false:true;},get:function(key){key=esc(key);var c=doc.cookie,ofs=c.indexOf(key+'='),len=ofs+key.length+1,sub=c.substring(0,key.length),end;if((!ofs&&key!=sub)||ofs<0)
+return null;end=c.indexOf(';',len);if(end<0)
+end=c.length;return un(c.substring(len,end));},remove:function(k){var r=me.get(k),opt={expires:EPOCH};doc.cookie=cookify(k,'',opt);return r;},keys:function(){var c=doc.cookie,ps=c.split('; '),i,p,r=[];for(i=0;i<ps.length;i++){p=ps[i].split('=');r.push(un(p[0]));}
+return r;},all:function(){var c=doc.cookie,ps=c.split('; '),i,p,r=[];for(i=0;i<ps.length;i++){p=ps[i].split('=');r.push([un(p[0]),un(p[1])]);}
+return r;},version:'0.2.1',enabled:false};me.enabled=alive.call(me);return me;}());empty=function(){};esc=function(str){return'PS'+str.replace(/_/g,'__').replace(/ /g,'_s');};C={search_order:['gears','localstorage','whatwg_db','globalstorage','flash','ie','cookie'],name_re:/^[a-z][a-z0-9_ -]+$/i,methods:['init','get','set','remove','load','save'],sql:{version:'1',create:"CREATE TABLE IF NOT EXISTS persist_data (k TEXT UNIQUE NOT NULL PRIMARY KEY, v TEXT NOT NULL)",get:"SELECT v FROM persist_data WHERE k = ?",set:"INSERT INTO persist_data(k, v) VALUES (?, ?)",remove:"DELETE FROM persist_data WHERE k = ?"},flash:{div_id:'_persist_flash_wrap',id:'_persist_flash',path:'persist.swf',size:{w:1,h:1},args:{autostart:true}}};B={gears:{size:-1,test:function(){return(window.google&&window.google.gears)?true:false;},methods:{transaction:function(fn){var db=this.db;db.execute('BEGIN').close();fn.call(this,db);db.execute('COMMIT').close();},init:function(){var db;db=this.db=google.gears.factory.create('beta.database');db.open(esc(this.name));db.execute(C.sql.create).close();},get:function(key,fn,scope){var r,sql=C.sql.get;if(!fn)
+return;this.transaction(function(t){r=t.execute(sql,[key]);if(r.isValidRow())
+fn.call(scope||this,true,r.field(0));else
+fn.call(scope||this,false,null);r.close();});},set:function(key,val,fn,scope){var rm_sql=C.sql.remove,sql=C.sql.set,r;this.transaction(function(t){t.execute(rm_sql,[key]).close();t.execute(sql,[key,val]).close();if(fn)
+fn.call(scope||this,true,val);});},remove:function(key,fn,scope){var get_sql=C.sql.get;sql=C.sql.remove,r,val;this.transaction(function(t){if(fn){r=t.execute(get_sql,[key]);if(r.isValidRow()){val=r.field(0);t.execute(sql,[key]).close();fn.call(scope||this,true,val);}else{fn.call(scope||this,false,null);}
+r.close();}else{t.execute(sql,[key]).close();}});}}},whatwg_db:{size:200*1024,test:function(){var name='PersistJS Test',desc='Persistent database test.';if(!window.openDatabase)
+return false;if(!window.openDatabase(name,C.sql.version,desc,B.whatwg_db.size))
+return false;return true;},methods:{transaction:function(fn){if(!this.db_created){var sql=C.sql.create;this.db.transaction(function(t){t.executeSql(sql,[],function(){this.db_created=true;});},empty);}
+this.db.transaction(fn);},init:function(){var desc,size;desc=this.o.about||"Persistent storage for "+this.name;size=this.o.size||B.whatwg_db.size;this.db=openDatabase(this.name,C.sql.version,desc,size);},get:function(key,fn,scope){var sql=C.sql.get;if(!fn)
+return;scope=scope||this;this.transaction(function(t){t.executeSql(sql,[key],function(t,r){if(r.rows.length>0)
+fn.call(scope,true,r.rows.item(0)['v']);else
+fn.call(scope,false,null);});});},set:function(key,val,fn,scope){var rm_sql=C.sql.remove,sql=C.sql.set;this.transaction(function(t){t.executeSql(rm_sql,[key],function(){t.executeSql(sql,[key,val],function(t,r){if(fn)
+fn.call(scope||this,true,val);});});});return val;},remove:function(key,fn,scope){var get_sql=C.sql.get;sql=C.sql.remove;this.transaction(function(t){if(fn){t.executeSql(get_sql,[key],function(t,r){if(r.rows.length>0){var val=r.rows.item(0)['v'];t.executeSql(sql,[key],function(t,r){fn.call(scope||this,true,val);});}else{fn.call(scope||this,false,null);}});}else{t.executeSql(sql,[key]);}});}}},globalstorage:{size:5*1024*1024,test:function(){return window.globalStorage?true:false;},methods:{key:function(key){return esc(this.name)+esc(key);},init:function(){this.store=globalStorage[this.o.domain];},get:function(key,fn,scope){key=this.key(key);if(fn)
+fn.call(scope||this,true,this.store.getItem(key));},set:function(key,val,fn,scope){key=this.key(key);this.store.setItem(key,val);if(fn)
+fn.call(scope||this,true,val);},remove:function(key,fn,scope){var val;key=this.key(key);val=this.store[key];this.store.removeItem(key);if(fn)
+fn.call(scope||this,(val!==null),val);}}},localstorage:{size:-1,test:function(){return window.localStorage?true:false;},methods:{key:function(key){return esc(this.name)+esc(key);},init:function(){this.store=localStorage;},get:function(key,fn,scope){key=this.key(key);if(fn)
+fn.call(scope||this,true,this.store.getItem(key));},set:function(key,val,fn,scope){key=this.key(key);this.store.setItem(key,val);if(fn)
+fn.call(scope||this,true,val);},remove:function(key,fn,scope){var val;key=this.key(key);val=this.getItem(key);this.store.removeItem(key);if(fn)
+fn.call(scope||this,(val!==null),val);}}},ie:{prefix:'_persist_data-',size:64*1024,test:function(){return window.ActiveXObject?true:false;},make_userdata:function(id){var el=document.createElement('div');el.id=id;el.style.display='none';el.addBehavior('#default#userData');document.body.appendChild(el);return el;},methods:{init:function(){var id=B.ie.prefix+esc(this.name);this.el=B.ie.make_userdata(id);if(this.o.defer)
+this.load();},get:function(key,fn,scope){var val;key=esc(key);if(!this.o.defer)
+this.load();val=this.el.getAttribute(key);if(fn)
+fn.call(scope||this,val?true:false,val);},set:function(key,val,fn,scope){key=esc(key);this.el.setAttribute(key,val);if(!this.o.defer)
+this.save();if(fn)
+fn.call(scope||this,true,val);},load:function(){this.el.load(esc(this.name));},save:function(){this.el.save(esc(this.name));}}},cookie:{delim:':',size:4000,test:function(){return P.Cookie.enabled?true:false;},methods:{key:function(key){return this.name+B.cookie.delim+key;},get:function(key,val,fn,scope){key=this.key(key);val=ec.get(key);if(fn)
+fn.call(scope||this,val!=null,val);},set:function(key,val,fn,scope){key=this.key(key);ec.set(key,val,this.o);if(fn)
+fn.call(scope||this,true,val);},remove:function(key,val,fn,scope){var val;key=this.key(key);val=ec.remove(key)
+if(fn)
+fn.call(scope||this,val!=null,val);}}},flash:{test:function(){if(!window.SWFObject||!deconcept||!deconcept.SWFObjectUtil)
+return false;var major=deconcept.SWFObjectUtil.getPlayerVersion().major;return(major>=8)?true:false;},methods:{init:function(){if(!B.flash.el){var o,key,el,cfg=C.flash;el=document.createElement('div');el.id=cfg.div_id;document.body.appendChild(el);o=new SWFObject(this.o.swf_path||cfg.path,cfg.id,cfg.size.w,cfg.size.h,'8');for(key in cfg.args)
+o.addVariable(key,cfg.args[key]);o.write(el);B.flash.el=document.getElementById(cfg.id);}
+this.el=B.flash.el;},get:function(key,fn,scope){var val;key=esc(key);val=this.el.get(this.name,key);if(fn)
+fn.call(scope||this,val!==null,val);},set:function(key,val,fn,scope){var old_val;key=esc(key);old_val=this.el.set(this.name,key,val);if(fn)
+fn.call(scope||this,true,val);},remove:function(key,fn,scope){var val;key=esc(key);val=this.el.remove(this.name,key);if(fn)
+fn.call(scope||this,true,val);}}}};var init=function(){var i,l,b,key,fns=C.methods,keys=C.search_order;for(i=0,l=fns.length;i<l;i++)
+P.Store.prototype[fns[i]]=empty;P.type=null;P.size=-1;for(i=0,l=keys.length;!P.type&&i<l;i++){b=B[keys[i]];if(b.test()){P.type=keys[i];P.size=b.size;for(key in b.methods)
+P.Store.prototype[key]=b.methods[key];}}
+P._init=true;};P={VERSION:VERSION,type:null,size:0,add:function(o){B[o.id]=o;C.search_order=[o.id].concat(C.search_order);init();},remove:function(id){var ofs=C.search_order.indexOf(id);if(ofs<0)
+return;C.search_order.splice(ofs,1);delete B[id];init();},Cookie:ec,Store:function(name,o){if(!C.name_re.exec(name))
+throw new Error("Invalid name");if(!P.type)
+throw new Error("No suitable storage found");o=o||{};this.name=name;o.domain=o.domain||location.hostname||'localhost.localdomain';this.o=o;o.expires=o.expires||365*2;o.path=o.path||'/';this.init();}};init();return P;})();
\ No newline at end of file

Added: sandbox/tschaub/olon/examples/persist/persist.swf
===================================================================
(Binary files differ)


Property changes on: sandbox/tschaub/olon/examples/persist/persist.swf
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream



More information about the Commits mailing list