Skip to content

Commit beeaeec

Browse files
author
xCss
committed
some update 2019-04-01 14:26
1 parent a0d23d1 commit beeaeec

File tree

7 files changed

+93
-60
lines changed

7 files changed

+93
-60
lines changed

dist/Valine.Pure.min.js

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/Valine.min.js

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/Valine.min.zip

24.8 KB
Binary file not shown.

index.js

+38-20
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ ValineFactory.prototype.init = function (option) {
132132
avatar_cdn,
133133
notify,
134134
verify,
135+
visitor,
135136
pageSize,
136137
recordIP
137138
} = option;
@@ -143,16 +144,16 @@ ValineFactory.prototype.init = function (option) {
143144
root.notify = notify || false;
144145
root.verify = verify || false;
145146

146-
if(recordIP){
147-
let ipScript = Utils.create('script','src','//api.ip.sb/jsonip?callback=getIP');
148-
let s = document.getElementsByTagName("script")[0];
147+
if (recordIP) {
148+
let ipScript = Utils.create('script', 'src', '//api.ip.sb/jsonip?callback=getIP');
149+
let s = document.getElementsByTagName("script")[0];
149150
s.parentNode.insertBefore(ipScript, s);
150151
// 获取IP
151-
window.getIP = function(json){
152+
window.getIP = function (json) {
152153
defaultComment['ip'] = json.ip;
153154
}
154155
}
155-
156+
156157
_avatarSetting['params'] = `?d=${(ds.indexOf(avatar) > -1 ? avatar : 'mp')}&v=${VERSION}${force}`;
157158
_avatarSetting['hide'] = avatar === 'hide' ? true : false;
158159
_avatarSetting['cdn'] = LINKREG.test(avatar_cdn) ? avatar_cdn : _avatarSetting['cdn']
@@ -182,6 +183,9 @@ ValineFactory.prototype.init = function (option) {
182183
}
183184
let id = option.app_id || option.appId;
184185
let key = option.app_key || option.appKey;
186+
if (!id || !key) throw 99;
187+
AV.applicationId && delete AV._config.applicationId || (AV.applicationId = null);
188+
AV.applicationKey && delete AV._config.applicationKey || (AV.applicationKey = null);
185189
AV.init({
186190
appId: id,
187191
appKey: key
@@ -204,7 +208,7 @@ ValineFactory.prototype.init = function (option) {
204208
}
205209

206210
// Counter
207-
option.visitor && CounterFactory.add(AV.Object.extend('Counter'));
211+
visitor && CounterFactory.add(AV.Object.extend('Counter'));
208212

209213
let el = option.el || null;
210214
let _el = Utils.findAll(document, el);
@@ -504,12 +508,14 @@ ValineFactory.prototype.bind = function (option) {
504508
}
505509
root.preview = {
506510
show() {
507-
root.emoji.hide();
508-
Utils.attr(_vpreviewCtrl, 'v', 1);
509-
Utils.removeAttr(_emojiCtrl, 'v');
510-
_vpreview.innerHTML = defaultComment['comment'];
511-
Utils.attr(_vpreview, 'style', 'display:block');
512-
_activeMathJax()
511+
if (defaultComment['comment']) {
512+
root.emoji.hide();
513+
Utils.attr(_vpreviewCtrl, 'v', 1);
514+
Utils.removeAttr(_emojiCtrl, 'v');
515+
_vpreview.innerHTML = defaultComment['comment'];
516+
Utils.attr(_vpreview, 'style', 'display:block');
517+
_activeOtherFn()
518+
}
513519
return root.preview
514520
},
515521
hide() {
@@ -725,7 +731,7 @@ ValineFactory.prototype.bind = function (option) {
725731
let _as = Utils.findAll(_vcard, 'a');
726732
for (let i = 0, len = _as.length; i < len; i++) {
727733
let _a = _as[i];
728-
if (_a && (Utils.attr(_a, 'data-at') || '').indexOf('at') == -1) {
734+
if (_a && (Utils.attr(_a, 'class') || '').indexOf('at') == -1) {
729735
Utils.attr(_a, {
730736
'target': '_blank',
731737
'rel': 'nofollow'
@@ -737,18 +743,30 @@ ValineFactory.prototype.bind = function (option) {
737743
else node.insertBefore(_vcard, _vlis[0]);
738744
let _vcontent = Utils.find(_vcard, '.vcontent');
739745
if (_vcontent) expandEvt(_vcontent);
740-
if (_vat) bindAtEvt(_vat,rt);
741-
_activeMathJax()
746+
if (_vat) bindAtEvt(_vat, rt);
747+
_activeOtherFn()
742748
}
743749

744750

745-
let _activeMathJax = () => {
751+
let _activeOtherFn = () => {
746752
setTimeout(function () {
747-
let MathJax = MathJax || '';
748-
MathJax && MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
753+
try {
754+
let MathJax = MathJax || '';
755+
MathJax && MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
756+
$('pre code').each(function (i, block) {
757+
hljs.highlightBlock(block);
758+
})
759+
$('code.hljs').each(function (i, block) {
760+
hljs.lineNumbersBlock(block);
761+
});
762+
} catch (error) {
763+
764+
}
749765
}, 20)
750766
}
751767

768+
let _activeHLJS = () => {}
769+
752770
// expand event
753771
let expandEvt = (el) => {
754772
setTimeout(function () {
@@ -763,7 +781,7 @@ ValineFactory.prototype.bind = function (option) {
763781

764782
let atData = {}
765783
// at event
766-
let bindAtEvt = (el,rt) => {
784+
let bindAtEvt = (el, rt) => {
767785
Utils.on('click', el, (e) => {
768786
let at = `@${Utils.escape(rt.get('nick'))}`;
769787
atData = {
@@ -848,7 +866,7 @@ ValineFactory.prototype.bind = function (option) {
848866
let pid = atData['pid'] || atData['rid'];
849867
comment.set('rid', atData['rid']);
850868
comment.set('pid', pid);
851-
defaultComment['comment'] = defaultComment['comment'].replace('<p>',`<p><a href="#${pid}">${atData['at']}</a> , `);
869+
defaultComment['comment'] = defaultComment['comment'].replace('<p>', `<p><a class="at" href="#${pid}">${atData['at']}</a> , `);
852870
}
853871
for (let i in defaultComment) {
854872
if (defaultComment.hasOwnProperty(i)) {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "valine",
3-
"version": "1.3.5",
3+
"version": "1.3.6",
44
"description": "A simple comment system based on Leancloud.",
55
"main": "/dist/Valine.min.js",
66
"author": "xCss <[email protected]> (https://github.com/xCss)",

utils/htmlUtils.js

+44-31
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ const reHasEscapedHtml = RegExp(reEscapedHtml.source)
2020

2121
const utils = {
2222
on(type, el, handler, capture) {
23-
type=type.split(' ')
24-
for(let i=0,len=type.length;i<len;i++){
25-
utils.off(type[i],el,handler,capture)
23+
type = type.split(' ')
24+
for (let i = 0, len = type.length; i < len; i++) {
25+
utils.off(type[i], el, handler, capture)
2626
if (el.addEventListener) el.addEventListener(type[i], handler, capture || false);
2727
else if (el.attachEvent) el.attachEvent(`on${type[i]}`, handler);
2828
else el[`on${type[i]}`] = handler;
@@ -51,9 +51,9 @@ const utils = {
5151
* @param {Object} attrName
5252
* @param {Object} attrVal
5353
*/
54-
create(name,attrName,attrVal){
54+
create(name, attrName, attrVal) {
5555
let el = document.createElement(name)
56-
utils.attr(el,attrName,attrVal)
56+
utils.attr(el, attrName, attrVal)
5757
return el
5858
},
5959
/**
@@ -85,11 +85,11 @@ const utils = {
8585
if (value !== undefined) {
8686
if (value === null) utils.removeAttr(el, name)
8787
else el.setAttribute(name, value)
88-
}else if(({}).toString.call(name) === '[object Object]' ){
89-
utils.each(name,(k,v)=>{
90-
el.setAttribute(k,v)
88+
} else if (({}).toString.call(name) === '[object Object]') {
89+
utils.each(name, (k, v) => {
90+
el.setAttribute(k, v)
9191
})
92-
}else return el.getAttribute(name)
92+
} else return el.getAttribute(name)
9393
},
9494
/**
9595
* get prop or set prop
@@ -98,13 +98,13 @@ const utils = {
9898
* @param {String} value
9999
*/
100100
prop(el, name, value) {
101-
if(value !== undefined){
101+
if (value !== undefined) {
102102
return el[name] = value
103-
}else if(({}).toString.call(name) === '[object Object]' ){
104-
utils.each(name,(k,v)=>{
103+
} else if (({}).toString.call(name) === '[object Object]') {
104+
utils.each(name, (k, v) => {
105105
el[k] = v
106106
})
107-
}else return el[name]
107+
} else return el[name]
108108
},
109109
/**
110110
* Remove el attribute
@@ -129,23 +129,37 @@ const utils = {
129129
* Clear element attributes
130130
* @param {HTMLElement} el
131131
*/
132-
clearAttr(el){
132+
clearAttr(el) {
133133
let attrs = el.attributes
134-
let ignoreAttrs = ['align','alt','disabled','href','id','target','title','type','src']
135-
utils.each(attrs,(idx,attr)=>{
134+
let ignoreAttrs = ['align', 'alt', 'disabled', 'href', 'id', 'target', 'title', 'type', 'src', 'class', 'style']
135+
utils.each(attrs, (idx, attr) => {
136136
let name = attr.name
137-
if('style' === name){
138-
let style = attr.value
139-
utils.each(style.split(';'),(idx,item)=>{
140-
if(item.indexOf('color') > -1) {
141-
utils.attr(el,'style',item);
137+
switch (attr.name.toLowerCase()) {
138+
case 'style':
139+
let style = attr.value
140+
utils.each(style.split(';'), (idx, item) => {
141+
if (item.indexOf('color') > -1) {
142+
utils.attr(el, 'style', item);
143+
return false
144+
} else utils.removeAttr(el, 'style');
145+
})
146+
break;
147+
case 'class':
148+
if (el.nodeName == 'CODE') return false
149+
let clazz = attr.value
150+
if (clazz.indexOf('at') > -1) {
151+
utils.attr(el, 'class', 'at');
142152
return false
143-
}else utils.removeAttr(el,'style');
144-
})
153+
}
154+
break;
155+
default:
156+
// utils.removeAttr(el,'class');
157+
break;
158+
145159
}
146160

147-
if(ignoreAttrs.indexOf(name)>-1) return
148-
else utils.removeAttr(el,name)
161+
if (ignoreAttrs.indexOf(name) > -1) return
162+
else utils.removeAttr(el, name)
149163
})
150164
return el
151165
},
@@ -155,9 +169,8 @@ const utils = {
155169
*/
156170
remove(child) {
157171
try {
158-
if(child.parentNode) child.parentNode.removeChild(child)
159-
} catch (error) {
160-
}
172+
if (child.parentNode) child.parentNode.removeChild(child)
173+
} catch (error) {}
161174
},
162175

163176
/**
@@ -171,17 +184,17 @@ const utils = {
171184
let value,
172185
i = 0,
173186
length = collection.length,
174-
likeArray = ["[object Array]","[object NodeList]"],
187+
likeArray = ["[object Array]", "[object NodeList]"],
175188
type = ({}).toString.call(collection)
176189
if (likeArray.indexOf(type) > -1) {
177190
for (; i < length; i++) {
178-
value = callback && callback.call(collection[i],i, collection[i])
191+
value = callback && callback.call(collection[i], i, collection[i])
179192
if (value === false) break
180193
}
181194
} else {
182195
for (i in collection) {
183196
if (collection.hasOwnProperty(i)) {
184-
value = callback && callback.call(collection[i],i, collection[i])
197+
value = callback && callback.call(collection[i], i, collection[i])
185198
if (value === false) break
186199
}
187200
}

webpack.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const plugins = [];
1111
const banner =
1212
'Valine v' + version + '\n' +
1313
'(c) 2017-' + new Date().getFullYear() + ' xCss\n' +
14-
'Released under the GPL-2.0 License.' +
15-
'Update: ' + new Date();
14+
'Released under the GPL-2.0 License.\n' +
15+
'Last Update: ' + (new Date()).toLocaleString();
1616

1717
const TARGET = process.env
1818
if(TARGET.NODE_ENV == 'production'){

0 commit comments

Comments
 (0)