Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 15. Some Interesting Beta Compon... > Using the StyleSheet component - Pg. 388

Some Interesting Beta Components You can pass up to three optional parameters to the get function of StorageManager: the desired engine by name (such as StorageEngineHTML5.ENGINE_NAME ), the desired location (either StorageManager.LOCATION_SESSION or StorageManager.LOCATION_ LOCAL ), and a configuration object. If you specify a desired engine the StorageManager will attempt to instantiate that engine first, before defaulting to the next available engine. You can set the force configuration proper true , if you want the function to throw an o exception when your engine is unavailable. The other configuration proper engine , which allows you to pass variables into the Storage subclass instance (currently this is used by StorageEngineSWF only). Once you have an instance, you need to subscribe to the \Storage.CE_READY event, which will fire when the engine is ready or right away, if it is already ready. When the engine is ready, you can use the getItem , setItem , and removeItem functions to interact with the storage engine. The length proper e the number of keys stored in the engine and the key function allows you to fetch the key at a given index. You may remove all keys by calling the clear function. Keep in mind these instances are singletons and if you have several variables using the same instance, and changing a value in one instance, will change the value in all instances. If your code needs to know when a key is changed, you can subscribe to the Storage.CE_ CHANGE event. This is fired anytime the value of a key is updated. The callback function will be passed a StorageEvent object with the following proper key , oldValue , newValue , url , window , storageArea , and type . The key is the key that is changed, the oldValue is the previous value of that key, and newValue is the new value of that key. The url is the URL of the page and the window is the window context that triggered this storage event. The storageArea is the same as the storage location (either StorageManager.LOCATION_ SESSION or StorageManager.LOCATION_LOCAL ). And the type is one of the three possible