Guest User

Untitled

a guest
Feb 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. require('core');
  2.  
  3. // this code just copies in the requisite SC.ButtonView behavior to enable a standard image view to function as a button
  4.  
  5. MyApp.ImageButtonView = SC.ImageView.extend({
  6.  
  7. value: null, // could also use a CSS selector here -- see SC.ImageView
  8. isEnabled: YES,
  9. action: null,
  10. target: null,
  11. _isMouseDown: false,
  12.  
  13. // on mouse down, set active only if enabled.
  14. /** @private */
  15. mouseDown: function(evt) {
  16. this.setClassName('active',this.get('isEnabled')) ;
  17. this._isMouseDown = true;
  18. return true ;
  19. },
  20.  
  21. // remove the active class on mouse down as well
  22. /** @private */
  23. mouseOut: function(evt)
  24. {
  25. this.setClassName('active', false);
  26. return true;
  27. },
  28.  
  29. // add the active class name if the mouse is down
  30. // this covers a scenario where the user drags out and back on to a button
  31. mouseOver: function(evt)
  32. {
  33. this.setClassName('active', this._isMouseDown) ;
  34. return true;
  35. },
  36.  
  37. // on mouse up, trigger the action only if we are enabled and the mouse
  38. // was released inside the view.
  39. /** @private */
  40. mouseUp: function(evt) {
  41. this.setClassName('active', false) ;
  42. this._isMouseDown = false;
  43. var tgt = Event.element(evt) ;
  44. var inside = false ;
  45. while(tgt && (tgt != this.rootElement)) tgt = tgt.parentNode;
  46. if (tgt == this.rootElement) inside = true ;
  47.  
  48. if (inside && this.get('isEnabled')) {
  49. var action = this.get('action');
  50. var target = this.get('target') || null;
  51. if (action) SC.app.sendAction(action, target, this);
  52. }
  53.  
  54. return true ;
  55. }
  56.  
  57. }) ;
Add Comment
Please, Sign In to add comment