spread.page.js
3.06 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
* 我的推广
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2017/6/22
*/
var $ = require('yoho-jquery');
var Clipboard = require('clipboard'),
Dialog = require('../common/dialog').Dialog;
var trendWordTpl = require('../../hbs/home/spread/trend-word.hbs');
var $spreadWord = $('.spread-id'),
$editBtn = $('.edit-word'),
$copySuccTip = $('.succ-tip'),
$qrcodeImg = $('.spread-code');
var reasonHtml = $('.trend-word-tpl').html();
var clipboard;
var defaultWord = $spreadWord.data('word');
require('../common');
require('yoho-jquery-qrcode');
function reseatWordSize(word) {
if (!word) {
return;
}
$spreadWord.css('font-size', 22 + parseInt((14 - word.length) / 7, 10) * 4);
}
function saveTrendWord(dg) {
var that = this;
var $errTip = dg.$el.find('.err-tip');
var word = $.trim(dg.$el.find('.trend-word-input').val());
if (this.saving) {
return;
}
if (!word) {
$errTip.html('请输入潮流口令');
return;
}
this.saving = true;
$.ajax({
url: '/home/spread/updateword',
type: 'POST',
data: {word: word}
}).done(function(data) {
if (data.code === 200) {
$spreadWord.text(word);
defaultWord = word;
reseatWordSize(defaultWord);
dg.close && dg.close();
} else {
$errTip.html(data.message || '网络异常,请稍后重试');
}
}).fail(function() {
$errTip.html('网络异常,请稍后重试');
}).always(function() {
that.saving = false;
});
}
// 生成二维码
$qrcodeImg.qrcode({
render: 'div', // 显示方式,canvas,image和div
text: $qrcodeImg.data('url'), // 二维码的内容
size: parseInt($qrcodeImg.width(), 10) // 大小
});
clipboard = new Clipboard('.copy-url', {
text: function(trigger) {
return trigger.value;
}
});
clipboard.on('success', function() {
$copySuccTip.show();
setTimeout(function() {
$copySuccTip.fadeOut();
}, 2000);
});
$editBtn.on('click', function(e) {
var _d = new Dialog({
content: trendWordTpl({
img: $spreadWord.data('img'),
word: defaultWord,
content: reasonHtml
}),
className: 'edit-trendword-dialog',
btns: [
{
id: 'trend-edit-cancel',
btnClass: ['trend-edit-cancel'],
name: '暂不',
cb: function() {
if (e.isTrigger && !window.cookie('no_cue_trendword')) {
window.setCookie('no_cue_trendword', 1, {expires: 30});
}
_d.close();
}
},
{
id: 'trend-edit-sure',
btnClass: ['trend-edit-sure'],
name: '设置',
cb: function() {
saveTrendWord(_d);
}
}
]
}).show();
});
reseatWordSize(defaultWord);
if (!defaultWord && !window.cookie('no_cue_trendword')) {
$editBtn.trigger('click');
}