comment.js
1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
/**
* 退换货申请
* @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');
});