加载更多评论(剩余'+(r-10*n)+"/"+r+"条)":"";var l=s.querySelector("#vmore");l&&d.on("click",l,function(t){s.innerHTML="",e(++g)})}t.loading.hide()}).catch(function(e){console.log(e),t.loading.hide()})}();var m=function(e){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=document.createElement("li");r.setAttribute("class","vcard"),r.setAttribute("id",e.id);var i="d41d8cd98f00b204e9800998ecf8427e"==e.get("emailHash")?"9e63c80900d106cbbec5a9f4ea433a3e":e.get("emailHash"),a="https://gravatar.loli.net/avatar/"+i+"?size=80";r.innerHTML='\n \n \\n \\n \\n \\n \\n \\n \\n \\n \\n
\\u5DF2\\u6709 0 \\u6761\\u8BC4\\u8BBA
\\n
\\n
\\n \\n \\n \\n ';\n _root.el.innerHTML = eleHTML;\n // Empty Data\n var vempty = _root.el.querySelector('.vempty');\n _root.nodata = {\n show: function show(txt) {\n vempty.innerHTML = txt || '\\u8FD8\\u6CA1\\u6709\\u8BC4\\u8BBA\\u54E6\\uFF0C\\u5FEB\\u6765\\u62A2\\u6C99\\u53D1\\u5427!';\n vempty.setAttribute('style', 'display:block;');\n },\n hide: function hide() {\n vempty.setAttribute('style', 'display:none;');\n }\n };\n _root.nodata.show();\n\n // load smiles image\n var _smile_wrapper = _root.el.querySelector('.vsmile-icons');\n var smile_names = option.emoticon_list || [\"mrgreen\", \"neutral\", \"twisted\", \"arrow\", \"eek\", \"smile\", \"confused\", \"cool\", \"evil\", \"biggrin\", \"idea\", \"redface\", \"razz\", \"rolleyes\", \"wink\", \"cry\", \"surprised\", \"lol\", \"mad\", \"sad\", \"exclaim\", \"question\"];\n for (var i in smile_names) {\n var img = document.createElement('img');\n img.setAttribute('src', option.emoticon_url + '/' + smile_names[i]);\n _smile_wrapper.appendChild(img);\n }\n av.init({\n appId: option.app_id || option.appId,\n appKey: option.app_key || option.appKey\n });\n _root.v = av;\n } catch (ex) {\n var issue = 'https://github.com/panjunwen/Valine/issues';\n if (_root.el) _root.nodata.show('' + ex + '
Valine:' + _root.version + '
\\u53CD\\u9988\\uFF1A' + issue + '
');else console && console.log('%c' + ex + '\\n%cValine%c' + _root.version + ' ' + issue, 'color:red;', 'background:#000;padding:5px;line-height:30px;color:#fff;', 'background:#456;line-height:30px;padding:5px;color:#fff;');\n return;\n }\n\n // loading\n var _spinner = '';\n var vloading = _root.el.querySelector('.vloading');\n vloading.innerHTML = _spinner;\n // loading control\n _root.loading = {\n show: function show() {\n vloading.setAttribute('style', 'display:block;');\n _root.nodata.hide();\n },\n hide: function hide() {\n vloading.setAttribute('style', 'display:none;');\n _root.el.querySelectorAll('.vcard').length === 0 && _root.nodata.show();\n }\n };\n\n var vsubmitting = _root.el.querySelector('.vsubmitting');\n vsubmitting.innerHTML = _spinner;\n _root.submitting = {\n show: function show() {\n vsubmitting.setAttribute('style', 'display:block;');\n },\n hide: function hide() {\n vsubmitting.setAttribute('style', 'display:none;');\n _root.nodata.hide();\n }\n };\n\n var _mark = _root.el.querySelector('.vmark');\n // alert\n _root.alert = {\n /**\n * {\n * type:0/1,\n * text:'',\n * ctxt:'',\n * otxt:'',\n * cb:fn\n * }\n *\n * @param {Object} o\n */\n show: function show(o) {\n _mark.innerHTML = '';\n var _vbtns = _mark.querySelector('.vbtns');\n var _cBtn = '';\n var _oBtn = '';\n _vbtns.innerHTML = '' + _cBtn + (o.type && _oBtn);\n _mark.querySelector('.vcancel').addEventListener('click', function (e) {\n _root.alert.hide();\n });\n _mark.setAttribute('style', 'display:block;');\n if (o && o.type) {\n var _ok = _mark.querySelector('.vsure');\n Event.on('click', _ok, function (e) {\n _root.alert.hide();\n o.cb && o.cb();\n });\n }\n },\n hide: function hide() {\n _mark.setAttribute('style', 'display:none;');\n }\n };\n\n _root.loading.show();\n var query = new _root.v.Query('Comment');\n query.equalTo('url', defaultComment['url']);\n query.count().then(function (count) {\n _root.el.querySelector('.count').innerHTML = '' + count;\n _root.bind(option);\n }, function (error) {\n console.log(error);\n });\n }\n\n /**\n * Bind Event\n */\n\n }, {\n key: 'bind',\n value: function bind(option) {\n var _root = this;\n // Smile pictures\n var vsmiles = _root.el.querySelector('.vsmile-icons');\n Event.on('click', vsmiles, function (e) {\n var textField = _root.el.querySelector('.veditor');\n var imgSrc = e.target.src;\n if (typeof imgSrc == 'undefined') return;\n // var tag = \" ![](/\" + imgSrc.replace(/^.*\\/(.*\\.gif)$/, '$1') + \") \";\n var tag = \"!(:\" + decodeURI(imgSrc).replace(/^.*\\/(.*)$/, '$1') + \":)\";\n if (document.selection) {\n textField.focus();\n sel = document.selection.createRange();\n sel.text = tag;\n textField.focus();\n } else if (textField.selectionStart || textField.selectionStart == '0') {\n var startPos = textField.selectionStart;\n var endPos = textField.selectionEnd;\n var cursorPos = endPos;\n textField.value = textField.value.substring(0, startPos) + tag + textField.value.substring(endPos, textField.value.length);\n cursorPos += tag.length;\n textField.focus();\n textField.selectionStart = cursorPos;\n textField.selectionEnd = cursorPos;\n } else {\n textField.value += tag;\n textField.focus();\n }\n defaultComment[\"comment\"] = textField.value;\n var submitBtn = _root.el.querySelector('.vsubmit');\n if (submitBtn.getAttribute('disabled')) submitBtn.removeAttribute('disabled');\n });\n var comment_trigger = _root.el.querySelector('.comment_trigger');\n Event.on('click', comment_trigger, function (e) {\n comment_trigger.setAttribute('style', 'display:none');\n _root.el.querySelector('.auth-section').removeAttribute('style');\n _root.el.querySelector('.veditor').focus();\n });\n var smile_btn = _root.el.querySelector('.vsmile-btn');\n var smile_icons = _root.el.querySelector('.vsmile-icons');\n Event.on('click', smile_btn, function (e) {\n if (smile_icons.getAttribute('triggered')) {\n smile_icons.setAttribute('style', 'display:none;');\n smile_icons.removeAttribute('triggered');\n } else {\n smile_icons.removeAttribute('style');\n smile_icons.setAttribute('triggered', 1);\n }\n });\n\n // Query && show comment list\n\n var expandEvt = function expandEvt(el) {\n if (el.offsetHeight > 180) {\n el.classList.add('expand');\n Event.on('click', el, function (e) {\n el.setAttribute('class', 'vcomment');\n });\n }\n };\n\n var commonQuery = function commonQuery() {\n var query = new _root.v.Query('Comment');\n query.select(['nick', 'comment', 'link', 'rid', 'emailHash']);\n query.notEqualTo('isSpam', true);\n query.equalTo('url', defaultComment['url']);\n query.addDescending('createdAt');\n return query;\n };\n\n var num = 1;\n var query = function query() {\n var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;\n\n _root.loading.show();\n var size = 10;\n var count = Number(_root.el.querySelector('.count').innerText);\n var cq = commonQuery();\n cq.limit(size);\n cq.skip((n - 1) * size);\n cq.find().then(function (rets) {\n var len = rets.length;\n if (len) {\n // _root.el.querySelector('.vlist').innerHTML = '';\n for (var i = 0; i < len; i++) {\n insertComment(rets[i], false);\n }\n var _vpage = _root.el.querySelector('.vpage');\n _vpage.innerHTML = size * n < count ? '\\u52A0\\u8F7D\\u66F4\\u591A\\u8BC4\\u8BBA\\uFF08\\u5269\\u4F59' + (count - size * n) + '/' + count + '\\u6761\\uFF09
' : '';\n var _vmore = _vpage.querySelector('#vmore');\n if (_vmore) {\n Event.on('click', _vmore, function (e) {\n _vpage.innerHTML = '';\n query(++num);\n });\n }\n }\n _root.loading.hide();\n }).catch(function (ex) {\n console.log(ex);\n _root.loading.hide();\n });\n };\n query();\n\n var insertComment = function insertComment(ret) {\n var top = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;\n\n var _vcard = document.createElement('li');\n _vcard.setAttribute('class', 'vcard');\n _vcard.setAttribute('id', ret.id);\n var emailHash = ret.get('emailHash') == EMPTY_EMAIL_HASH ? DEFAULT_EMAIL_HASH : ret.get('emailHash');\n var gravatar_url = GRAVATAR_BASE_URL + emailHash + '?size=80';\n // language=HTML\n _vcard.innerHTML = '\\n \\n \n \n \n \n \n \n \n \n \n \n \n \n `;\n _root.el.innerHTML = eleHTML;\n // Empty Data\n let vempty = _root.el.querySelector('.vempty');\n _root.nodata = {\n show(txt) {\n vempty.innerHTML = txt || `还没有评论哦,快来抢沙发吧!`;\n vempty.setAttribute('style', 'display:block;');\n },\n hide() {\n vempty.setAttribute('style', 'display:none;');\n }\n }\n _root.nodata.show();\n\n // load smiles image\n let _smile_wrapper = _root.el.querySelector('.vsmile-icons'); \n let smile_names = option.emoticon_list || [\"mrgreen\", \"neutral\", \"twisted\", \"arrow\", \"eek\", \"smile\", \"confused\", \"cool\", \"evil\", \"biggrin\", \"idea\", \"redface\", \"razz\", \"rolleyes\", \"wink\", \"cry\", \"surprised\", \"lol\", \"mad\", \"sad\", \"exclaim\", \"question\"];\n for(let i in smile_names) {\n let img = document.createElement('img');\n img.setAttribute('src', `${option.emoticon_url}/${smile_names[i]}`);\n _smile_wrapper.appendChild(img) ;\n }\n av.init({\n appId: option.app_id || option.appId,\n appKey: option.app_key || option.appKey\n });\n _root.v = av;\n\n } catch (ex) {\n let issue = 'https://github.com/panjunwen/Valine/issues';\n if (_root.el) _root.nodata.show(`${ex}
Valine:${_root.version}
反馈:${issue}
`);\n else console && console.log(`%c${ex}\\n%cValine%c${_root.version} ${issue}`, 'color:red;', 'background:#000;padding:5px;line-height:30px;color:#fff;', 'background:#456;line-height:30px;padding:5px;color:#fff;');\n return;\n }\n\n // loading\n let _spinner = ``;\n let vloading = _root.el.querySelector('.vloading');\n vloading.innerHTML = _spinner;\n // loading control\n _root.loading = {\n show() {\n vloading.setAttribute('style', 'display:block;');\n _root.nodata.hide();\n },\n hide() {\n vloading.setAttribute('style', 'display:none;');\n _root.el.querySelectorAll('.vcard').length === 0 && _root.nodata.show();\n }\n };\n\n let vsubmitting = _root.el.querySelector('.vsubmitting');\n vsubmitting.innerHTML = _spinner;\n _root.submitting = {\n show() {\n vsubmitting.setAttribute('style', 'display:block;');\n },\n hide() {\n vsubmitting.setAttribute('style', 'display:none;');\n _root.nodata.hide();\n }\n };\n\n let _mark = _root.el.querySelector('.vmark');\n // alert\n _root.alert = {\n /**\n * {\n * type:0/1,\n * text:'',\n * ctxt:'',\n * otxt:'',\n * cb:fn\n * }\n *\n * @param {Object} o\n */\n show(o) {\n _mark.innerHTML = ``;\n let _vbtns = _mark.querySelector('.vbtns');\n let _cBtn = ``;\n let _oBtn = ``;\n _vbtns.innerHTML = `${_cBtn}${o.type && _oBtn}`;\n _mark.querySelector('.vcancel').addEventListener('click', function (e) {\n _root.alert.hide();\n });\n _mark.setAttribute('style', 'display:block;');\n if (o && o.type) {\n let _ok = _mark.querySelector('.vsure');\n Event.on('click', _ok, (e) => {\n _root.alert.hide();\n o.cb && o.cb();\n });\n }\n },\n hide() {\n _mark.setAttribute('style', 'display:none;');\n }\n }\n\n _root.loading.show();\n var query = new _root.v.Query('Comment');\n query.equalTo('url', defaultComment['url']);\n query.count().then(function (count) {\n _root.el.querySelector('.count').innerHTML = `${count}`;\n _root.bind(option);\n }, function (error) {\n console.log(error);\n });\n }\n\n /**\n * Bind Event\n */\n bind(option) {\n let _root = this;\n // Smile pictures\n let vsmiles = _root.el.querySelector('.vsmile-icons');\n Event.on('click', vsmiles, (e) => {\n var textField = _root.el.querySelector('.veditor');\n let imgSrc = e.target.src;\n if ( typeof imgSrc == 'undefined' ) return;\n // var tag = \" ![](/\" + imgSrc.replace(/^.*\\/(.*\\.gif)$/, '$1') + \") \";\n var tag = \"!(:\" + decodeURI(imgSrc).replace(/^.*\\/(.*)$/, '$1') + \":)\";\n if (document.selection) {\n textField.focus();\n sel = document.selection.createRange();\n sel.text = tag;\n textField.focus();\n } else if (textField.selectionStart || textField.selectionStart == '0') {\n var startPos = textField.selectionStart;\n var endPos = textField.selectionEnd;\n var cursorPos = endPos;\n textField.value = textField.value.substring(0, startPos) + tag + textField.value.substring(endPos, textField.value.length);\n cursorPos += tag.length;\n textField.focus();\n textField.selectionStart = cursorPos;\n textField.selectionEnd = cursorPos\n } else {\n textField.value += tag;\n textField.focus()\n }\n defaultComment[\"comment\"] = textField.value;\n let submitBtn = _root.el.querySelector('.vsubmit');\n if (submitBtn.getAttribute('disabled')) submitBtn.removeAttribute('disabled');\n })\n let comment_trigger = _root.el.querySelector('.comment_trigger');\n Event.on('click', comment_trigger, (e) => {\n comment_trigger.setAttribute('style', 'display:none');\n _root.el.querySelector('.auth-section').removeAttribute('style');\n _root.el.querySelector('.veditor').focus();\n })\n let smile_btn = _root.el.querySelector('.vsmile-btn');\n let smile_icons = _root.el.querySelector('.vsmile-icons');\n Event.on('click', smile_btn, (e)=>{\n if (smile_icons.getAttribute('triggered')) {\n smile_icons.setAttribute('style', 'display:none;');\n smile_icons.removeAttribute('triggered');\n }\n else {\n smile_icons.removeAttribute('style');\n smile_icons.setAttribute('triggered', 1);\n }\n });\n\n // Query && show comment list\n\n let expandEvt = (el) => {\n if (el.offsetHeight > 180) {\n el.classList.add('expand');\n Event.on('click', el, (e) => {\n el.setAttribute('class', 'vcomment');\n })\n }\n };\n\n let commonQuery = () => {\n let query = new _root.v.Query('Comment');\n query.select(['nick', 'comment', 'link', 'rid', 'emailHash']);\n query.notEqualTo('isSpam', true);\n query.equalTo('url', defaultComment['url']);\n query.addDescending('createdAt');\n return query;\n };\n\n var num = 1;\n let query = (n = 1) => {\n _root.loading.show();\n var size = 10;\n var count = Number(_root.el.querySelector('.count').innerText);\n let cq = commonQuery();\n cq.limit(size);\n cq.skip((n - 1) * size);\n cq.find().then(rets => {\n let len = rets.length;\n if (len) {\n // _root.el.querySelector('.vlist').innerHTML = '';\n for (let i = 0; i < len; i++) {\n insertComment(rets[i], false)\n }\n var _vpage = _root.el.querySelector('.vpage');\n _vpage.innerHTML = size * n < count ? `加载更多评论(剩余${count - size * n}/${count}条)
` : '';\n var _vmore = _vpage.querySelector('#vmore');\n if (_vmore) {\n Event.on('click', _vmore, (e) => {\n _vpage.innerHTML = '';\n query(++num)\n })\n }\n }\n _root.loading.hide();\n }).catch(ex => {\n console.log(ex);\n _root.loading.hide();\n })\n }\n query();\n\n let insertComment = (ret, top=true) => {\n let _vcard = document.createElement('li');\n _vcard.setAttribute('class', 'vcard');\n _vcard.setAttribute('id', ret.id);\n let emailHash = ret.get('emailHash') == EMPTY_EMAIL_HASH ? DEFAULT_EMAIL_HASH : ret.get('emailHash')\n let gravatar_url = GRAVATAR_BASE_URL + emailHash + '?size=80';\n // language=HTML\n _vcard.innerHTML = `\n \n \\n \\n \\n \\n \\n \\n \\n \\n \\n
\\u5DF2\\u6709 0 \\u6761\\u8BC4\\u8BBA
\\n
\\n
\\n \\n \\n \\n ';\n _root.el.innerHTML = eleHTML;\n // Empty Data\n var vempty = _root.el.querySelector('.vempty');\n _root.nodata = {\n show: function show(txt) {\n vempty.innerHTML = txt || '\\u8FD8\\u6CA1\\u6709\\u8BC4\\u8BBA\\u54E6\\uFF0C\\u5FEB\\u6765\\u62A2\\u6C99\\u53D1\\u5427!';\n vempty.setAttribute('style', 'display:block;');\n },\n hide: function hide() {\n vempty.setAttribute('style', 'display:none;');\n }\n };\n _root.nodata.show();\n\n // load smiles image\n var _smile_wrapper = _root.el.querySelector('.vsmile-icons');\n var smile_names = option.emoticon_list || [\"mrgreen\", \"neutral\", \"twisted\", \"arrow\", \"eek\", \"smile\", \"confused\", \"cool\", \"evil\", \"biggrin\", \"idea\", \"redface\", \"razz\", \"rolleyes\", \"wink\", \"cry\", \"surprised\", \"lol\", \"mad\", \"sad\", \"exclaim\", \"question\"];\n for (var i in smile_names) {\n var img = document.createElement('img');\n img.setAttribute('src', option.emoticon_url + '/' + smile_names[i]);\n _smile_wrapper.appendChild(img);\n }\n av.init({\n appId: option.app_id || option.appId,\n appKey: option.app_key || option.appKey\n });\n _root.v = av;\n } catch (ex) {\n var issue = 'https://github.com/panjunwen/Valine/issues';\n if (_root.el) _root.nodata.show('' + ex + '
Valine:' + _root.version + '
\\u53CD\\u9988\\uFF1A' + issue + '
');else console && console.log('%c' + ex + '\\n%cValine%c' + _root.version + ' ' + issue, 'color:red;', 'background:#000;padding:5px;line-height:30px;color:#fff;', 'background:#456;line-height:30px;padding:5px;color:#fff;');\n return;\n }\n\n // loading\n var _spinner = '';\n var vloading = _root.el.querySelector('.vloading');\n vloading.innerHTML = _spinner;\n // loading control\n _root.loading = {\n show: function show() {\n vloading.setAttribute('style', 'display:block;');\n _root.nodata.hide();\n },\n hide: function hide() {\n vloading.setAttribute('style', 'display:none;');\n _root.el.querySelectorAll('.vcard').length === 0 && _root.nodata.show();\n }\n };\n\n var vsubmitting = _root.el.querySelector('.vsubmitting');\n vsubmitting.innerHTML = _spinner;\n _root.submitting = {\n show: function show() {\n vsubmitting.setAttribute('style', 'display:block;');\n },\n hide: function hide() {\n vsubmitting.setAttribute('style', 'display:none;');\n _root.nodata.hide();\n }\n };\n\n var _mark = _root.el.querySelector('.vmark');\n // alert\n _root.alert = {\n /**\n * {\n * type:0/1,\n * text:'',\n * ctxt:'',\n * otxt:'',\n * cb:fn\n * }\n *\n * @param {Object} o\n */\n show: function show(o) {\n _mark.innerHTML = '';\n var _vbtns = _mark.querySelector('.vbtns');\n var _cBtn = '';\n var _oBtn = '';\n _vbtns.innerHTML = '' + _cBtn + (o.type && _oBtn);\n _mark.querySelector('.vcancel').addEventListener('click', function (e) {\n _root.alert.hide();\n });\n _mark.setAttribute('style', 'display:block;');\n if (o && o.type) {\n var _ok = _mark.querySelector('.vsure');\n Event.on('click', _ok, function (e) {\n _root.alert.hide();\n o.cb && o.cb();\n });\n }\n },\n hide: function hide() {\n _mark.setAttribute('style', 'display:none;');\n }\n };\n\n _root.loading.show();\n var query = new _root.v.Query('Comment');\n query.equalTo('url', defaultComment['url']);\n query.count().then(function (count) {\n _root.el.querySelector('.count').innerHTML = '' + count;\n _root.bind(option);\n }, function (error) {\n console.log(error);\n });\n }\n\n /**\n * Bind Event\n */\n\n }, {\n key: 'bind',\n value: function bind(option) {\n var _root = this;\n // Smile pictures\n var vsmiles = _root.el.querySelector('.vsmile-icons');\n Event.on('click', vsmiles, function (e) {\n var textField = _root.el.querySelector('.veditor');\n var imgSrc = e.target.src;\n if (typeof imgSrc == 'undefined') return;\n // var tag = \" ![](/\" + imgSrc.replace(/^.*\\/(.*\\.gif)$/, '$1') + \") \";\n var tag = \"!(:\" + decodeURI(imgSrc).replace(/^.*\\/(.*)$/, '$1') + \":)\";\n if (document.selection) {\n textField.focus();\n sel = document.selection.createRange();\n sel.text = tag;\n textField.focus();\n } else if (textField.selectionStart || textField.selectionStart == '0') {\n var startPos = textField.selectionStart;\n var endPos = textField.selectionEnd;\n var cursorPos = endPos;\n textField.value = textField.value.substring(0, startPos) + tag + textField.value.substring(endPos, textField.value.length);\n cursorPos += tag.length;\n textField.focus();\n textField.selectionStart = cursorPos;\n textField.selectionEnd = cursorPos;\n } else {\n textField.value += tag;\n textField.focus();\n }\n defaultComment[\"comment\"] = textField.value;\n var submitBtn = _root.el.querySelector('.vsubmit');\n if (submitBtn.getAttribute('disabled')) submitBtn.removeAttribute('disabled');\n });\n var comment_trigger = _root.el.querySelector('.comment_trigger');\n Event.on('click', comment_trigger, function (e) {\n comment_trigger.setAttribute('style', 'display:none');\n _root.el.querySelector('.auth-section').removeAttribute('style');\n _root.el.querySelector('.veditor').focus();\n });\n var smile_btn = _root.el.querySelector('.vsmile-btn');\n var smile_icons = _root.el.querySelector('.vsmile-icons');\n Event.on('click', smile_btn, function (e) {\n if (smile_icons.getAttribute('triggered')) {\n smile_icons.setAttribute('style', 'display:none;');\n smile_icons.removeAttribute('triggered');\n } else {\n smile_icons.removeAttribute('style');\n smile_icons.setAttribute('triggered', 1);\n }\n });\n\n // Query && show comment list\n\n var expandEvt = function expandEvt(el) {\n if (el.offsetHeight > 180) {\n el.classList.add('expand');\n Event.on('click', el, function (e) {\n el.setAttribute('class', 'vcomment');\n });\n }\n };\n\n var commonQuery = function commonQuery() {\n var query = new _root.v.Query('Comment');\n query.select(['nick', 'comment', 'link', 'rid', 'emailHash']);\n query.notEqualTo('isSpam', true);\n query.equalTo('url', defaultComment['url']);\n query.addDescending('createdAt');\n return query;\n };\n\n var num = 1;\n var query = function query() {\n var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;\n\n _root.loading.show();\n var size = 10;\n var count = Number(_root.el.querySelector('.count').innerText);\n var cq = commonQuery();\n cq.limit(size);\n cq.skip((n - 1) * size);\n cq.find().then(function (rets) {\n var len = rets.length;\n if (len) {\n // _root.el.querySelector('.vlist').innerHTML = '';\n for (var i = 0; i < len; i++) {\n insertComment(rets[i], false);\n }\n var _vpage = _root.el.querySelector('.vpage');\n _vpage.innerHTML = size * n < count ? '\\u52A0\\u8F7D\\u66F4\\u591A\\u8BC4\\u8BBA\\uFF08\\u5269\\u4F59' + (count - size * n) + '/' + count + '\\u6761\\uFF09
' : '';\n var _vmore = _vpage.querySelector('#vmore');\n if (_vmore) {\n Event.on('click', _vmore, function (e) {\n _vpage.innerHTML = '';\n query(++num);\n });\n }\n }\n _root.loading.hide();\n }).catch(function (ex) {\n console.log(ex);\n _root.loading.hide();\n });\n };\n query();\n\n var insertComment = function insertComment(ret) {\n var top = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;\n\n var _vcard = document.createElement('li');\n _vcard.setAttribute('class', 'vcard');\n _vcard.setAttribute('id', ret.id);\n var emailHash = ret.get('emailHash') == EMPTY_EMAIL_HASH ? DEFAULT_EMAIL_HASH : ret.get('emailHash');\n var gravatar_url = GRAVATAR_BASE_URL + emailHash + '?size=80';\n // language=HTML\n _vcard.innerHTML = '\\n \\n \n \n \n \n \n \n \n \n \n \n \n \n `;\n _root.el.innerHTML = eleHTML;\n // Empty Data\n let vempty = _root.el.querySelector('.vempty');\n _root.nodata = {\n show(txt) {\n vempty.innerHTML = txt || `还没有评论哦,快来抢沙发吧!`;\n vempty.setAttribute('style', 'display:block;');\n },\n hide() {\n vempty.setAttribute('style', 'display:none;');\n }\n }\n _root.nodata.show();\n\n // load smiles image\n let _smile_wrapper = _root.el.querySelector('.vsmile-icons'); \n let smile_names = option.emoticon_list || [\"mrgreen\", \"neutral\", \"twisted\", \"arrow\", \"eek\", \"smile\", \"confused\", \"cool\", \"evil\", \"biggrin\", \"idea\", \"redface\", \"razz\", \"rolleyes\", \"wink\", \"cry\", \"surprised\", \"lol\", \"mad\", \"sad\", \"exclaim\", \"question\"];\n for(let i in smile_names) {\n let img = document.createElement('img');\n img.setAttribute('src', `${option.emoticon_url}/${smile_names[i]}`);\n _smile_wrapper.appendChild(img) ;\n }\n av.init({\n appId: option.app_id || option.appId,\n appKey: option.app_key || option.appKey\n });\n _root.v = av;\n\n } catch (ex) {\n let issue = 'https://github.com/panjunwen/Valine/issues';\n if (_root.el) _root.nodata.show(`${ex}
Valine:${_root.version}
反馈:${issue}
`);\n else console && console.log(`%c${ex}\\n%cValine%c${_root.version} ${issue}`, 'color:red;', 'background:#000;padding:5px;line-height:30px;color:#fff;', 'background:#456;line-height:30px;padding:5px;color:#fff;');\n return;\n }\n\n // loading\n let _spinner = ``;\n let vloading = _root.el.querySelector('.vloading');\n vloading.innerHTML = _spinner;\n // loading control\n _root.loading = {\n show() {\n vloading.setAttribute('style', 'display:block;');\n _root.nodata.hide();\n },\n hide() {\n vloading.setAttribute('style', 'display:none;');\n _root.el.querySelectorAll('.vcard').length === 0 && _root.nodata.show();\n }\n };\n\n let vsubmitting = _root.el.querySelector('.vsubmitting');\n vsubmitting.innerHTML = _spinner;\n _root.submitting = {\n show() {\n vsubmitting.setAttribute('style', 'display:block;');\n },\n hide() {\n vsubmitting.setAttribute('style', 'display:none;');\n _root.nodata.hide();\n }\n };\n\n let _mark = _root.el.querySelector('.vmark');\n // alert\n _root.alert = {\n /**\n * {\n * type:0/1,\n * text:'',\n * ctxt:'',\n * otxt:'',\n * cb:fn\n * }\n *\n * @param {Object} o\n */\n show(o) {\n _mark.innerHTML = ``;\n let _vbtns = _mark.querySelector('.vbtns');\n let _cBtn = ``;\n let _oBtn = ``;\n _vbtns.innerHTML = `${_cBtn}${o.type && _oBtn}`;\n _mark.querySelector('.vcancel').addEventListener('click', function (e) {\n _root.alert.hide();\n });\n _mark.setAttribute('style', 'display:block;');\n if (o && o.type) {\n let _ok = _mark.querySelector('.vsure');\n Event.on('click', _ok, (e) => {\n _root.alert.hide();\n o.cb && o.cb();\n });\n }\n },\n hide() {\n _mark.setAttribute('style', 'display:none;');\n }\n }\n\n _root.loading.show();\n var query = new _root.v.Query('Comment');\n query.equalTo('url', defaultComment['url']);\n query.count().then(function (count) {\n _root.el.querySelector('.count').innerHTML = `${count}`;\n _root.bind(option);\n }, function (error) {\n console.log(error);\n });\n }\n\n /**\n * Bind Event\n */\n bind(option) {\n let _root = this;\n // Smile pictures\n let vsmiles = _root.el.querySelector('.vsmile-icons');\n Event.on('click', vsmiles, (e) => {\n var textField = _root.el.querySelector('.veditor');\n let imgSrc = e.target.src;\n if ( typeof imgSrc == 'undefined' ) return;\n // var tag = \" ![](/\" + imgSrc.replace(/^.*\\/(.*\\.gif)$/, '$1') + \") \";\n var tag = \"!(:\" + decodeURI(imgSrc).replace(/^.*\\/(.*)$/, '$1') + \":)\";\n if (document.selection) {\n textField.focus();\n sel = document.selection.createRange();\n sel.text = tag;\n textField.focus();\n } else if (textField.selectionStart || textField.selectionStart == '0') {\n var startPos = textField.selectionStart;\n var endPos = textField.selectionEnd;\n var cursorPos = endPos;\n textField.value = textField.value.substring(0, startPos) + tag + textField.value.substring(endPos, textField.value.length);\n cursorPos += tag.length;\n textField.focus();\n textField.selectionStart = cursorPos;\n textField.selectionEnd = cursorPos\n } else {\n textField.value += tag;\n textField.focus()\n }\n defaultComment[\"comment\"] = textField.value;\n let submitBtn = _root.el.querySelector('.vsubmit');\n if (submitBtn.getAttribute('disabled')) submitBtn.removeAttribute('disabled');\n })\n let comment_trigger = _root.el.querySelector('.comment_trigger');\n Event.on('click', comment_trigger, (e) => {\n comment_trigger.setAttribute('style', 'display:none');\n _root.el.querySelector('.auth-section').removeAttribute('style');\n _root.el.querySelector('.veditor').focus();\n })\n let smile_btn = _root.el.querySelector('.vsmile-btn');\n let smile_icons = _root.el.querySelector('.vsmile-icons');\n Event.on('click', smile_btn, (e)=>{\n if (smile_icons.getAttribute('triggered')) {\n smile_icons.setAttribute('style', 'display:none;');\n smile_icons.removeAttribute('triggered');\n }\n else {\n smile_icons.removeAttribute('style');\n smile_icons.setAttribute('triggered', 1);\n }\n });\n\n // Query && show comment list\n\n let expandEvt = (el) => {\n if (el.offsetHeight > 180) {\n el.classList.add('expand');\n Event.on('click', el, (e) => {\n el.setAttribute('class', 'vcomment');\n })\n }\n };\n\n let commonQuery = () => {\n let query = new _root.v.Query('Comment');\n query.select(['nick', 'comment', 'link', 'rid', 'emailHash']);\n query.notEqualTo('isSpam', true);\n query.equalTo('url', defaultComment['url']);\n query.addDescending('createdAt');\n return query;\n };\n\n var num = 1;\n let query = (n = 1) => {\n _root.loading.show();\n var size = 10;\n var count = Number(_root.el.querySelector('.count').innerText);\n let cq = commonQuery();\n cq.limit(size);\n cq.skip((n - 1) * size);\n cq.find().then(rets => {\n let len = rets.length;\n if (len) {\n // _root.el.querySelector('.vlist').innerHTML = '';\n for (let i = 0; i < len; i++) {\n insertComment(rets[i], false)\n }\n var _vpage = _root.el.querySelector('.vpage');\n _vpage.innerHTML = size * n < count ? `加载更多评论(剩余${count - size * n}/${count}条)
` : '';\n var _vmore = _vpage.querySelector('#vmore');\n if (_vmore) {\n Event.on('click', _vmore, (e) => {\n _vpage.innerHTML = '';\n query(++num)\n })\n }\n }\n _root.loading.hide();\n }).catch(ex => {\n console.log(ex);\n _root.loading.hide();\n })\n }\n query();\n\n let insertComment = (ret, top=true) => {\n let _vcard = document.createElement('li');\n _vcard.setAttribute('class', 'vcard');\n _vcard.setAttribute('id', ret.id);\n let emailHash = ret.get('emailHash') == EMPTY_EMAIL_HASH ? DEFAULT_EMAIL_HASH : ret.get('emailHash')\n let gravatar_url = GRAVATAR_BASE_URL + emailHash + '?size=80';\n // language=HTML\n _vcard.innerHTML = `\n \n