兼容性调整

This commit is contained in:
结发受长生 2018-06-08 10:48:48 +08:00
parent e7c6945df4
commit 9fa331206c
15 changed files with 226 additions and 286 deletions

View File

@ -11,9 +11,6 @@
<div class="article-entry" itemprop="articleBody">
<% if (post.excerpt && index){ %>
<%- post.excerpt %>
<% if (theme.excerpt_link) { %>
<a class="article-more-a" href="<%- url_for(post.path) %>#more"><%= theme.excerpt_link %> >></a>
<% } %>
<% } else { %>
<%- post.content %>
<% } %>
@ -78,24 +75,7 @@
<% } %>
<%- partial('_partial/aside') %>
<% if (!index && post.comments){ %>
<% if (theme.duoshuo){ %>
<%- partial('post/duoshuo', {
key: post.slug,
title: post.title,
url: config.url+url_for(post.path)
}) %>
<% } %>
<% if (theme.wangyiyun){ %>
<%- partial('post/wangyiyun', {
key: post.slug,
title: post.title,
url: config.url+url_for(post.path)
}) %>
<% } %>
<% if (theme.changyan_appid && theme.changyan_conf){ %>
<%- partial('post/changyan', {
key: post.slug,
@ -105,21 +85,21 @@
<% } %>
<% if (theme.disqus || config.disqus_shortname){ %>
<section id="comments">
<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = '<%= theme.disqus || config.disqus_shortname %>'; // required: replace example with your forum shortname
<section id="comments">
<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = '<%= theme.disqus || config.disqus_shortname %>'; // required: replace example with your forum shortname
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</section>
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</section>
<% } %>
<% if(theme.gitalk.enable){ %>

View File

@ -15,12 +15,8 @@
<% if (theme.subtitle){ %>
<p class="header-subtitle"><i class="icon icon-quo-left"></i><%=theme.subtitle%><i class="icon icon-quo-right"></i></p>
<% } %>
<% var count = 0%>
<% for (var i in theme.menu){ %>
<% count++ %>
<% } %>
<% var ulWidth = count > 2 ? '70%' : '50%' %>
<% var count = Object.keys(theme.menu).length
var ulWidth = count > 2 ? '70%' : '50%' %>
<nav class="header-nav">
<div class="social">
<% for (var i in theme.subnav){ %>

View File

@ -1,10 +0,0 @@
<div id="cloud-tie-wrapper" class="cloud-tie-wrapper"></div>
<script>
var cloudTieConfig = {
url: "<%=url%>",
sourceId: "<%=key%>",
productKey: "<%=theme.wangyiyun%>",
target: "cloud-tie-wrapper"
};
</script>
<script src="//img1.cache.netease.com/f2e/tie/yun/sdk/loader.js"></script>

View File

@ -1 +1 @@
<%- js('js/mobile.04379a910e1ff32f2a41.js') %> <%- js('js/slider.a725c75e59c2eeae98e0.js') %> <%- js('js/main.254cebd259c4777bdd2e.js') %>
<%- js('js/mobile.ea63a7925e7ff5c87e64.js') %> <%- js('js/slider.6142a9af4c6883a7d429.js') %> <%- js('js/main.361198a3fa95601c34df.js') %>

View File

@ -121,7 +121,7 @@
<%if(hasAboutme){%>
<section class="tools-section tools-section-me" v-show="aboutme">
<%if(theme.aboutme){%>
<div class="aboutme-wrap" id="js-aboutme"><%=theme.aboutme%></div>
<div class="aboutme-wrap" id="js-aboutme"><%-theme.aboutme%></div>
<%}%>
</section>
<%}%>

View File

@ -89,7 +89,4 @@ function init() {
}
}
module.exports = {
init: init
}
export default { init }

View File

@ -1,47 +1,47 @@
var backTop = function (domE, ctn, distance) {
if (!domE) return;
var timer = null;
var _onscroll = window.onscroll,
_onclick = domE.onclick;
(ctn || window).onscroll = throttle(function () {
typeof _onscroll === 'function' && _onscroll.apply(this, arguments);
toggleDomE();
}, 100);
domE.onclick = function () {
typeof _onclick === 'function' && _onclick.apply(this, arguments);
var baseCt = ctn.scrollTop || document.documentElement.scrollTop || document.body.scrollTop;
timer = setInterval(function () { //设置一个计时器
var ct = ctn.scrollTop || document.documentElement.scrollTop || document.body.scrollTop; //获取距离顶部的距离
var diff = Math.max(10, ct / 6);
ct -= diff;
if (ct > 0) {//如果与顶部的距离大于零
ctn.scrollTop = ctn.scrollTop - diff;
window.scrollTo(0, ct);//向上移动10px
} else {//如果距离小于等于零
ctn.scrollTop = 0;
window.scrollTo(0, 0);//移动到顶部
clearInterval(timer);//清除计时器
}
}, 10);//隔10ms执行一次前面的function展现一种平滑滑动效果
};
if (!domE) return;
var timer = null;
var _onscroll = window.onscroll,
_onclick = domE.onclick;
(ctn || window).onscroll = throttle(function () {
typeof _onscroll === 'function' && _onscroll.apply(this, arguments);
toggleDomE();
}, 100);
domE.onclick = function () {
typeof _onclick === 'function' && _onclick.apply(this, arguments);
var baseCt = ctn.scrollTop || document.documentElement.scrollTop || document.body.scrollTop;
timer = setInterval(function () { //设置一个计时器
var ct = ctn.scrollTop || document.documentElement.scrollTop || document.body.scrollTop; //获取距离顶部的距离
var diff = Math.max(10, ct / 6);
ct -= diff;
if (ct > 0) {//如果与顶部的距离大于零
ctn.scrollTop = ctn.scrollTop - diff;
window.scrollTo(0, ct);//向上移动10px
} else {//如果距离小于等于零
ctn.scrollTop = 0;
window.scrollTo(0, 0);//移动到顶部
clearInterval(timer);//清除计时器
}
}, 10);//隔10ms执行一次前面的function展现一种平滑滑动效果
};
function toggleDomE() {
domE.style.display = (ctn.scrollTop || document.documentElement.scrollTop || document.body.scrollTop) > (distance || 500) ? 'block' : 'none';
}
function throttle(func, wait) {
var timer = null;
return function () {
var self = this, args = arguments;
if (timer) clearTimeout(timer);
timer = setTimeout(function () {
return typeof func === 'function' && func.apply(self, args);
}, wait);
}
function toggleDomE() {
domE.style.display = (ctn.scrollTop || document.documentElement.scrollTop || document.body.scrollTop) > (distance || 500) ? 'block' : 'none';
}
function throttle(func, wait) {
var timer = null;
return function () {
var self = this, args = arguments;
if (timer) clearTimeout(timer);
timer = setTimeout(function () {
return typeof func === 'function' && func.apply(self, args);
}, wait);
}
}
};
function init() {
backTop(document.getElementById('js-jump-container'), document.getElementById('container'));
backTop(document.getElementById('js-jump-container'), document.getElementById('container'));
}
export default { init }

View File

@ -1,20 +1,18 @@
var browser = {
versions: function() {
var u = window.navigator.userAgent;
return {
trident: u.indexOf('Trident') > -1, //IE内核
presto: u.indexOf('Presto') > -1, //opera内核
webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者安卓QQ浏览器
iPad: u.indexOf('iPad') > -1, //是否为iPad
webApp: u.indexOf('Safari') == -1, //是否为web应用程序没有头部与底部
weixin: u.indexOf('MicroMessenger') == -1 //是否为微信浏览器
};
}()
export default {
versions: function() {
var u = window.navigator.userAgent;
return {
trident: u.indexOf('Trident') > -1, //IE内核
presto: u.indexOf('Presto') > -1, //opera内核
webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者安卓QQ浏览器
iPad: u.indexOf('iPad') > -1, //是否为iPad
webApp: u.indexOf('Safari') == -1, //是否为web应用程序没有头部与底部
weixin: u.indexOf('MicroMessenger') == -1 //是否为微信浏览器
};
}()
}
module.exports = browser

View File

@ -21,19 +21,10 @@ function init() {
// 目录序号
if (yiliaConfig && yiliaConfig.toc_hide_index) {
let $a = document.querySelectorAll(('.toc-number'))
$a.forEach(($em) => {
Array.prototype.forEach.call($a, function($em){
$em.style.display = 'none';
})
}
// about me 转义
var $aboutme = document.querySelector('#js-aboutme')
if ($aboutme && $aboutme.length !== 0) {
$aboutme.innerHTML = $aboutme.innerText
}
}
module.exports = {
init: init
}
export default { init }

View File

@ -1,7 +1,5 @@
// 样式
import '../css/main.scss'
// 上报
// import './report'
// 图片查看器
import Viewer from './viewer'
// 分享
@ -9,9 +7,9 @@ import Share from './share'
// 边缘
import Aside from './aside'
import {addLoadEvent} from './util'
import Util from './util'
addLoadEvent(function() {
Util.addLoadEvent(function() {
Share.init()
Viewer.init()
Aside.init()

View File

@ -6,7 +6,7 @@ import Browser from './browser'
// fix hexo 不支持的配置
import Fix from './fix'
import {addLoadEvent} from './util'
import Util from './util'
function isPathMatch(path, href) {
let reg = /\/|index.html/g
@ -16,13 +16,11 @@ function isPathMatch(path, href) {
function tabActive() {
let $tabs = document.querySelectorAll('.js-header-menu li a')
let path = window.location.pathname
for (var i = 0, len = $tabs.length; i < len; i++) {
let $tab = $tabs[i]
Array.prototype.forEach.call($tabs, function($tab, i){
if (isPathMatch(path, $tab.getAttribute('href'))) {
addClass($tab, 'active')
}
}
})
}
function getElementLeft(element) {    
@ -99,6 +97,6 @@ function init() {
init();
addLoadEvent(function() {
Util.addLoadEvent(function() {
Fix.init()
})

View File

@ -2,78 +2,74 @@ import addClass from 'dom101/add-class'
import removeClass from 'dom101/remove-class'
function generate(url, opts) {
var url = url.replace(/<%-sUrl%>/g, encodeURIComponent(opts.sUrl))
.replace(/<%-sTitle%>/g, opts.sTitle)
.replace(/<%-sDesc%>/g, opts.sDesc)
.replace(/<%-sPic%>/g, encodeURIComponent(opts.sPic));
var url = url.replace(/<%-sUrl%>/g, encodeURIComponent(opts.sUrl))
.replace(/<%-sTitle%>/g, opts.sTitle)
.replace(/<%-sDesc%>/g, opts.sDesc)
.replace(/<%-sPic%>/g, encodeURIComponent(opts.sPic));
window.open(url);
window.open(url);
}
function showWX() {
let $wx = document.querySelector('.js-wx-box')
let $mask = document.querySelector('.mask')
addClass($wx, 'in')
addClass($wx, 'ready')
addClass($mask, 'in')
let $wx = document.querySelector('.js-wx-box')
let $mask = document.querySelector('.mask')
addClass($wx, 'in')
addClass($wx, 'ready')
addClass($mask, 'in')
}
function hideWX() {
let $wx = document.querySelector('.js-wx-box')
let $mask = document.querySelector('.mask')
removeClass($wx, 'in')
removeClass($wx, 'ready')
removeClass($mask, 'in')
let $wx = document.querySelector('.js-wx-box')
let $mask = document.querySelector('.mask')
removeClass($wx, 'in')
removeClass($wx, 'ready')
removeClass($mask, 'in')
}
function handleClick(type, opts) {
if (type === 'weibo') {
generate('http://service.weibo.com/share/share.php?url=<%-sUrl%>&title=<%-sTitle%>&pic=<%-sPic%>', opts)
} else if (type === 'qq') {
generate('http://connect.qq.com/widget/shareqq/index.html?url=<%-sUrl%>&title=<%-sTitle%>&source=<%-sDesc%>', opts)
} else if (type === 'douban') {
generate('https://www.douban.com/share/service?image=<%-sPic%>&href=<%-sUrl%>&name=<%-sTitle%>&text=<%-sDesc%>', opts)
} else if (type === 'qzone') {
generate('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=<%-sUrl%>&title=<%-sTitle%>&pics=<%-sPic%>&summary=<%-sDesc%>', opts)
} else if (type === 'facebook') {
generate('https://www.facebook.com/sharer/sharer.php?u=<%-sUrl%>', opts)
} else if (type === 'twitter') {
generate('https://twitter.com/intent/tweet?text=<%-sTitle%>&url=<%-sUrl%>&via=<%-config.url%>', opts)
} else if (type === 'google') {
generate('https://plus.google.com/share?url=<%-sUrl%>', opts)
} else if (type === 'weixin') {
showWX();
}
if (type === 'weibo') {
generate('http://service.weibo.com/share/share.php?url=<%-sUrl%>&title=<%-sTitle%>&pic=<%-sPic%>', opts)
} else if (type === 'qq') {
generate('http://connect.qq.com/widget/shareqq/index.html?url=<%-sUrl%>&title=<%-sTitle%>&source=<%-sDesc%>', opts)
} else if (type === 'douban') {
generate('https://www.douban.com/share/service?image=<%-sPic%>&href=<%-sUrl%>&name=<%-sTitle%>&text=<%-sDesc%>', opts)
} else if (type === 'qzone') {
generate('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=<%-sUrl%>&title=<%-sTitle%>&pics=<%-sPic%>&summary=<%-sDesc%>', opts)
} else if (type === 'facebook') {
generate('https://www.facebook.com/sharer/sharer.php?u=<%-sUrl%>', opts)
} else if (type === 'twitter') {
generate('https://twitter.com/intent/tweet?text=<%-sTitle%>&url=<%-sUrl%>&via=<%-config.url%>', opts)
} else if (type === 'google') {
generate('https://plus.google.com/share?url=<%-sUrl%>', opts)
} else if (type === 'weixin') {
showWX();
}
}
let init = function() {
let $sns = document.querySelectorAll('.share-sns');
if (!$sns || $sns.length === 0) return;
let $sns = document.querySelectorAll('.share-sns');
if (!$sns || $sns.length === 0) return;
let sUrl = window.location.href;
let sTitle = document.querySelector('title').innerHTML;
let $img = document.querySelectorAll('.article-entry img');
let sPic = $img.length ? document.querySelector('.article-entry img').getAttribute('src') : '';
if ((sPic !== '') && !/^(http:|https:)?\/\//.test(sPic)) {
sPic = window.location.origin + sPic
let sUrl = window.location.href;
let sTitle = document.querySelector('title').innerHTML;
let $img = document.querySelectorAll('.article-entry img');
let sPic = $img.length ? document.querySelector('.article-entry img').getAttribute('src') : '';
if ((sPic !== '') && !/^(http:|https:)?\/\//.test(sPic)) {
sPic = window.location.origin + sPic
}
Array.prototype.forEach.call($sns, ($em) => {
$em.onclick = (e) => {
let type = $em.getAttribute('data-type')
handleClick(type, {
sUrl: sUrl,
sPic: sPic,
sTitle: sTitle,
sDesc: sTitle
})
}
$sns.forEach(($em) => {
$em.onclick = (e) => {
let type = $em.getAttribute('data-type')
handleClick(type, {
sUrl: sUrl,
sPic: sPic,
sTitle: sTitle,
sDesc: sTitle
})
}
})
document.querySelector('.mask').onclick = hideWX
document.querySelector('.js-modal-close').onclick = hideWX
})
document.querySelector('.mask').onclick = hideWX
document.querySelector('.js-modal-close').onclick = hideWX
}
module.exports = {
init: init
}
export default { init }

View File

@ -15,7 +15,7 @@ function fixzero(str) {
function setScrollZero() {
let $sct = document.querySelectorAll('.tools-section')
$sct.forEach((em) => {
Array.prototype.forEach.call($sct, (em) => {
em.scrollTop = 0
})
}

View File

@ -1,89 +1,89 @@
var e = function() {
function r(e, r, n) {
return r || n ? String.fromCharCode(r || n) : u[e] || e
}
function n(e) {
return p[e]
}
var t = /&quot;|&lt;|&gt;|&amp;|&nbsp;|&apos;|&#(\d+);|&#(\d+)/g
, o = /['<> "&]/g
, u = {
"&quot;": '"',
"&lt;": "<",
"&gt;": ">",
"&amp;": "&",
"&nbsp;": " "
}
, c = /\u00a0/g
, a = /<br\s*\/?>/gi
, i = /\r?\n/g
, f = /\s/g
, p = {};
for (var s in u)
p[u[s]] = s;
return u["&apos;"] = "'",
p["'"] = "&#39;",
{
encode: function(e) {
return e ? ("" + e).replace(o, n).replace(i, "<br/>").replace(f, "&nbsp;") : ""
},
decode: function(e) {
return e ? ("" + e).replace(a, "\n").replace(t, r).replace(c, " ") : ""
},
encodeBase16: function(e) {
if (!e)
return e;
e += "";
for (var r = [], n = 0, t = e.length; t > n; n++)
r.push(e.charCodeAt(n).toString(16).toUpperCase());
return r.join("")
},
encodeBase16forJSON: function(e) {
if (!e)
return e;
e = e.replace(/[\u4E00-\u9FBF]/gi, function(e) {
return escape(e).replace("%u", "\\u")
});
for (var r = [], n = 0, t = e.length; t > n; n++)
r.push(e.charCodeAt(n).toString(16).toUpperCase());
return r.join("")
},
decodeBase16: function(e) {
if (!e)
return e;
e += "";
for (var r = [], n = 0, t = e.length; t > n; n += 2)
r.push(String.fromCharCode("0x" + e.slice(n, n + 2)));
return r.join("")
},
encodeObject: function(r) {
if (r instanceof Array)
for (var n = 0, t = r.length; t > n; n++)
r[n] = e.encodeObject(r[n]);
else if ("object" == typeof r)
for (var o in r)
r[o] = e.encodeObject(r[o]);
else if ("string" == typeof r)
return e.encode(r);
return r
},
loadScript: function(path) {
var $script = document.createElement('script')
document.getElementsByTagName('body')[0].appendChild($script)
$script.setAttribute('src', path)
},
addLoadEvent: function(func){
var oldonload = window.onload;
if (typeof window.onload!="function") {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}
}
const Util = (function(){
function r(e, r, n) {
return r || n ? String.fromCharCode(r || n) : u[e] || e
}
function n(e) {
return p[e]
}
var t = /&quot;|&lt;|&gt;|&amp;|&nbsp;|&apos;|&#(\d+);|&#(\d+)/g
, o = /['<> "&]/g
, u = {
"&quot;": '"',
"&lt;": "<",
"&gt;": ">",
"&amp;": "&",
"&nbsp;": " "
}
, c = /\u00a0/g
, a = /<br\s*\/?>/gi
, i = /\r?\n/g
, f = /\s/g
, p = {};
for (var s in u)
p[u[s]] = s;
return u["&apos;"] = "'",
p["'"] = "&#39;",
{
encode: function(e) {
return e ? ("" + e).replace(o, n).replace(i, "<br/>").replace(f, "&nbsp;") : ""
},
decode: function(e) {
return e ? ("" + e).replace(a, "\n").replace(t, r).replace(c, " ") : ""
},
encodeBase16: function(e) {
if (!e)
return e;
e += "";
for (var r = [], n = 0, t = e.length; t > n; n++)
r.push(e.charCodeAt(n).toString(16).toUpperCase());
return r.join("")
},
encodeBase16forJSON: function(e) {
if (!e)
return e;
e = e.replace(/[\u4E00-\u9FBF]/gi, function(e) {
return escape(e).replace("%u", "\\u")
});
for (var r = [], n = 0, t = e.length; t > n; n++)
r.push(e.charCodeAt(n).toString(16).toUpperCase());
return r.join("")
},
decodeBase16: function(e) {
if (!e)
return e;
e += "";
for (var r = [], n = 0, t = e.length; t > n; n += 2)
r.push(String.fromCharCode("0x" + e.slice(n, n + 2)));
return r.join("")
},
encodeObject: function(r) {
if (r instanceof Array)
for (var n = 0, t = r.length; t > n; n++)
r[n] = e.encodeObject(r[n]);
else if ("object" == typeof r)
for (var o in r)
r[o] = e.encodeObject(r[o]);
else if ("string" == typeof r)
return e.encode(r);
return r
},
loadScript: function(path) {
var $script = document.createElement('script')
document.getElementsByTagName('body')[0].appendChild($script)
$script.setAttribute('src', path)
},
addLoadEvent: function(func){
var oldonload = window.onload;
if (typeof window.onload !== "function") {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}
}
}
}();
}
})();
module.exports = e
export default Util

View File

@ -10,14 +10,12 @@ window.PhotoSwipeUI_Default = PhotoSwipeUI_Default
function init() {
let pswpElement = document.querySelectorAll('.pswp')[0];
let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))
$imgArr.forEach(($em, i) => {
Array.prototype.forEach.call($imgArr, ($em, i) => {
$em.onclick = () => {
// slider展开状态
// todo: 这样不好,后面改成状态
if (document.querySelector('.left-col.show')) return
let items = []
$imgArr.forEach(($em2, i2) => {
Array.prototype.forEach.call($imgArr, ($em2, i2) => {
let img = $em2.getAttribute('data-idx', i2)
let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
let title = $em2.getAttribute('alt')
@ -40,6 +38,4 @@ function init() {
})
}
module.exports = {
init: init
}
export default { init }