Module: UWA/Class/Timed

UWA/Class/Timed

Classes implementing or extending this Class will have extra methods to handle delayed, animated and periodical events.

Example

define('MyProject/Class/MyAnime', [
    'UWA/Class',
    'UWA/Class/Timed',
], function (Class, Timed) {

     var MyAnime = Class.extend(Timed, {

          init: function (element, start, stop) {

               this.current = null;
               this.start = start;
               this.stop = stop;
               this.element = element;
           },

           run: function () {
               this.setAnimate('myAnimation', this.animate);
           },

           stop: function () {
               this.clearAnimate('myAnimation');
           },

           isRuning: function () {
               return this.hasAnimate('myAnimation');
           },

           animate: function () {

               var element = this.element;

               if (this.current === null) {
                   this.current = this.start;
               }

               UWA.Element.setStyle.call(element, 'top', this.current++);

               if (this.current <= this.stop) {
                   this.setAnimate('myAnimation', this.animate);
               }
          }
    });

    return MyAnime;
});

require(['MyProject/Class/MyAnime'], function (MyAnime) {

    var myAnime = new MyAnime(widget.body, 1, 300);

    myAnime.run();
});

Index

Methods

<inner> setPeriodical(name, fn, delay, force, bind) → {this}

Register a function as periodical event.

Parameters
Name Type Description
name String

The name of the periodical event

fn Function

The function to register

delay Number

The execution delay in milliseconds

force Boolean

If true, fire the function for the time right now

bind Object

The context to pass to the function, current instance by default.

Returns
Type
this

<inner> clearPeriodical(name) → {this}

Unregister a periodical event previously registered with <setPeriodical>. If the name is specified, it removes the associated periodical event. Else, it removes all periodicals events.

Parameters
Name Type Description
name String

the name of the event

Returns
Type
this

<inner> hasPeriodical(name) → {Boolean}

Check if a periodical event is registered.

Parameters
Name Type Description
name String

The name of the periodical event

Returns

true If a periodical event is registered.

Type
Boolean

<inner> setDelayed(name, fn, delay, force, bind) → {this}

Registers a function as delayed event.

Parameters
Name Type Description
name String

The name of the delayed event

fn Function

The function to register

delay Number

The delay in milliseconds

force Boolean

If true, fire the function for the time right now

bind Object

The context to pass to the function, current instance by default.

Returns
Type
this

<inner> clearDelayed(name) → {this}

Unregister a delayed event previously registered with <setDelayed>. If the name is specified, it removes the associated periodical event. Else, it removes all periodicals events.

Parameters
Name Type Description
name String

The name of the delayed event

Returns
Type
this

<inner> hasDelayed(name) → {Boolean}

Check if a delayed event is registered.

Parameters
Name Type Description
name String

The name of the delayed event

Returns

true If a delayed event is registered.

Type
Boolean

<inner> setAnimate(name, fn, bind) → {this}

Register a function as frame animation event.

Use requestAnimationFrame if available else fallback on setTimeout with 16ms delay.

Parameters
Name Type Description
name String

The name of the animation event

fn Function

The function to register

bind Object

The context to pass to the function, current instance by default.

Returns
Type
this

<inner> clearAnimate(name) → {this}

Unregister a frame animation event previously registered with <setAnimate>. If the name is specified, it removes the associated animation event. Else, it removes all animation events.

Parameters
Name Type Description
name String

The name of the event

Returns
Type
this

<inner> hasAnimate(name) → {Boolean}

Check if a animation event is registered.

Parameters
Name Type Description
name String

The name of the animation event

Returns

true If a animation event is registered.

Type
Boolean

<inner> setImmediate(name, fn, bind) → {this}

Register a function as immediate event.

Use setImmediate if available else fallback on setTimeout with ~1ms delay.

Parameters
Name Type Description
name String

The name of the immediate event

fn Function

The function to register

bind Object

The context to pass to the function, current instance by default.

Returns
Type
this

<inner> clearImmediate(name) → {this}

Unregister a immediate event previously registered with <setImmediate>. If the name is specified, it removes the associated immediate event. Else, it removes all immediate events.

Parameters
Name Type Description
name String

The name of the event

Returns
Type
this

<inner> hasImmediate(name) → {Boolean}

Check if a immediate event is registered.

Parameters
Name Type Description
name String

The name of the immediate event

Returns

true If a immediate event is registered.

Type
Boolean

<inner> clearAllTimed() → {this}

Clear all registered 'timed' callback.

Returns
Type
this