2012-06-22 3 views
1

Y at-il un moyen de désactiver un dojox.mobile.Switch pour qu'il soit visible mais grisé et non-enclinable? Je ne vois rien dans le document API standard.Y at-il un moyen de désactiver un dojox.mobile.switch?

Édition: Je devrais ajouter que je travaille avec Dojo 1.7.

+0

Avez-vous trouvé une solution pour cela? J'ai résolu le problème grisé en changeant l'opacité du conteneur mais je ne vois pas comment désactiver le contrôle réel – Mike

Répondre

1

Je devais le faire aujourd'hui. J'ai étendu le module Switch. Fonctionne bien pour moi, mais je suis sûr que cela pourrait être amélioré.

define([ 
    "dojo/_base/declare", 
    "dojox/mobile/Switch" 
], function(declare, Switch){ 
    return declare("my.package.Switch", [Switch], { 

     disabled: false, 
     events: {}, 

     disableSwitch: function() { 
      //remove events (but hold on to them for later).. there may be a better dojo way of doing this 
      this.events._onClick = this._onClick; 
      this.events.onClick = this.onClick; 
      this.events.onTouchStart = this.onTouchStart; 
      this.events.onTouchMove = this.onTouchMove; 
      this._onClick = function(){}; 
      this.onClick = function(){}; 
      this.onTouchStart = function(){}; 
      this.onTouchMove = function(){}; 

      //TODO: better styling to make it look disabled? 
      // this.domNode.style.opacity = '0.5'; 
      this.domNode.style['-webkit-filter'] = 'grayscale(1)'; 

      this.disabled = true; 
     }, 

     enableSwitch: function() { 
      //reattach events 
      this._onClick = this.events._onClick; 
      this.onClick = this.events.onClick; 
      this.onTouchStart = this.events.onTouchStart; 
      this.onTouchMove = this.events.onTouchMove; 

      // this.domNode.style.opacity = '1'; 
      this.domNode.style['-webkit-filter'] = 'grayscale(0)'; 

      this.disabled = false; 
     } 
    }); 
}); 
Questions connexes