Blame view

public/js/plugin/rich-tip.js 2.12 KB
郭成尧 authored
1 2 3
/**
 * Created by yoho on 2016/11/22.
 */
lijing authored
4
let $ = require('yoho-jquery');
郭成尧 authored
5
lijing authored
6
let $tip = $('#yoho-order-bg'),
郭成尧 authored
7 8 9
    $tipMsg = $tip.find('.order-tip-msg'),
    $tipBtns = $tip.find('.order-tip-btn-group');
lijing authored
10
let touchCallback,
郭成尧 authored
11 12 13 14 15 16 17 18 19 20 21
    params;

function setCallback(t, p) {
    touchCallback = t;
    params = p;
}

/**
 * 跳转还是消失控制
 */
(function() {
郭成尧 authored
22
    $tip.on('click', function(event) {
ccbikai(👎🏻🍜) authored
23
        if (event.target.tagName === 'SPAN') {
郭成尧 authored
24 25 26 27 28 29 30 31 32 33
            if (touchCallback) {
                touchCallback(params);
            }

            touchCallback = null;
            params = null;

            setTimeout(function() {
                $tip.hide();
            }, 200);
ccbikai(👎🏻🍜) authored
34
        } else if (event.target.tagName === 'A') {
郭成尧 authored
35 36 37 38 39 40 41 42 43 44 45 46 47
            setTimeout(function() {
                $tip.hide();
            }, 200);
        } else {
            $tip.hide();
        }
    });
}());

/**
 * 显示提示
 */
function show(con, btn) {
lijing authored
48
    let content = '',
郭成尧 authored
49 50 51 52 53 54 55 56 57 58
        buttons = '';

    if (con && $.isArray(con)) {
        $.each(con, function(key, value) {
            content += '<p>' + value + '</p>';
        });
    }

    if (btn && $.isArray(btn) && btn.length === 1) {
        if (!btn[0].href) {
ccbikai(👎🏻🍜) authored
59 60 61
            buttons += '<a class="order-tip-btn1 ' + btn[0].class +
                '"><span>' + btn[0].text +
                '</span></a>';
郭成尧 authored
62
        } else {
ccbikai(👎🏻🍜) authored
63 64 65 66
            buttons += '<a href="' + btn[0].href +
                '" class="order-tip-btn1 ' + btn[0].class +
                '">' + btn[0].text +
                '</a>';
郭成尧 authored
67 68 69 70
        }
    }

    if (btn && $.isArray(btn) && btn.length > 1) {
ccbikai(👎🏻🍜) authored
71 72
        $.each(btn, function(key, value) {
            if (!value.href) {
ccbikai(👎🏻🍜) authored
73 74 75
                buttons += '<a class="' + value.class +
                     '"><span>' + value.text +
                     '</span></a>';
ccbikai(👎🏻🍜) authored
76
            } else {
ccbikai(👎🏻🍜) authored
77 78 79 80
                buttons += '<a href="' + value.href +
                     '" class="' + value.class +
                     '">' + value.text +
                     '</a>';
ccbikai(👎🏻🍜) authored
81
            }
郭成尧 authored
82 83
        });
    }
ccbikai(👎🏻🍜) authored
84
郭成尧 authored
85 86 87 88 89 90
    $tipMsg.html(content);
    $tipBtns.html(buttons);
    $tip.show();
}

exports.setCallback = setCallback;
ccbikai(👎🏻🍜) authored
91
exports.show = show;