Blame view

web-static/js/footer.js 4.53 KB
whb authored
1 2 3 4 5 6 7 8
/**
 * 尾部
 * @author: wangqing<robin.wang@yoho.cn>
 * @date: 2015/12/01
 */

var $ = require('yoho.jquery');
9 10
var $returnTop = $('.return-top');
whb authored
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/**
 * 订阅
 * @return {[type]} [description]
 */
function actionSubscription() {
    var $subscriberBox = $('#subscriber-box'),
        $subscriberBtn = $('#subscriber-btn'),
        emailReg = /^[.\-_a-zA-Z0-9]+@[\-_a-zA-Z0-9]+\.[a-zA-Z0-9]/;

    var iconCode = {
        mail: '&#xe61b;',
        tick: '&#xe61a'
    };

    $subscriberBox.focus(function() {
        $(this).val('').css('color', '');
        $subscriberBtn.removeClass('done').html(iconCode.mail);
    });

    $subscriberBtn.click(function() {
xuqi authored
31 32
        var email = $.trim($subscriberBox.val());
whb authored
33 34
        if (email !== '' && emailReg.test(email)) {
            try {
xuqi authored
35
                $.ajax({
whb authored
36
                    url: 'http://www.yohobuy.com/common/emailSubscriber',
xuqi authored
37 38 39 40 41 42 43 44 45 46 47 48 49
                    dataType: 'jsonp',
                    data: {
                        email: email,
                        tmp: Math.random(),
                        uid: window.getUid()
                    },
                    success: function(data) {
                        if (data.data.result === 1) {
                            $subscriberBox.val('已订阅到:' + email);
                            $subscriberBtn.addClass('done').html(iconCode.tick);
                        } else {
                            $subscriberBox.css('color', 'red');
                        }
whb authored
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
                    }
                });
            } catch (e) {
                console.log(e.message);
            }
        } else {
            $subscriberBox.css('color', 'red');
        }
    });
}

function actionhomeFootChange() {
    var $vote = $('.vote'),
        $feedBackPage = $('#feed-back-page'),
        count = $vote.children('li').length;

    //意见反馈
    $feedBackPage.on('click', 'span', function() {
        var $this = $(this);

        if ($this.hasClass('cur')) {
            return;
        }

        $this.siblings('.cur').removeClass('cur');
        $this.addClass('cur');

        $vote.children().not('.hide').addClass('hide')
            .end()
            .eq($this.index()).removeClass('hide');
    });

    $vote.on('click', '.feed-back-btn', function() {
        var $this = $(this),
            $li = $this.closest('li'),
            index = $li.index(),
            _solution = [];

        var _answer = $li.find('.feedback-answer').val(),
            _feedback = $li.find('.feedback-id').val(),
            _question = $li.find('.question-id').val();

        $li.find(':checked').each(function() {
            _solution.push($(this).val());
        });
xuqi authored
96
        $.ajax({
whb authored
97
            url: 'http://www.yohobuy.com/common/suggestFeedback',
xuqi authored
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
            dataType: 'jsonp',
            data: {
                feedback_id: _feedback || 0,
                question_id: _question || 0,
                answer: _answer || '',
                solution: _solution.join(',')
            },
            success: function(data) {
                var next = index + 1;

                if (~~data.data.result === 1) {
                    if (index === count - 1) {
                        alert('感谢您的参与!');
                        return;
                    }
whb authored
113
xuqi authored
114
                    $li.addClass('hide');
whb authored
115
xuqi authored
116 117 118 119
                    $vote.children(':eq(' + (index + 1) + ')').removeClass('hide');
                    $feedBackPage.children('.cur').removeClass('cur');
                    $feedBackPage.children(':eq(' + next + ')').addClass('cur');
                }
whb authored
120 121 122 123 124
            }
        });
    });
}
125
function rePosReturn() {
126
    if ($(window).height() > $(document).height()) {
127 128
        $returnTop.addClass('hide');
    }
129 130 131 132 133

    // 只在窗口高度大于文档高度的时候,隐藏返回顶部
    // else {
    //     $returnTop.removeClass('hide');
    // }
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
}

//返回顶部
$returnTop.click(function() {
    $('html,body').animate({
        scrollTop: 0
    }, 500);
});

$(window).scroll(function() {
    if ($(window).scrollTop() === 0) {
        $returnTop.addClass('hide');
    } else {
        $returnTop.removeClass('hide');
    }
});

//如果初始是隐藏的,监听图片加载,重新确定return-top的高度
if ($returnTop.hasClass('hide')) {
    $('img').load(rePosReturn);
}
whb authored
156 157 158
//初始化
actionSubscription();
actionhomeFootChange();
159 160

//暴露给有可能通AJAX改变内容的页面去用
161
window.rePosReturnTop = rePosReturn;