footer.js 1.63 KB
/**
 * 底部JS
 * @author: liangzhifeng<zhifeng.liang@yoho.cn>
 * @date: 2015/10/26
 */

var $ = require('yoho-jquery'),
    Hammer = require('yoho-hammer');

var floatLayerBtnHammer;

require('../common');

/**
 * 获取url参数
 */
function getQueryString(name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
    var r = window.location.search.substr(1).match(reg);

    if (r != null) {
        return window.unescape(r[2]);
    }
    return null;
}

function downLoadApp() {
    var appUrl = 'http://www.yohoshow.com/about/index/yohobuyqr/';
    var clickedAt = new Date();

    setTimeout(function() {
        var mkt = getQueryString('mkt_code');

        if ((new Date()) - clickedAt < 2000) {
            if (mkt) {
                appUrl += '?union_type=' + mkt;
            }
            window.location = appUrl;
        }
    }, 500);
}

$('#float-layer-close').on('touchend', function(e) {
    $('#float-layer-app').hide();
    window.setCookie('_float-layer-app', 'id490655927',
        {
            domain: '.yohobuy.com'
        });
    window.setCookie('_float-layer-app-close', 1,
        {
            domain: '.yohobuy.com',
            expires: 1
        });
    return false;
});

if ($('#float-layer-btn') && $('#float-layer-btn')[0]) {
    floatLayerBtnHammer = new Hammer($('#float-layer-btn')[0]);
    floatLayerBtnHammer.on('tap', function(e) {
        downLoadApp('bottom');
        e.srcEvent.stopPropagation();
    });

    // if (typeof window.cookie === 'function' && !window.cookie('_float-layer-app')) {
    //     $('#float-layer-app').show();
    // } else {
    //     $('#float-layer-app').hide();
    // }
}