File size: 869 Bytes
194b4ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

function log(m) {
    console.log(m);
}

String.prototype.format = function() {
    var args = arguments;
    return this.replace(/{(\d+)}/g, function(match, number) {
        return typeof args[number] != 'undefined' ? args[number] : match;
    });
};

document.addEventListener('DOMContentLoaded', function() {

    $.fn.bindClick = function (func, args) {
        if (args) {
            return this.off('click').on('click', function () {
                func.apply(this, args);
            });
        } else {
            return this.off('click').on('click', func);
        }
    };

    $.fn.triggerEvent = function (event) {
        if (! this.length) {
            return this;
        }
        let el = this[0];
        event.split(' ').forEach(function (evt) {
            el.dispatchEvent(new Event(evt.trim()));
        });
        return this;
    };
});