comment.js 1.72 KB
/**
 * 退换货申请
 * @author: yyqing<yanqing.yang@yoho.cn>
 * @date: 2016/3/1
 */
var $ = require('yoho.jquery');

var $comment = $('.comment-table'),
    $remarkBtn = $comment.find('.remark-btn');

var $dialog = $('#comment-dialog-widget'),
    $titleBar = $dialog.find('.dialog-titlebar'),
    $commentArea = $dialog.find('textarea'),
    $closeBtn = $dialog.find('.dialog-close-btn');

var pageW = $(document).width(),
    pageH = $(document).height(),
    winH = $(window).height();

var dialog = {
    padding: 12,
    canmove: false,
    offset: {},
    maxtop: 0,
    maxleft: 0
};

$remarkBtn.click(function() {
    var scrollTop = $(document).scrollTop();

    $commentArea.val('');
    $dialog.removeClass('hide').css({
        top: scrollTop + (winH - $dialog.height() - dialog.padding) / 2,
        left: (pageW - $dialog.width() - dialog.padding) / 2
    });
});

// 评论弹窗
$titleBar.bind('mousedown', function(e) {
    if ($(e.target).hasClass('dialog-close-btn')) {
        return;
    }

    dialog.canmove = true;
    dialog.offset = {
        x: e.offsetX,
        y: e.offsetY
    };
    dialog.maxtop = pageH - $dialog.height() - dialog.padding;
    dialog.maxleft = pageW - $dialog.width() - dialog.padding;
});

$(document).mousemove(function(e) {
    var mtop, mleft;

    if (!dialog.canmove) {
        return;
    }

    mtop = e.pageY - dialog.offset.y;
    mleft = e.pageX - dialog.offset.x;
    mtop = mtop < dialog.maxtop ? mtop : dialog.maxtop;
    mleft = mleft < dialog.maxleft ? mleft : dialog.maxleft;
    $dialog.css({
        top: mtop > 0 ? mtop : 0,
        left: mleft > 0 ? mleft : 0
    });
}).mouseup(function(e) {
    dialog.canmove = false;
});

$closeBtn.click(function() {
    $dialog.addClass('hide');
});