ginebra2/chrome/js/SimpleButton.js
branchGCC_SURGE
changeset 8 2e16851ffecd
parent 5 0f2326c2a325
equal deleted inserted replaced
2:bf4420e9fa4d 8:2e16851ffecd
     1 // Call SimpleButton to wire an HTML button (typically an <img> tag) to a JS callback
     1 // Call SimpleButton to wire an HTML button (typically an <img> tag) to a JS callback
     2 // 
     2 //
     3 // (As opposed to ActionButton which is served all the way through QT Actions)
     3 // (As opposed to ActionButton which is served all the way through QT Actions)
     4 //
     4 //
     5 // Params:
     5 // Params:
     6 //   id - the id of the button.  Ex:  <img id="buttonId" .../>
     6 //   id - the id of the button.  Ex:  <img id="buttonId" .../>
     7 //   upImg - the path to the "up" image for the button.
     7 //   upImg - the path to the "up" image for the button.
    72 // and mouse up seem to cancel the onclick.
    72 // and mouse up seem to cancel the onclick.
    73 //    this.onClick = function() {
    73 //    this.onClick = function() {
    74 //        //window.chrome.alert("SimpleButton::onClick: " + this);
    74 //        //window.chrome.alert("SimpleButton::onClick: " + this);
    75 //        this.handler();
    75 //        this.handler();
    76 //    }
    76 //    }
    77     
    77 
    78     this.onMouseDown = function() {
    78     this.onMouseDown = function() {
    79         this.isDown = true;
    79         this.isDown = true;
    80         this.updateButton.call(this);
    80         this.updateButton.call(this);
    81         if (this.triggerOnMouseDown && this.enabled) {
    81         if (this.triggerOnMouseDown && this.enabled) {
    82             this.handler();
    82             this.handler();
    83         }
    83         }
    84     }
    84     }
    85     
    85 
    86     this.onMouseUp = function() {
    86     this.onMouseUp = function() {
    87         this.isDown = false;
    87         this.isDown = false;
    88         this.updateButton.call(this);
    88         this.updateButton.call(this);
    89         if (this.triggerOnMouseUp && this.enabled) {
    89         if (this.triggerOnMouseUp && this.enabled) {
    90             this.handler();
    90             this.handler();
    93 
    93 
    94     this.onMouseOut = function() {
    94     this.onMouseOut = function() {
    95         if (this.isDown) {
    95         if (this.isDown) {
    96             this.isDown = false;
    96             this.isDown = false;
    97             this.updateButton.call(this);
    97             this.updateButton.call(this);
    98             
    98 
    99             if (this.triggerOnMouseOut && this.enabled) {
    99             if (this.triggerOnMouseOut && this.enabled) {
   100                 this.handler();
   100                 this.handler();
   101             }
   101             }
   102         }
   102         }
   103     }
   103     }
   104  
   104 
   105     // Set up element event handlers.
   105     // Set up element event handlers.
   106     this.element().onmousedown = this.onMouseDown.bind(this);
   106     this.element().onmousedown = this.onMouseDown.bind(this);
   107     this.element().onmouseup = this.onMouseUp.bind(this);
   107     this.element().onmouseup = this.onMouseUp.bind(this);
   108     this.element().onmouseout = this.onMouseOut.bind(this);
   108     this.element().onmouseout = this.onMouseOut.bind(this);
   109 //    this.element().onclick = this.onClick.bind(this);
   109 //    this.element().onclick = this.onClick.bind(this);