func(loadDsqjs): bring up

feat/fix/umd
SukkaW 7 years ago
parent fdc083faf4
commit c2b0ae1ebc

@ -55,20 +55,16 @@ function DisqusJS(config) {
() => {} () => {}
}) })
*/ */
const get = ({ const get = (url, success, error) => {
url = '/',
timeout = '4000',
async = true
}, success, error) => {
let xhr = new XMLHttpRequest() let xhr = new XMLHttpRequest()
xhr.open('GET', encodeURI(url), async); xhr.open('GET', encodeURI(url), true);
xhr.onreadystatechange = () => { xhr.onreadystatechange = () => {
if (xhr.readyState == 4 && xhr.status == 200) { if (xhr.readyState == 4 && xhr.status == 200) {
let res = JSON.parse(xhr.responseText) let res = JSON.parse(xhr.responseText)
success(res) success(res)
} }
}; };
xhr.timeout = timeout; xhr.timeout = 4000;
xhr.ontimeout = (e) => { xhr.ontimeout = (e) => {
error(e); error(e);
}; };
@ -125,6 +121,9 @@ function DisqusJS(config) {
return `${y}-${m}-${d} ${h}:${minute}:${second}`; return `${y}-${m}-${d} ${h}:${minute}:${second}`;
} }
/*
* loadDisqus() - 加载 Disqus
*/
function loadDisqus() { function loadDisqus() {
let d = document; let d = document;
let s = d.createElement('script'); let s = d.createElement('script');
@ -174,4 +173,33 @@ function DisqusJS(config) {
} }
} }
function loadDsqjs() {
(() => {
let url = `${disqusjs.config.api}3.0/threads/list.json?forum=${disqusjs.config.shortname}&thread=ident:${disqusjs.config.identifier}&api_key=${disqusjs.config.apikey}`;
/*
* 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 URI: /3.0/threads/list.json?forum=[disqus_shortname]&thread=ident:[identifier]&api_key=[apikey]
*/
get(url, (res) => {
if (res.response.length === 1) {
var resp = res.response[0];
disqusjs.page = {
id: resp.id,
title: resp.title,
isClosed: resp.isClosed,
length: resp.posts
};
// 获取评论列表
} else {
// 当前页面可能还未初始化(创建 thread
}
}, (e) => {
console.log(e);
})
})()
}
loadDsqjs()
} }

Loading…
Cancel
Save