www.webOShelp.net

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

CommandMenu

Example usage:
// StoryViewAssistant(storyFeed, storyIndex)
//
// Passed a story element, displays that element in a
// full scene view and offers options for next story (right
// command menu button), previous story (left command menu button)
// and to launch story URL in the browser (view menu).

function StoryViewAssistant(storyFeed, storyIndex) {
  // Save the passed arguments for use in the scene.
  //
  this.storyFeed = storyFeed;
  this.storyIndex = storyIndex;
}

StoryViewAssistant.prototype.setup = function() {
  // Setup command menu for next and previous story as a menu group.
  // If first story, suppress Previous menu; if last story, suppress Next menu
  this.storyMenuAttr = {items: [{visable: false}, {items: []}, {visable: false}]};
  if (this.storyIndex > 0) {
    this.storyMenuAttr.items[1].items.push({icon: "back", command: 'do-viewPrevious'});
  } else {
    this.storyMenuAttr.items[1].items.push({icon: "", command: '', label: " "});
  }
  if (this.storyIndex < this.storyFeed.stories.length-1) {
    this.storyMenuAttr.items[1].items.push({icon: "forward", command: 'do-viewNext'});
  } else {
    this.storyMenuAttr.items[1].items.push({icon: "", command: '', label: " "});
  }
this.controller.setupWidget(Mojo.Menu.commandMenu, undefined, this.storyMenuAttr);

To handle the commands generated by the menu, set up a handleCommand() function:

// Handlers to go to next and previous stories
StoryViewAssistant.prototype.handleCommand = function(event) {
  if(event.type == Mojo.Event.command) {
    switch(event.command) {
      case 'do-viewNext':
        Mojo.Controller.stageController.swapScene("storyView",
        this.storyFeed, this.storyIndex+1);
        break;
      case 'do-viewPrevious':
        Mojo.Controller.stageController.swapScene("storyView", this.storyFeed,
        this.storyIndex-1);
        break;
    }
  }
};

The generated menu looks like this:

alt

 

webOS UI Widget List