Giter Site home page Giter Site logo

mx-timer's Introduction

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.

mx-timer's People

Contributors

mahsumurebe avatar

Stargazers

Yakup AD avatar Mehmet Emin Gelmedi avatar Hüseyin Deniz avatar Bilal Koçak avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.