www.webOShelp.net

Get the latest on:webOS Developers' RSS FeedwebOS Facebook page webOS Twitter Feed

Home Resources API Reference Mojo.Model.Cookie()

Mojo.Model.Cookie()

Example usage:

This function loads or creates a cookie at application startup:

//Get preferences cookie, or create it 
this.cookie = new Mojo.Model.Cookie("NewsPrefs"); 
var oldNewsPrefs = this.cookie.get(); 
if (oldNewsPrefs) { 
    if (oldNewsPrefs.newsVersionString == "1.0"){ 
            featureIndexFeed = oldNewsPrefs.featureIndexFeed; 
            featureFeedEnable = oldNewsPrefs.featureFeedEnable; 
            featureStoryInterval = oldNewsPrefs.featureStoryInterval; 
            feedUpdateInterval = oldNewsPrefs.feedUpdateInterval; 
            updateDialog = oldNewsPrefs.updateDialog; 
     } else { 
            this.cookie.put({ 
               featureIndexFeed: featureIndexFeed, 
               featureFeedEnable: featureFeedEnable, 
               feedUpdateInterval: feedUpdateInterval, 
               featureStoryInterval: featureStoryInterval, 
               newsVersionString: newsVersionString 
            });
      } 
   } 
}); 

This function writes preferences to a cookie when a "preferences" scene is popped:

//    Deactivate - update cookie
//
NewsPrefsAssistant.prototype.deactivate = function() {
    this.stageAssistant.cookie.put(        {
        featureIndexFeed: this.featureFeedListModel.value,
        featureFeedEnable: this.featureFeedToggleModel.value,
        feedUpdateInterval: this.feedIntervalModel.value,
        newsVersionString: newsVersionString,
        featureStoryInterval: featureStoryInterval
    });
};

To delete a cookie:

cookie.remove()
 

3 Comments

Feed
  1. The closing parenthesis on the put() in the first example needs to be moved to after the }
  2. Fixed. Thanks, aphie!
  3. so where do these functions go?

Add Comment


    • >:o
    • :-[
    • :'(
    • :-(
    • :-D
    • :-*
    • :-)
    • :P
    • :\
    • 8-)
    • ;-)