pay.js 1.87 KB
/**
 * 支付页面
 * @author: 赵彪<bill.zhao@yoho.cn>
 * @date: 2015/12/03
 */
var loading = require('../plugin/loading');

function isWXOpen() {
    var ua = navigator.userAgent.toLowerCase();

    if (ua.match(/MicroMessenger/i) === 'micromessenger') {
        return true;
    } else {
        return false;
    }
}

function hideWeChatPay() {
    var payApps = document.getElementsByClassName('app');

    [].forEach.call(payApps, function(app, index) {
        if (app.innerHTML.indexOf('微信') !== -1) {
            app.parentNode.style.display = 'none';
            return false;
        }
    });
}

function handleForWX() {
    if (!isWXOpen()) {
        hideWeChatPay();
    }
}

function setIcon(div, appName) {

    if (appName.indexOf('百度') !== -1) {
        div.style.backgroundPositionY = '-2.7rem';
        return false;
    }

    if (appName.indexOf('微信') !== -1) {
        div.style.backgroundPositionY = '-1.2rem';
        return false;
    }

    if (appName.indexOf('银联') !== -1) {
        div.style.backgroundPositionY = '-4rem';
        return false;
    }

    if (appName.indexOf('QQ') !== -1) {
        div.style.backgroundPositionY = '-5.4rem';
        return false;
    }
}

function loadIcon() {
    var boxs = document.getElementsByClassName('box');
    var div = null;
    var appName = null;

    [].forEach.call(boxs, function(box, index) {
        div = box.getElementsByClassName('icon')[0].getElementsByTagName('div')[0];
        if (div) {
            appName = box.getElementsByClassName('app')[0].innerHTML;
            setIcon(div, appName);
        }
    });
}

function showPage() {
    var pageList = document.getElementsByClassName('payapp-list')[0];

    pageList.style.visibility = 'visible';
}

function main() {
    handleForWX();
    loading.hideLoadingMask();
    showPage();
    loadIcon();
}

loading.showLoadingMask();

window.onload = main;