dojox/widget/AutoRotator.js

  • Provides:

    • dojox.widget.AutoRotator
  • Requires:

    • dojox.widget.Rotator in common
  • dojox.widget.AutoRotator

    • type
      Function
    • chains:
      • dojox.widget.Rotator: (prototype)
      • dojox.widget.Rotator: (call)
    • summary
      Initializes the timer and connect to the rotator.
    • description
      Adds automatic rotating to the dojox.widget.Rotator.  The
      AutoRotator has parameters that control how user input can
      affect the rotator including a suspend when hovering over the
      rotator and pausing when the user manually advances to another
      pane.
    • example
      
      	<div dojoType="dojox.widget.AutoRotator" duration="3000">
      		<div>
      			Pane 1!
      		</div>
      		<div duration="5000">
      			Pane 2 with an overrided duration!
      		</div>
      	</div>
    • source: [view]
         var _t = this;


         // validate the cycles counter
         if(_t.cycles-0 == _t.cycles && _t.cycles > 0){
          // we need to add 1 because we decrement cycles before the animation starts
          _t.cycles++;
         }else{
          _t.cycles = _t.cycles ? -1 : 0;
         }


         // wire up the mouse hover events
         _t._connects = [
          d.connect(_t._domNode, "onmouseover", function(){
           // temporarily suspend the cycling, but don't officially pause
           // it and don't allow suspending if we're transitioning
           if(_t.suspendOnHover && !_t.anim && !_t.wfe){
            var t = _t._endTime,
             n = _t._now();
            _t._suspended = true;
            _t._resetTimer();
            _t._resumeDuration = t > n ? t - n : 0.01;
           }
          }),


          d.connect(_t._domNode, "onmouseout", function(){
           // if we were playing, resume playback unless were in the
           // middle of a transition
           if(_t.suspendOnHover && !_t.anim){
            _t._suspended = false;
            if(_t.playing && !_t.wfe){
             _t.play(true);
            }
           }
          })
         ];


         // everything is ready, so start
         if(_t.autoStart && _t.panes.length > 1){
          // start playing
          _t.play();
         }else{
          // since we're not playing, lets pause
          _t.pause();
         }
  • dojox.widget.AutoRotator.suspendOnHover

    • type
      boolean
    • summary
      Pause the rotator when the mouse hovers over it.
  • dojox.widget.AutoRotator.duration

    • type
      int
    • summary
      The time in milliseconds before transitioning to the next pane.  The
      default value is 4000 (4 seconds).
  • dojox.widget.AutoRotator.autoStart

    • type
      boolean
    • summary
      Starts the timer to transition children upon creation.
  • dojox.widget.AutoRotator.pauseOnManualChange

    • type
      boolean
    • summary
      Pause the rotator when the pane is changed or a controller's next or
      previous buttons are clicked.
  • dojox.widget.AutoRotator.cycles

    • type
      int
    • summary
      Number of cycles before pausing.
  • dojox.widget.AutoRotator.random

    • type
      boolean
    • summary
      Determines if the panes should cycle randomly.
  • dojox.widget.AutoRotator.reverse

    • type
      boolean
    • summary
      Causes the rotator to rotate in reverse order.
  • dojox.widget.AutoRotator.destroy

    • type
      Function
    • source: [view]
         d.forEach(this._connects, d.disconnect);
         this.inherited(arguments);
    • summary
      Disconnect the AutoRotator's events.
  • dojox.widget.AutoRotator.play

    • type
      Function
    • parameters:
      • skipCycleDecrement: (typeof boolean)
      • skipDuration: (typeof boolean)
    • source: [view]
         this.playing = true;
         this._resetTimer();


         // don't decrement the count if we're resuming play
         if(skipCycleDecrement !== true && this.cycles > 0){
          this.cycles--;
         }


         if(this.cycles == 0){
          // we have reached the number of cycles, so pause
          this.pause();
         }else if(!this._suspended){
          this.onUpdate("play");
          // if we haven't been suspended, then grab the duration for this pane and
          // schedule a cycle to be run
          if(skipDuration){
           this._cycle();
          }else{
           var r = (this._resumeDuration || 0)-0,
            u = (r > 0 ? r : (this.panes[this.idx].duration || this.duration))-0;
           // call _cycle() after a duration and pass in false so it isn't manual
           this._resumeDuration = 0;
           this._endTime = this._now() + u;
           this._timer = setTimeout(d.hitch(this, "_cycle", false), u);
          }
         }
    • summary
      Sets the state to &quot;playing&quot; and schedules the next cycle to run.
  • dojox.widget.AutoRotator.pause

    • type
      Function
    • source: [view]
         this.playing = this._suspended = false;
         this.cycles = -1;
         this._resetTimer();


         // notify the controllers we're paused
         this.onUpdate("pause");
    • summary
      Sets the state to &quot;not playing&quot; and clears the cycle timer.
  • dojox.widget.AutoRotator._now

    • type
      Function
    • source: [view]
         return (new Date()).getTime(); /*int*/
    • summary
      Helper function to return the current system time in milliseconds.
    • returns
      int
  • dojox.widget.AutoRotator._resetTimer

    • type
      Function
    • source: [view]
         clearTimeout(this._timer);
    • summary
      Resets the timer used to schedule the next transition.
  • dojox.widget.AutoRotator._cycle

    • type
      Function
    • parameters:
      • manual: (typeof boolean|int)
    • source: [view]
         var _t = this,
          i = _t.idx,
          j;


         if(_t.random){
          // make sure we don't randomly pick the pane we're already on
          do{
           j = Math.floor(Math.random() * _t.panes.length + 1);
          }while(j == i);
         }else{
          j = i + (_t.reverse ? -1 : 1)
         }


         // rotate!
         var def = _t.go(j);


         if(def){
          def.addCallback(function(/*boolean?*/skipDuration){
           _t.onUpdate("cycle");
           if(_t.playing){
            _t.play(false, skipDuration);
           }
          });
         }
    • summary
      Cycles the rotator to the next/previous pane.
  • dojox.widget.AutoRotator.onManualChange

    • type
      Function
    • parameters:
      • action: (typeof string)
    • source: [view]
         this.cycles = -1;


         // obviously we don't want to pause if play was just clicked
         if(action != "play"){
          this._resetTimer();
          if(this.pauseOnManualChange){
           this.pause();
          }
         }


         if(this.playing){
          this.play();
         }
    • summary
      Override the Rotator's onManualChange so we can pause.
  • dojox.widget.AutoRotator.playing

    • summary
  • dojox.widget.AutoRotator._resumeDuration

    • summary
  • dojox.widget.AutoRotator._endTime

    • summary
  • dojox.widget.AutoRotator._timer

    • summary
  • dojox.widget

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary