core.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // CORE
  3. //
  4. App.Core.listen = function()
  5. {
  6. fb.log('start listening');
  7. $(document).bind('click', function(evt) {
  8. App.Helpers.handleItemsRegisteredInBackground(evt);
  9. var elm = $(evt.target);
  10. var action = $(elm).attr('class');
  11. if (!action) {
  12. return fb.log('No action passed');
  13. }
  14. action = action.split('do_action_');
  15. if (action.length < 2) {
  16. if (elm.hasClass('check-this')) {
  17. var ref = $(elm).parents('.row');
  18. ref.hasClass('checked-row') ? ref.removeClass('checked-row') : ref.addClass('checked-row');
  19. }
  20. return; // no action found attached to the dom object
  21. }
  22. try {
  23. action_with_params = action[1].split(' ');// retrieve the action itself
  24. action = action_with_params[0];
  25. App.Core.__CALL__(evt, action);// Call the action
  26. }
  27. catch(e) {
  28. fb.error(e);
  29. }
  30. });
  31. $(document).bind('keyup', function(evt) {
  32. fb.log(evt.keyCode);
  33. if ('undefined' != typeof App.Constants.KEY.CODED_NAME[evt.keyCode]) {
  34. var method_name = 'keyboard_' + App.Constants.KEY.CODED_NAME[evt.keyCode];
  35. App.Helpers[method_name] && App.Helpers[method_name](evt);
  36. }
  37. });
  38. }
  39. /**
  40. * Action caller
  41. * if no action registered, execution will stop
  42. */
  43. App.Core.__CALL__ = function(evt, action)
  44. {
  45. if ('undefined' == typeof App.Actions[action]) {
  46. return alert('No action registered for: "'+action+'". Stop propagation');
  47. }
  48. else{
  49. return App.Actions[action](evt);
  50. }
  51. }
  52. App.Core.initMenu = function()
  53. {
  54. $('.section').bind('click', function(evt) {
  55. var elm = $(evt.target);
  56. !elm.hasClass('section') ? elm = elm.parents('.section') : -1;
  57. if (App.Env.world != elm.attr('id')) {
  58. App.Env.world = elm.attr('id');
  59. App.Pages.init();
  60. fb.warn('Switch page to: ' + App.Env.world);
  61. }
  62. });
  63. }