Skip to content

mahsumurebe/mx-timer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MXTimer

Timer Plugin for JavaScript

1. Installation MXTimer

  1. Download files !

  2. Add the code inside the body tag.

    <script src="mx-timer.js"></script>
    
  3. Start coding freely :)

2. Examples

  1. Easily create timers.

    var myTimer = new Timer({
        func: function () {
            console.log('is timer function');
        },
        interval: 1000, // interval 1 second.
        autoStart: true // Automatic start timer.
    });
    
  2. Define events within options.

    var myTimer = new Timer({
        func: function () {
            console.log('is timer function');
        },
        interval: 2000, // interval 2 second.
        autoStart: true, // Automatic start timer.
        initializer: function () {
            console.log('On initialize timer.'); // This function calls the timer constructor.
        },
        onafterstart: function () {
            console.log('After start timer.'); // This function is executed every time after the timer runs.
        },
        onstart: function () {
            console.log('Start timer.'); // This function is executed every time the timer runs.
        },
        onafterstop: function () {
            console.log('After stop timer.'); // This function is executed after it has been stopped in time.
        },
        onstop: function () {
            console.log('Stop timer.'); // This function is executed when the timer is stopped.
        },
        callback: function () {
            console.log('Callback timer.'); // Callback function
        }
    });
    
  3. Define events after create timer.

    var myTimer = new Timer({
        func: function () {
            console.log('is timer function');
        },
        interval: 2000, // interval 2 second.
        autoStart: true, // Automatic start timer.
    });
    myTimer.on('start', function ($this) {
        console.log('Starting');
    }).on('stop', function () {
        console.log('stopping');
    });
    

3. Options

Option Name Type Details
func function Function to be called
interval int Interval in miliseconds. (1s = 1000 ms)
group_name string If you want to group the timer, enter the group name. Note: The _global group name is used by the plugin.
autoStart boolean Auto start timer.
initializer function This function calls the timer constructor.
onafterstart function|function[] This function is executed every time after the timer runs.
onstart function|function[] This function is executed every time the timer runs.
onafterstop function|function[] This function is executed after it has been stopped in time.
onstop function|function[] This function is executed when the timer is stopped.
callback function|function[] Callback function

4. Methods

Method Name Return Type Details

Timer

Timer.getCount int The number of times the timer works
Timer.isStarted boolean Timer is started ?
Timer.trigger Timer Trigger timer events.
Timer.on Timer Binding events.
Timer.start Timer Start timer.
Timer.reset Timer Reset timer. Like Timer.stop(true).start();
Timer.stop Timer Stop timer.

XMTimer

MXTimer.add({/* Options */}) Timer Adding timer.
MXTimer.remove(_/** Optional */_'group_name') MXTimer Remove timer by group name. Note: If no group name is sent, removes all timers.
MXTimer.stop(_/** Optional */_'group_name') Timer Stop timer by group name. Note: If no group name is sent, stopped all timers.
MXTimer.getByGroupName('group_name') Timer Get timers by group name.
MXTimer.info(_/** Optional */_'group_name') Timer Timer information by group name. Note: If the group name is not sent, it returns information for all timers.

5. Events

Event Name Details
onafterstart This function is executed every time after the timer runs.
onstart This function is executed every time the timer runs.
onafterstop This function is executed after it has been stopped in time.
onstop This function is executed when the timer is stopped.

6. Errors

Error Class Details
Invalid argument was sent for adding timer. TimerInvalidAddArgs If a value other than object type is entered while adding the timer, you will get this error message. You can get help from the examples above when adding timers.
Timer function not defined correctly. TimerIsNotFunction The timer has to be defined as a function. The reason for encountering this error is to define a real function.
Invalid Interval value. Interval to be bigger than zero. TimerInvalidAddArgs Timer interval must be greater than zero.

About

Timer Plugin for JavaScript

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published