Deviant State Machine


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. transitionTo: function(newState, e) {
  2. transition = "from_" + this.state + "_to_" + newState;
  3. switch(transition) {
  4. case 'from_waiting_to_anchoring':
  5. anchorSelection(e);
  6. this.state = 'anchoring';
  7. break;
  8.  
  9. case 'from_anchoring_to_anchoring':
  10. break;
  11.  
  12. case 'from_anchoring_to_drawing':
  13. resizeSelection(e);
  14. this.state = 'drawing';
  15. break;
  16.  
  17. case 'from_drawing_to_drawing':
  18. resizeSelection(e);
  19. break;
  20.  
  21. case 'from_anchoring_to_choosing':
  22. checkRectangleSize(e);
  23. setSelectionValues();
  24. $('appearance_name').value = '';
  25. showVisualTagForm();
  26. this.state = 'choosing';
  27. break;
  28.  
  29. case 'from_drawing_to_choosing':
  30. checkRectangleSize(e);
  31. setSelectionValues();
  32. $('appearance_name').value = '';
  33. showVisualTagForm();
  34. this.state = 'choosing';
  35. break;
  36.  
  37. case 'from_choosing_to_start_dragging':
  38. $('visual-tag-form').hide();
  39. this.pointerOffset = pointerRelativeToSelection(e);
  40. repositionSelection(this.pointerOffset, e);
  41. this.previousState = 'choosing';
  42. this.state = 'dragging';
  43. break;
  44.  
  45. case 'from_choosing_more_to_start_dragging':
  46. $('visual-tag-form').hide();
  47. this.pointerOffset = pointerRelativeToSelection(e);
  48. repositionSelection(this.pointerOffset, e);
  49. this.previousState = 'choosing_more';
  50. this.state = 'dragging';
  51. break;
  52.  
  53. case 'from_dragging_to_dragging':
  54. repositionSelection(this.pointerOffset, e);
  55. break;
  56.  
  57. case 'from_dragging_to_choosing':
  58. $('appearance-rectangle').setStyle({ cursor: 'default' });
  59. setSelectionValues();
  60. showVisualTagForm();
  61. this.state = 'choosing';
  62. break;
  63.  
  64. case 'from_dragging_to_choosing_more':
  65. $('appearance-rectangle').setStyle({ cursor: 'default' });
  66. setSelectionValues();
  67. showVisualTagForm();
  68. this.state = 'choosing';
  69. break;
  70.  
  71. case 'from_dragging_to_adding':
  72. $('appearance-rectangle').setStyle({ cursor: 'default' });
  73. $('new-person-form').show();
  74. this.state = 'adding';
  75. break;
  76.  
  77. case 'from_choosing_to_getting_more':
  78. $('searching-indicator').show();
  79. addMoreRelatives();
  80. this.state = 'getting_more';
  81. break;
  82.  
  83. case 'from_getting_more_to_choosing_more':
  84. this.state = 'choosing_more';
  85. break;
  86.  
  87. case 'from_choosing_more_to_getting_more':
  88. addMoreRelatives();
  89. this.state = 'getting_more';
  90. break;
  91.  
  92. case 'from_choosing_to_adding':
  93. $('tag-selection-list').hide();
  94. $('new-person-form').show();
  95. initNewPersonForm();
  96. this.state = 'adding';
  97. break;
  98.  
  99. case 'from_getting_more_to_adding':
  100. $('tag-selection-list').hide();
  101. $('new-person-form').show();
  102. initNewPersonForm();
  103. this.state = 'adding';
  104. break;
  105.  
  106. case 'from_choosing_more_to_adding':
  107. $('tag-selection-list').hide();
  108. $('new-person-form').show();
  109. initNewPersonForm();
  110. this.state = 'adding';
  111. break;
  112.  
  113. case 'from_adding_to_start_dragging':
  114. $('visual-tag-form').hide();
  115. this.pointerOffset = pointerRelativeToSelection(e);
  116. repositionSelection(this.pointerOffset, e);
  117. this.previousState = 'adding';
  118. this.state = 'dragging';
  119. break;
  120.  
  121. case 'from_adding_to_choosing_more':
  122. $('outer-cancel-link').show();
  123. $('tag-selection-list').show();
  124. $('new-person-form').hide();
  125. resetNewPersonForm();
  126. showVisualTagForm();
  127. this.state = 'choosing_more';
  128. break;
  129.  
  130. case 'from_adding_to_choosing':
  131. Kinfo.Appearance.resetNewPersonForm();
  132. Kinfo.Appearance.reloadPrimaryRelations();
  133. $('outer-cancel-link').show();
  134. $('tag-selection-list').show();
  135. $('new-person-form').hide();
  136. showVisualTagForm();
  137. this.state = 'choosing';
  138. break;
  139. }
  140. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.