utility.js 917 Bytes
var blinkInterval;
var docTitle = document.title;

/**
 * 检查是否支持 websocket
 * @returns {boolean}
 */
exports.isSupport = function() {
    return !!window.WebSocket;
};

/**
 * 添加闪烁提醒
 * @returns {boolean}
 */
exports.addBlinkAlert = function() {
    if (blinkInterval) {
        clearInterval(blinkInterval);
    }

    blinkInterval = setInterval(function() {
        document.title = '您有新消息';
        setTimeout(function() {
            document.title = docTitle;
        }, 300);
    }, 600);
};

/**
 * 去除闪烁提醒
 * @returns {boolean}
 */
exports.removeBlinkAlert = function() {
    if (blinkInterval) {
        clearInterval(blinkInterval);
        document.title = docTitle;
    }
};

/**
 * 链接自适应协议
 * @author: lq <qi.li@yoho.cn>
 * @date: 2017/04/06
 */

exports.autoProtocol = function(src) {
    return (src || '').replace(/^(http:|https:)/, '');
};