common.js 1.73 KB
/*
 * @description: common js
 * @author: lore-w
 * @date: 2015-4-23
 */

var $ = require('jquery'),
    swiper = require('swiper-mobile');

    require('jgestures');

// 初始化页面
exports.init = function () {

    // nav
    var navSwiper = new swiper('.girl-nav',{
        grabCursor: true,
        slidesPerView: 'auto',
        slideElement: 'li',
        hashnav: true
    });

    // channel page banner
    var channelSwiper = new swiper('.banner .swiper-container',{
        loop: true,
        pagination: '.pagination',
        grabCursor: true,
        paginationClickable: true,
        autoplay: 5000,
        slideElement: 'li'
    });

    // download app
    var downBtn = $('.home-download').find('.down-btn');

    if (downBtn.length > 0) {
        if (getDeviceType().isIphone) {
            downBtn.each(function (index) {
                $(this).attr('href', $(this).attr('data-ios'));
            });
        }

        if (getDeviceType().isAndroid) {
            downBtn.each(function (index) {
                $(this).attr('href', $(this).attr('data-android'));
            });
        }
    }

    // back to top
    $('.come-back').bind('tapone',function () {
        $('body').animate({scrollTop: 0});
    });

};

/*
 * @description: 获取设备类型
 * @param: none
 * @return: JSON
*/
function getDeviceType () {

    var sUserAgent = navigator.userAgent.toLowerCase(),

        bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os",
        bIsAndroid = sUserAgent.match(/android/i) == "android",
        bIsWeixin = sUserAgent.match(/MicroMessenger/i) == 'micromessenger';

    return {
        isIphone: bIsIphoneOs,
        isAndroid: bIsAndroid,
        isWeixin: bIsWeixin
    }
}

exports.getDeviceType = getDeviceType;