|
|
@ -248,28 +248,29 @@
|
|
|
|
* disqusjs.page.lenfth - How many comment in this thread
|
|
|
|
* disqusjs.page.lenfth - How many comment in this thread
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
disqusjs.page = [];
|
|
|
|
(function () {
|
|
|
|
|
|
|
|
disqusjs.page = [];
|
|
|
|
|
|
|
|
|
|
|
|
window.disqus_config = function () {
|
|
|
|
window.disqus_config = function () {
|
|
|
|
this.page.url = disqusjs.config.url;
|
|
|
|
this.page.url = disqusjs.config.url;
|
|
|
|
this.page.identifier = disqusjs.config.identifier;
|
|
|
|
this.page.identifier = disqusjs.config.identifier;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
|
|
|
|
|
|
|
|
setLS = (key, value) => {
|
|
|
|
let setLS = (key, value) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
localStorage.setItem(key, value)
|
|
|
|
localStorage.setItem(key, value)
|
|
|
|
} catch (o) {
|
|
|
|
} catch (o) {
|
|
|
|
console.log(o), console.log("Failed to set localStorage item")
|
|
|
|
console.log(o), console.log("Failed to set localStorage item")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
getLS = (key) => {
|
|
|
|
getLS = (key) => {
|
|
|
|
return localStorage.getItem(key);
|
|
|
|
return localStorage.getItem(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Name: Date.Format()
|
|
|
|
* Name: Date.Format()
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
* Usage:
|
|
|
@ -285,7 +286,7 @@ getLS = (key) => {
|
|
|
|
* Example: (new Date()).Format("yyyy-MM-dd hh:mm:ss.S")
|
|
|
|
* Example: (new Date()).Format("yyyy-MM-dd hh:mm:ss.S")
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
Date.prototype.Format = function (fmt) {
|
|
|
|
Date.prototype.Format = function (fmt) {
|
|
|
|
var o = {
|
|
|
|
var o = {
|
|
|
|
"M+": this.getMonth() + 1, // Minth
|
|
|
|
"M+": this.getMonth() + 1, // Minth
|
|
|
|
"d+": this.getDate(), // Date
|
|
|
|
"d+": this.getDate(), // Date
|
|
|
@ -299,14 +300,14 @@ Date.prototype.Format = function (fmt) {
|
|
|
|
for (var k in o)
|
|
|
|
for (var k in o)
|
|
|
|
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
|
|
|
|
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
|
|
|
|
return fmt;
|
|
|
|
return fmt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Name: loadDisqus()
|
|
|
|
* Name: loadDisqus()
|
|
|
|
* Descriptin: load disqus as it should be.
|
|
|
|
* Descriptin: load disqus as it should be.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
loadDisqus = () => {
|
|
|
|
let loadDisqus = () => {
|
|
|
|
var d = document;
|
|
|
|
var d = document;
|
|
|
|
d.getElementById('dsqjs-load-disqus').classList.remove('dsqjs-hide');
|
|
|
|
d.getElementById('dsqjs-load-disqus').classList.remove('dsqjs-hide');
|
|
|
|
d.getElementById('dsqjs-force-dsqjs').addEventListener('click', forceDsqjs);
|
|
|
|
d.getElementById('dsqjs-force-dsqjs').addEventListener('click', forceDsqjs);
|
|
|
@ -314,15 +315,15 @@ loadDisqus = () => {
|
|
|
|
s.src = 'https://' + disqusjs.config.shortname + '.disqus.com/embed.js';
|
|
|
|
s.src = 'https://' + disqusjs.config.shortname + '.disqus.com/embed.js';
|
|
|
|
s.setAttribute('data-timestamp', + new Date());
|
|
|
|
s.setAttribute('data-timestamp', + new Date());
|
|
|
|
(d.head || d.body).appendChild(s);
|
|
|
|
(d.head || d.body).appendChild(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Name: checkDisqus()
|
|
|
|
* Name: checkDisqus()
|
|
|
|
* Description: Check disqus is avaliable for visitor or not
|
|
|
|
* Description: Check disqus is avaliable for visitor or not
|
|
|
|
* How it works: check favicons under 2 domains can be loaded or not.
|
|
|
|
* How it works: check favicons under 2 domains can be loaded or not.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
checkDisqus = () => {
|
|
|
|
let checkDisqus = () => {
|
|
|
|
var img = new Image;
|
|
|
|
var img = new Image;
|
|
|
|
let check1 = setTimeout(() => {
|
|
|
|
let check1 = setTimeout(() => {
|
|
|
|
img.onerror = img.onload = null;
|
|
|
|
img.onerror = img.onload = null;
|
|
|
@ -357,41 +358,41 @@ checkDisqus = () => {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
img.src = 'https://disqus.com/favicon.ico?' + +(new Date);
|
|
|
|
img.src = 'https://disqus.com/favicon.ico?' + +(new Date);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Name: forceDsqjs() forceDisqus()
|
|
|
|
* Name: forceDsqjs() forceDisqus()
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
forceDsqjs = () => {
|
|
|
|
let forceDsqjs = () => {
|
|
|
|
setLS('disqusjs_mode', 'dsqjs');
|
|
|
|
setLS('disqusjs_mode', 'dsqjs');
|
|
|
|
main();
|
|
|
|
main();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
forceDisqus = () => {
|
|
|
|
let forceDisqus = () => {
|
|
|
|
setLS('disqusjs_mode', 'disqus');
|
|
|
|
setLS('disqusjs_mode', 'disqus');
|
|
|
|
main();
|
|
|
|
main();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Name: loadError()
|
|
|
|
* Name: loadError()
|
|
|
|
* Description: When dsqjs mode load error
|
|
|
|
* Description: When dsqjs mode load error
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
loadError = () => {
|
|
|
|
let loadError = () => {
|
|
|
|
document.getElementById('dsqjs-load-error').classList.remove('dsqjs-hide');
|
|
|
|
document.getElementById('dsqjs-load-error').classList.remove('dsqjs-hide');
|
|
|
|
document.getElementById('dsqjs-loading-dsqjs').classList.add('dsqjs-hide');
|
|
|
|
document.getElementById('dsqjs-loading-dsqjs').classList.add('dsqjs-hide');
|
|
|
|
document.getElementById('dsqjs-reload').addEventListener('click', getThreadInfo);
|
|
|
|
document.getElementById('dsqjs-reload').addEventListener('click', getThreadInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Name: getThreadInfo()
|
|
|
|
* Name: getThreadInfo()
|
|
|
|
* Description: Disqus API only support get thread list by ID, not identifter. So get Thread ID before get thread list.
|
|
|
|
* Description: Disqus API only support get thread list by ID, not identifter. So get Thread ID before get thread list.
|
|
|
|
* API Docs: https://disqus.com/api/docs/threads/list/
|
|
|
|
* API Docs: https://disqus.com/api/docs/threads/list/
|
|
|
|
* API URI: /3.0/threads/list.json?forum=[disqus_shortname]&thread=ident:[identifier]&api_key=[apikey]
|
|
|
|
* API URI: /3.0/threads/list.json?forum=[disqus_shortname]&thread=ident:[identifier]&api_key=[apikey]
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
getThreadInfo = () => {
|
|
|
|
let getThreadInfo = () => {
|
|
|
|
document.getElementById('dsqjs-loading-dsqjs').classList.remove('dsqjs-hide');
|
|
|
|
document.getElementById('dsqjs-loading-dsqjs').classList.remove('dsqjs-hide');
|
|
|
|
document.getElementById('dsqjs-force-disqus').addEventListener('click', forceDisqus);
|
|
|
|
document.getElementById('dsqjs-force-disqus').addEventListener('click', forceDisqus);
|
|
|
|
document.getElementById('dsqjs-reload-disqus').addEventListener('click', checkDisqus);
|
|
|
|
document.getElementById('dsqjs-reload-disqus').addEventListener('click', checkDisqus);
|
|
|
@ -417,15 +418,15 @@ getThreadInfo = () => {
|
|
|
|
xhr.onerror = (e) => {
|
|
|
|
xhr.onerror = (e) => {
|
|
|
|
loadError();
|
|
|
|
loadError();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Name: getComment()
|
|
|
|
* Name: getComment()
|
|
|
|
* Description: get the comment content
|
|
|
|
* Description: get the comment content
|
|
|
|
* API URI: /3.0/posts/list.json?forum=[shortname]&thread=[thread id]&api_key=[apikey]
|
|
|
|
* API URI: /3.0/posts/list.json?forum=[shortname]&thread=[thread id]&api_key=[apikey]
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
getComment = () => {
|
|
|
|
let getComment = () => {
|
|
|
|
let url = disqusjs.config.api + '3.0/posts/list.json?forum=' + disqusjs.config.shortname + '&thread=' + disqusjs.page.id + '&api_key=' + disqusjs.config.apikey;
|
|
|
|
let url = disqusjs.config.api + '3.0/posts/list.json?forum=' + disqusjs.config.shortname + '&thread=' + disqusjs.page.id + '&api_key=' + disqusjs.config.apikey;
|
|
|
|
xhr.open('GET', url, true);
|
|
|
|
xhr.open('GET', url, true);
|
|
|
|
xhr.timeout = 4000;
|
|
|
|
xhr.timeout = 4000;
|
|
|
@ -450,14 +451,14 @@ getComment = () => {
|
|
|
|
// Have error when get comments.
|
|
|
|
// Have error when get comments.
|
|
|
|
loadError();
|
|
|
|
loadError();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Name: getCommentList(data)
|
|
|
|
* Name: getCommentList(data)
|
|
|
|
* Description: Render JSON to comment list components
|
|
|
|
* Description: Render JSON to comment list components
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
getCommentList = (data) => {
|
|
|
|
let getCommentList = (data) => {
|
|
|
|
var topLevelComments = [];
|
|
|
|
var topLevelComments = [];
|
|
|
|
var childComments = [];
|
|
|
|
var childComments = [];
|
|
|
|
|
|
|
|
|
|
|
@ -497,9 +498,9 @@ getCommentList = (data) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
renderComment(commentLists)
|
|
|
|
renderComment(commentLists)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
renderComment = (data) => {
|
|
|
|
let renderComment = (data) => {
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
<div class="dsqjs-item-container">
|
|
|
|
<div class="dsqjs-item-container">
|
|
|
|
<div class="dsqjs-avater">
|
|
|
|
<div class="dsqjs-avater">
|
|
|
@ -518,7 +519,7 @@ renderComment = (data) => {
|
|
|
|
var commentBodyTpl = `<div class="dsqjs-item-container"><div class="dsqjs-avater"><%- avatarEl %></div><div class="dsqjs-body"><header class="dsqjs-header"><span class="dsqjs-author"><%- authorEl %></span><span class="dsqjs-bullet"></span><span class="dsqjs-meta"><time><%- (new Date(createdAt)).Format("yyyy-MM-dd hh:mm:ss") %></time></span></header><div class="dsqjs-content"><%- message %></div></div></div>`
|
|
|
|
var commentBodyTpl = `<div class="dsqjs-item-container"><div class="dsqjs-avater"><%- avatarEl %></div><div class="dsqjs-body"><header class="dsqjs-header"><span class="dsqjs-author"><%- authorEl %></span><span class="dsqjs-bullet"></span><span class="dsqjs-meta"><time><%- (new Date(createdAt)).Format("yyyy-MM-dd hh:mm:ss") %></time></span></header><div class="dsqjs-content"><%- message %></div></div></div>`
|
|
|
|
|
|
|
|
|
|
|
|
data.map(s => {
|
|
|
|
data.map(s => {
|
|
|
|
childrenComments = (s) => {
|
|
|
|
let childrenComments = (s) => {
|
|
|
|
var nesting = s.nesting
|
|
|
|
var nesting = s.nesting
|
|
|
|
|
|
|
|
|
|
|
|
var children = (s.children || []);
|
|
|
|
var children = (s.children || []);
|
|
|
@ -598,9 +599,9 @@ renderComment = (data) => {
|
|
|
|
|
|
|
|
|
|
|
|
document.getElementById('dsqjs-list').insertAdjacentHTML('beforeend', html);
|
|
|
|
document.getElementById('dsqjs-list').insertAdjacentHTML('beforeend', html);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
main = () => {
|
|
|
|
let main = () => {
|
|
|
|
// Add dsqjs container element to #disqus_thread
|
|
|
|
// Add dsqjs container element to #disqus_thread
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
@ -630,6 +631,8 @@ main = () => {
|
|
|
|
checkDisqus();
|
|
|
|
checkDisqus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main();
|
|
|
|
|
|
|
|
|
|
|
|
main();
|
|
|
|
})();
|