のソースコードにgoog.ui.Control
は、次のコメントが含まれています。
すべてのコントロールは、show、hide、mouseover、mouseout、およびuserアクションでそれぞれSHOW、HIDE、ENTER、LEAVE、およびACTIONイベントをディスパッチします。
さまざまなアクションに対してどのイベントがディスパッチされているかを正確に確認するには、ライブイベントログがあるgoog.ui.Controlデモをご覧ください。
追加の遷移イベントを有効にするためにgoog.ui.Control
、次のメソッドを含めます。
/**
* Enables or disables transition events for the given state(s). Controls
* handle state transitions internally by default, and only dispatch state
* transition events if explicitly requested to do so by calling this method.
* @param {number} states Bit mask of {@link goog.ui.Component.State}s for
* which transition events should be enabled or disabled.
* @param {boolean} enable Whether transition events should be enabled.
*/
goog.ui.Control.prototype.setDispatchTransitionEvents = function(states,
enable) {
this.statesWithTransitionEvents_ = enable ?
this.statesWithTransitionEvents_ | states :
this.statesWithTransitionEvents_ & ~states;
};
たとえば、次のようにして、すべての状態の遷移イベントを有効にすることができます。
var myButton = new myapp.MyButton();
myButton.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true);
これで、マウスボタンを押すとactivate
イベントがディスパッチされ、マウスボタンを離すとdeactivate
イベントがディスパッチされます。
goog.ui.Buttonデモ(特に、ページの下部にある組み合わせたトグルボタン)を参照してください。