chore: use buble instead of babel

feat/fix/umd
SukkaW 7 years ago
parent 074bd57522
commit e08ead2f0a

226
dist/disqus.js vendored

@ -0,0 +1,226 @@
/*!
* DisqusJS | v0.2.4
* Author: SukkaW
* Link: https://github.com/SukkaW/DisqusJS
* License: GPL-3.0
*//*
* The variable used in DisqusJS
*
* DisqusJS Mode
* disqusjs.mode = dsqjs | disqus - Set which mode to use, should store and get in localStorage
*
* DisqusJS Config
* disqusjs.config.shortname - The disqus shortname
* disqusjs.config.identifier - The identifier of the page
* disqusjs.config.url - The url of the page
* disqusjs.config.api - Where to get data
* disqusjs.config.apikey - The apikey used to request Disqus API
* disqusjs.config.admin - The disqus forum admin username
* disqusjs.config.adminLabel - The disqus moderator badge text
*
* DisqusJS Info
* disqusjs.page.id = The thread id, used at next API call
* disqusjs.page.title - The thread title
* disqusjs.page.isClosed - Whether the comment is closed
* disqusjs.page.lenfth - How many comment in this thread
*/
function DisqusJS(config) {
var disqusjs = [];
disqusjs.config = config
// 定义 disqusjs.page之后会填充 thread id、title 等数据
disqusjs.page = [];
/*
* window.disqus_config - disqusjs.config 获取 Disqus 所需的配置
*/
window.disqus_config = function () {
this.page.url = disqusjs.config.url;
this.page.identifier = disqusjs.config.identifier;
};
/*
* get - 封装 XHR GET
*
* @param {string} url
* @param {string} timeout
* @param {boolean} async
* @param {function} success
* @param {function} error
*
* Example:
get({
'http://localhost:3000/getData',
4000,
true,
(res) => {
console.log(res)
},
() => {}
})
*/
var get = function (url, success, error) {
var xhr = new XMLHttpRequest()
xhr.open('GET', encodeURI(url), true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
var res = JSON.parse(xhr.responseText)
success(res)
}
};
xhr.timeout = 4000;
xhr.ontimeout = function (e) {
error(e);
};
xhr.onerror = function (e) {
error(e);
};
xhr.send();
}
// localstorage 操作类
// 用于持久化某些数据(如 newComment 的评论者的相关信息)
/*
* setLS(kwy, value) - 设置 localStorage
*
* @param {string} key
* @param {string} value
*/
var setLS = function (key, value) {
try {
localStorage.setItem(key, value);
} catch (e) {
}
}
/*
* getLS(key) - localStorage 条目
*
* @param {string} key
* @return {string} - 返回条目 value 内容
*/
var getLS = function (key) {
return localStorage.getItem(key);
}
/*
* dateFormat(date) - 解析 date yyyy-MM-dd hh:mm:ss
*
* @param {function} date - 传入 Date 对象
* @return {string} - 格式化后的日期
*/
var dateFormat = function (date) {
var y = date.getFullYear();
var m = date.getMonth() + 1;
m = m < 10 ? (("0" + m)) : m;
var d = date.getDate();
d = d < 10 ? (("0" + d)) : d;
var h = date.getHours() + 8;
h = h < 10 ? (("0" + h)) : h;
var minute = date.getMinutes();
minute = minute < 10 ? (("0" + minute)) : minute;
var second = date.getSeconds();
second = minute < 10 ? (("0" + second)) : second;
return (y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + second);
}
/*
* loadDisqus() - 加载 Disqus
*/
function loadDisqus() {
var d = document;
var s = d.createElement('script');
s.src = 'https://' + disqusjs.config.shortname + '.disqus.com/embed.js';
s.setAttribute('data-timestamp', + new Date());
(d.head || d.body).appendChild(s);
}
function checkDisqus() {
var domain = ['disqus.com', ((disqusjs.config.shortname) + ".disqus.com")],
test = 0,
success = 0;
var checker = function () {
if ((domain.length === test) && (test === success)) {
setLS('dsqjs_mode', 'disqus')
} else if (domain.length === test) {
setLS('dsqjs_mode', 'dsqjs')
}
}
for (var i$1 = 0, list = domain; i$1 < list.length; i$1 += 1) {
var i = list[i$1];
(function (i) {
var img = new Image;
var timeout = setTimeout(function () {
img.onerror = img.onload = null;
test++;
checker()
}, 2000);
img.onerror = function () {
clearTimeout(timeout);
test++;
checker()
}
img.onload = function () {
clearTimeout(timeout);
test++;
success++;
checker()
}
img.src = "https://" + i + "/favicon.ico?" + (+(new Date))
})(i);
}
}
function loadDsqjs() {
(function () {
var 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, function (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
}
}, function (e) {
console.log(e);
})
})()
function getComment(cursor) {
if (!cursor) {
cursor = '';
} else {
cursor = "&cursor=" + cursor;
}
/*
* Description: get the comment content
* API URI: /3.0/posts/list.json?forum=[shortname]&thread=[thread id]&api_key=[apikey]
*/
var url = (disqusjs.config.api) + "3.0/posts/list.json?forum=" + (disqusjs.config.shortname) + "&thread=" + (disqusjs.page.id) + cursor + "&api_key=" + (disqusjs.config.apikey);
console.log(url)
}
}
loadDsqjs()
}

6
dist/disqusjs.css vendored

@ -0,0 +1,6 @@
/*!
* DisqusJS - Default Theme | v0.2.4
* Author: SukkaW
* Link: https://github.com/SukkaW/DisqusJS
* License: GPL-3.0
*/

@ -1,6 +1,6 @@
let gulp = require('gulp'); let gulp = require('gulp');
let uglify = require('gulp-uglify'); let uglify = require('gulp-uglify');
let babel = require('gulp-babel'); let buble = require('gulp-buble');
let autoprefixer = require('gulp-autoprefixer'); let autoprefixer = require('gulp-autoprefixer');
let cleanCSS = require('gulp-clean-css'); let cleanCSS = require('gulp-clean-css');
let header = require('gulp-header'); let header = require('gulp-header');
@ -39,12 +39,8 @@ var configs = {
gulp.task('minify-js', () => { gulp.task('minify-js', () => {
return gulp.src('src/**/*.js') return gulp.src('src/**/*.js')
.pipe(babel({ .pipe(buble({
"presets": [ transforms: { dangerousForOf: true }
["@babel/env", {
"targets": configs.browsers
}]
]
})) }))
.pipe(uglify({ .pipe(uglify({
keep_fnames: false keep_fnames: false

@ -25,11 +25,9 @@
}, },
"homepage": "https://github.com/SukkaW/DisqusJS#readme", "homepage": "https://github.com/SukkaW/DisqusJS#readme",
"dependencies": { "dependencies": {
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"gulp": "4", "gulp": "4",
"gulp-autoprefixer": "^6.0.0", "gulp-autoprefixer": "^6.0.0",
"gulp-babel": "^8.0.0", "gulp-buble": "^0.9.0",
"gulp-clean-css": "^3.10.0", "gulp-clean-css": "^3.10.0",
"gulp-header": "^2.0.5", "gulp-header": "^2.0.5",
"gulp-uglify": "^3.0.1" "gulp-uglify": "^3.0.1"

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save