🚀 refactor: code
This commit is contained in:
parent
1003d95815
commit
ebe1e25719
@ -1,5 +1,4 @@
|
||||
<%- js('/js/jquery-2.0.3.min') %>
|
||||
<%- js('/js/share') %>
|
||||
<%- js('/js/lazyload.min') %>
|
||||
<% if (theme.subtitle.enable){ %>
|
||||
<script>
|
||||
@ -46,7 +45,7 @@
|
||||
<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
|
||||
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>
|
||||
<%- js('js/ayer') %>
|
||||
<%- js('dist/main') %>
|
||||
|
||||
<% if (theme.image_viewer){ %>
|
||||
<%- partial('viewer') %>
|
||||
|
@ -23,7 +23,7 @@
|
||||
<% if (theme.favicon){ %>
|
||||
<link rel="shortcut icon" href="<%- theme.favicon %>" />
|
||||
<% } %>
|
||||
<%- css('css/main') %>
|
||||
<%- css('dist/main') %>
|
||||
<% if (theme.progressBar){ %>
|
||||
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>
|
||||
<% } %>
|
||||
|
@ -3,8 +3,8 @@
|
||||
"version": "1.0.0",
|
||||
"description": "a clean and elegant theme for hexo.",
|
||||
"scripts": {
|
||||
"dev": "parcel serve source-src/main.js -d source/css",
|
||||
"build": "parcel build source-src/main.js -d source/css --no-source-maps"
|
||||
"dev": "parcel serve source-src/main.js -d source/dist",
|
||||
"build": "parcel build source-src/main.js -d source/dist --no-source-maps"
|
||||
},
|
||||
"source": "source-src/main.js",
|
||||
"repository": {
|
||||
|
@ -1,21 +1,21 @@
|
||||
(function ($) {
|
||||
// Search
|
||||
var $searchWrap = $('.search-form-wrap'),
|
||||
let $searchWrap = $('.search-form-wrap'),
|
||||
isSearchAnim = false,
|
||||
searchAnimDuration = 200;
|
||||
|
||||
var startSearchAnim = function () {
|
||||
const startSearchAnim = () => {
|
||||
isSearchAnim = true;
|
||||
};
|
||||
|
||||
var stopSearchAnim = function (callback) {
|
||||
const stopSearchAnim = (callback) => {
|
||||
setTimeout(function () {
|
||||
isSearchAnim = false;
|
||||
callback && callback();
|
||||
}, searchAnimDuration);
|
||||
};
|
||||
|
||||
$('.nav-item-search').on('click', function () {
|
||||
$('.nav-item-search').click(() => {
|
||||
if (isSearchAnim) return;
|
||||
startSearchAnim();
|
||||
$searchWrap.addClass('on');
|
||||
@ -24,15 +24,15 @@
|
||||
});
|
||||
});
|
||||
|
||||
$(document).mouseup(function (e) {
|
||||
var _con = $('.local-search');
|
||||
$(document).mouseup((e) => {
|
||||
const _con = $('.local-search');
|
||||
if (!_con.is(e.target) && _con.has(e.target).length === 0) {
|
||||
$searchWrap.removeClass('on');
|
||||
}
|
||||
});
|
||||
|
||||
// 移动设备侦测
|
||||
var isMobile = {
|
||||
// Mobile Detect
|
||||
const isMobile = {
|
||||
Android: function () {
|
||||
return navigator.userAgent.match(/Android/i);
|
||||
},
|
||||
@ -53,28 +53,21 @@
|
||||
}
|
||||
};
|
||||
|
||||
// 建议在移动端不初始化,其实 /search.xml 文件还挺大的,
|
||||
if ($('.local-search').size()) {
|
||||
$.getScript('/js/search.js', function () {
|
||||
searchFunc("/search.xml", 'local-search-input', 'local-search-result');
|
||||
});
|
||||
}
|
||||
|
||||
// Share
|
||||
$('.share-outer').click(() => $('.share-wrap').fadeToggle())
|
||||
|
||||
// lazyload
|
||||
// Lazyload
|
||||
$("img.lazy").lazyload({
|
||||
effect: "fadeIn"
|
||||
});
|
||||
|
||||
// justifiedGallery
|
||||
// JustifiedGallery
|
||||
$('#gallery').justifiedGallery({
|
||||
rowHeight: 200,
|
||||
margins: 5
|
||||
});
|
||||
|
||||
// scroll down
|
||||
// ScrollDown
|
||||
$(document).ready(function ($) {
|
||||
$('.anchor').click(function (e) {
|
||||
e.preventDefault();
|
||||
@ -82,22 +75,22 @@
|
||||
});
|
||||
});
|
||||
|
||||
// To top
|
||||
(function ($) {
|
||||
// To Top
|
||||
(() => {
|
||||
// When to show the scroll link
|
||||
// higher number = scroll link appears further down the page
|
||||
var upperLimit = 1000;
|
||||
const upperLimit = 1000;
|
||||
|
||||
// Our scroll link element
|
||||
var scrollElem = $('#totop');
|
||||
const scrollElem = $('#totop');
|
||||
|
||||
// Scroll to top speed
|
||||
var scrollSpeed = 1600;
|
||||
const scrollSpeed = 1600;
|
||||
|
||||
// Show and hide the scroll to top link based on scroll position
|
||||
scrollElem.hide();
|
||||
$('.content').scroll(function () {
|
||||
var scrollTop = $('.content').scrollTop();
|
||||
const scrollTop = $('.content').scrollTop();
|
||||
if (scrollTop > upperLimit) {
|
||||
$(scrollElem).stop().fadeTo(200, .6); // fade back in
|
||||
} else {
|
||||
@ -109,10 +102,10 @@
|
||||
$(scrollElem).click(function () {
|
||||
$('.content').animate({ scrollTop: 0 }, scrollSpeed); return false;
|
||||
});
|
||||
})(jQuery);
|
||||
})();
|
||||
|
||||
// Mobile nav
|
||||
var $content = $('.content'),
|
||||
// Mobile Nav
|
||||
const $content = $('.content'),
|
||||
$sidebar = $('.sidebar');
|
||||
|
||||
$('.navbar-toggle').on('click', function () {
|
||||
@ -120,7 +113,7 @@
|
||||
$sidebar.toggleClass('on');
|
||||
});
|
||||
|
||||
$($content).on('click', function () {
|
||||
$content.click(() => {
|
||||
$content.removeClass('on');
|
||||
$sidebar.removeClass('on');
|
||||
});
|
||||
@ -130,33 +123,33 @@
|
||||
$sidebar.addClass('on');
|
||||
}
|
||||
|
||||
// reward
|
||||
$('#reward-btn').on('click', function () {
|
||||
// Reward
|
||||
$('#reward-btn').click(() => {
|
||||
$('#reward').fadeIn(150)
|
||||
$('#mask').fadeIn(150)
|
||||
});
|
||||
$('#reward .close, #mask').on('click', function () {
|
||||
$('#reward .close, #mask').click(() => {
|
||||
$('#mask').fadeOut(100)
|
||||
$('#reward').fadeOut(100)
|
||||
})
|
||||
|
||||
// darkmode
|
||||
if(sessionStorage.getItem('darkmode')==1){
|
||||
// DarkMode
|
||||
if (sessionStorage.getItem('darkmode') == 1) {
|
||||
$('body').addClass('darkmode')
|
||||
$('#todark i').removeClass('ri-moon-line').addClass('ri-sun-line')
|
||||
}else{
|
||||
} else {
|
||||
$('body').removeClass('darkmode')
|
||||
$('#todark i').removeClass('ri-sun-line').addClass('ri-moon-line')
|
||||
}
|
||||
$('#todark').click(()=>{
|
||||
if(sessionStorage.getItem('darkmode')==1){
|
||||
$('#todark').click(() => {
|
||||
if (sessionStorage.getItem('darkmode') == 1) {
|
||||
$('body').removeClass('darkmode')
|
||||
$('#todark i').removeClass('ri-sun-line').addClass('ri-moon-line')
|
||||
sessionStorage.removeItem('darkmode')
|
||||
}else{
|
||||
} else {
|
||||
$('body').addClass('darkmode')
|
||||
$('#todark i').removeClass('ri-moon-line').addClass('ri-sun-line')
|
||||
sessionStorage.setItem('darkmode',1)
|
||||
sessionStorage.setItem('darkmode', 1)
|
||||
}
|
||||
})
|
||||
})(jQuery);
|
@ -9,19 +9,13 @@ function generate(url, opts) {
|
||||
}
|
||||
|
||||
function showWX() {
|
||||
let $wx = $('.wx-share-modal')
|
||||
let $mask = $('#share-mask')
|
||||
$wx.addClass('in')
|
||||
$wx.addClass('ready')
|
||||
$mask.show()
|
||||
$('.wx-share-modal').addClass('in ready')
|
||||
$('#share-mask').show()
|
||||
}
|
||||
|
||||
function hideWX() {
|
||||
let $wx = $('.wx-share-modal')
|
||||
let $mask = $('#share-mask')
|
||||
$wx.removeClass('in')
|
||||
$wx.removeClass('ready')
|
||||
$mask.hide()
|
||||
$('.wx-share-modal').removeClass('in ready')
|
||||
$('#share-mask').hide()
|
||||
}
|
||||
|
||||
function handleClick(type, opts) {
|
||||
@ -44,10 +38,9 @@ function handleClick(type, opts) {
|
||||
}
|
||||
}
|
||||
|
||||
let init = function () {
|
||||
const share_init = () => {
|
||||
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');
|
||||
@ -55,7 +48,6 @@ let init = function () {
|
||||
if ((sPic !== '') && !/^(http:|https:)?\/\//.test(sPic)) {
|
||||
sPic = window.location.origin + sPic
|
||||
}
|
||||
|
||||
$sns.forEach(($em) => {
|
||||
$em.onclick = (e) => {
|
||||
let type = $em.getAttribute('data-type')
|
||||
@ -72,4 +64,4 @@ let init = function () {
|
||||
document.querySelector('.modal-close').onclick = hideWX
|
||||
}
|
||||
|
||||
init()
|
||||
share_init()
|
@ -1 +1,3 @@
|
||||
import './css/style.styl'
|
||||
import './js/ayer'
|
||||
import './js/share'
|
@ -1,5 +0,0 @@
|
||||
parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"MiQR":[function(require,module,exports) {
|
||||
|
||||
},{}],"epB2":[function(require,module,exports) {
|
||||
"use strict";require("./css/style.styl");
|
||||
},{"./css/style.styl":"MiQR"}]},{},["epB2"], null)
|
9
source/dist/main.js
vendored
Normal file
9
source/dist/main.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"MiQR":[function(require,module,exports) {
|
||||
|
||||
},{}],"jSg4":[function(require,module,exports) {
|
||||
!function(e){var o=e(".search-form-wrap"),a=!1;e(".nav-item-search").click(function(){var n;a||(a=!0,o.addClass("on"),n=function(){e(".local-search-input").focus()},setTimeout(function(){a=!1,n&&n()},200))}),e(document).mouseup(function(a){var n=e(".local-search");n.is(a.target)||0!==n.has(a.target).length||o.removeClass("on")});var n;e(".share-outer").click(function(){return e(".share-wrap").fadeToggle()}),e("img.lazy").lazyload({effect:"fadeIn"}),e("#gallery").justifiedGallery({rowHeight:200,margins:5}),e(document).ready(function(e){e(".anchor").click(function(o){o.preventDefault(),e("main").animate({scrollTop:e(".cover").height()},"smooth")})}),(n=e("#totop")).hide(),e(".content").scroll(function(){e(".content").scrollTop()>1e3?e(n).stop().fadeTo(200,.6):e(n).stop().fadeTo(200,0)}),e(n).click(function(){return e(".content").animate({scrollTop:0},1600),!1});var s=e(".content"),r=e(".sidebar");e(".navbar-toggle").on("click",function(){s.toggleClass("on"),r.toggleClass("on")}),s.click(function(){s.removeClass("on"),r.removeClass("on")}),window.matchMedia("(min-width: 768px)").matches&&(s.addClass("on"),r.addClass("on")),e("#reward-btn").click(function(){e("#reward").fadeIn(150),e("#mask").fadeIn(150)}),e("#reward .close, #mask").click(function(){e("#mask").fadeOut(100),e("#reward").fadeOut(100)}),1==sessionStorage.getItem("darkmode")?(e("body").addClass("darkmode"),e("#todark i").removeClass("ri-moon-line").addClass("ri-sun-line")):(e("body").removeClass("darkmode"),e("#todark i").removeClass("ri-sun-line").addClass("ri-moon-line")),e("#todark").click(function(){1==sessionStorage.getItem("darkmode")?(e("body").removeClass("darkmode"),e("#todark i").removeClass("ri-sun-line").addClass("ri-moon-line"),sessionStorage.removeItem("darkmode")):(e("body").addClass("darkmode"),e("#todark i").removeClass("ri-moon-line").addClass("ri-sun-line"),sessionStorage.setItem("darkmode",1))})}(jQuery);
|
||||
},{}],"BNiz":[function(require,module,exports) {
|
||||
function e(e,t){e=e.replace(/<%-sUrl%>/g,encodeURIComponent(t.sUrl)).replace(/<%-sTitle%>/g,t.sTitle).replace(/<%-sDesc%>/g,t.sDesc).replace(/<%-sPic%>/g,encodeURIComponent(t.sPic));window.open(e)}function t(){$(".wx-share-modal").addClass("in ready"),$("#share-mask").show()}function s(){$(".wx-share-modal").removeClass("in ready"),$("#share-mask").hide()}function r(s,r){"weibo"===s?e("http://service.weibo.com/share/share.php?url=<%-sUrl%>&title=<%-sTitle%>&pic=<%-sPic%>",r):"qq"===s?e("http://connect.qq.com/widget/shareqq/index.html?url=<%-sUrl%>&title=<%-sTitle%>&source=<%-sDesc%>",r):"douban"===s?e("https://www.douban.com/share/service?image=<%-sPic%>&href=<%-sUrl%>&name=<%-sTitle%>&text=<%-sDesc%>",r):"qzone"===s?e("http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=<%-sUrl%>&title=<%-sTitle%>&pics=<%-sPic%>&summary=<%-sDesc%>",r):"facebook"===s?e("https://www.facebook.com/sharer/sharer.php?u=<%-sUrl%>",r):"twitter"===s?e("https://twitter.com/intent/tweet?text=<%-sTitle%>&url=<%-sUrl%>&via=<%-config.url%>",r):"google"===s?e("https://plus.google.com/share?url=<%-sUrl%>",r):"weixin"===s&&t()}var c=function(){var e=document.querySelectorAll(".share-sns");if(e&&0!==e.length){var t=window.location.href,c=document.querySelector("title").innerHTML,o=document.querySelectorAll(".article-entry img").length?document.querySelector(".article-entry img").getAttribute("src"):"";""===o||/^(http:|https:)?\/\//.test(o)||(o=window.location.origin+o),e.forEach(function(e){e.onclick=function(s){r(e.getAttribute("data-type"),{sUrl:t,sPic:o,sTitle:c,sDesc:c})}}),document.querySelector("#mask").onclick=s,document.querySelector(".modal-close").onclick=s}};c();
|
||||
},{}],"epB2":[function(require,module,exports) {
|
||||
"use strict";require("./css/style.styl"),require("./js/ayer"),require("./js/share");
|
||||
},{"./css/style.styl":"MiQR","./js/ayer":"jSg4","./js/share":"BNiz"}]},{},["epB2"], null)
|
Loading…
Reference in New Issue
Block a user