Source: Menu.js

/*jslint plusplus: true, white: true, indent: 2, maxlen: 90 */
/**
 *  @author    Wolfgang Kowarschick
 *  @copyright 2013, Wolfgang Kowarschick
 *  <br/>
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted under the terms of the 
 *  Creative Commons License Attribution-NonCommercial-ShareAlike 3.0 Unported    
 *  (CC BY-NC-SA 3.0: http://creativecommons.org/licenses/by-nc-sa/3.0/). 
 */

// Define package $app$.game.snake, if that has not already be done.
(function($app$, document)
{ "use strict";
////////////////////////////////////////////////////////////////////////////////
// Class "Menu"
////////////////////////////////////////////////////////////////////////////////

/** 
 *  @class
 *  @name $app$.game.snake.Menu
 *  
 *  @param {Object} p_init 
 *         Should contain the attributes
 *         <code>buttonStartID</code> (the id of the start button element),
 *         <code>buttonPauseID</code> (the id of the pause button element), and
 *         <code>buttonStopID</code>  (the id of the stop button element).
 *  @param {$app$.game.snake.Controller} p_controller 
 *         The controller of the app. 
 */
function Menu(p_init, p_controller)
{ var l_button_start = document.getElementById(p_init.buttonStartID),
      l_button_pause = document.getElementById(p_init.buttonPauseID),
      l_button_stop  = document.getElementById(p_init.buttonStopID);
 
  function f_init_start()
  { p_controller.startGame(); 
    l_button_start.disabled = true;
    l_button_pause.disabled = false;
    l_button_stop.disabled  = false;
  }
  function f_init_pause()
  { p_controller.pauseGame();
    l_button_start.disabled = false;
    l_button_pause.disabled = true;
    l_button_stop.disabled  = false;
  }
  function f_init_stop()
  { p_controller.stopGame();
    l_button_start.disabled = false;
    l_button_pause.disabled = true;
    l_button_stop.disabled  = true;
  }
  
  // Do not use "click", as Firefox looses the focus when the "disabled"
  // status of buttons is changed by f_init_...
  // http://stackoverflow.com/questions/7392959/how-do-you-avoid-losing-focus-on-a-contenteditable-element-when-a-user-clicks-ou
  l_button_start.addEventListener("mousedown", f_init_start); 
  l_button_pause.addEventListener("mousedown", f_init_pause); 
  l_button_stop .addEventListener("mousedown", f_init_stop); 
  f_init_stop();
}

$app$.game.snake.Menu = Menu;

////////////////////////////////////////////////////////////////////////////////
// End of Class "Menu"
////////////////////////////////////////////////////////////////////////////////
}(this.$app$, this.document)); 
W. Kowarschick © 2013 (CC BY-NC-SA 3.0: http://creativecommons.org/licenses/by-nc-sa/3.0/)
Documentation generated by JSDoc 3.3.0-dev on Sun Dec 15 2013 11:20:32 GMT+0100 (MEZ) using the DocStrap template.