util.js 1.35 KB
// 通用方法

function getQuery(name) {
    var result = window.location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
    if (result == null || result.length < 1)
        return undefined;
    return decodeURIComponent(result[1]);
}


getCDNFile = function (cdnUrl) {
    var link = cdnUrl.substring(cdnUrl.indexOf('/uploads/'), cdnUrl.indexOf('?'));
    return link;
}

var timer = {
    options: {
        timer: null,
        dom: null
    },
    init: function(dom){
        this.options.dom = dom;
        this.startTimer();
    },
    getTimer: function(){
        var _dom = this.options.dom;
        var t = 1,
            h = 0,
            m = 0,
            s = 1,
            ss = 1;
        return function(){
            if (s > 0 && s % 60 == 0) {
                m += 1;
                s = 0;
            }
            if (m > 0 && m % 60 == 0) {
                h += 1;
                m = 0;
            }
            t = (h < 10 ? '0' + h : h) + ":" + (m < 10 ? '0' + m : m) + ":" + (s < 10 ? '0' + s : s);
            _dom.html(t).val(ss);
            s += 1;
            ss += 1;
        }
    },
    startTimer: function(){
        var _getTimer = this.getTimer();
        this.options.timer = setInterval(_getTimer, 1000);
    },
    stopTimer: function(){
        clearInterval(this.options.timer);
        this.options.timer = null;
    }
}