🚀 refactor: code
This commit is contained in:
157
source-src/js/ayer.js
Normal file
157
source-src/js/ayer.js
Normal file
@@ -0,0 +1,157 @@
|
||||
(function ($) {
|
||||
// Search
|
||||
let $searchWrap = $('.search-form-wrap'),
|
||||
isSearchAnim = false,
|
||||
searchAnimDuration = 200;
|
||||
|
||||
const startSearchAnim = () => {
|
||||
isSearchAnim = true;
|
||||
};
|
||||
|
||||
const stopSearchAnim = (callback) => {
|
||||
setTimeout(function () {
|
||||
isSearchAnim = false;
|
||||
callback && callback();
|
||||
}, searchAnimDuration);
|
||||
};
|
||||
|
||||
$('.nav-item-search').click(() => {
|
||||
if (isSearchAnim) return;
|
||||
startSearchAnim();
|
||||
$searchWrap.addClass('on');
|
||||
stopSearchAnim(function () {
|
||||
$('.local-search-input').focus();
|
||||
});
|
||||
});
|
||||
|
||||
$(document).mouseup((e) => {
|
||||
const _con = $('.local-search');
|
||||
if (!_con.is(e.target) && _con.has(e.target).length === 0) {
|
||||
$searchWrap.removeClass('on');
|
||||
}
|
||||
});
|
||||
|
||||
// Mobile Detect
|
||||
const isMobile = {
|
||||
Android: function () {
|
||||
return navigator.userAgent.match(/Android/i);
|
||||
},
|
||||
BlackBerry: function () {
|
||||
return navigator.userAgent.match(/BlackBerry/i);
|
||||
},
|
||||
iOS: function () {
|
||||
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
|
||||
},
|
||||
Opera: function () {
|
||||
return navigator.userAgent.match(/Opera Mini/i);
|
||||
},
|
||||
Windows: function () {
|
||||
return navigator.userAgent.match(/IEMobile/i);
|
||||
},
|
||||
any: function () {
|
||||
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
|
||||
}
|
||||
};
|
||||
|
||||
// Share
|
||||
$('.share-outer').click(() => $('.share-wrap').fadeToggle())
|
||||
|
||||
// Lazyload
|
||||
$("img.lazy").lazyload({
|
||||
effect: "fadeIn"
|
||||
});
|
||||
|
||||
// JustifiedGallery
|
||||
$('#gallery').justifiedGallery({
|
||||
rowHeight: 200,
|
||||
margins: 5
|
||||
});
|
||||
|
||||
// ScrollDown
|
||||
$(document).ready(function ($) {
|
||||
$('.anchor').click(function (e) {
|
||||
e.preventDefault();
|
||||
$('main').animate({ scrollTop: $('.cover').height() }, 'smooth');
|
||||
});
|
||||
});
|
||||
|
||||
// To Top
|
||||
(() => {
|
||||
// When to show the scroll link
|
||||
// higher number = scroll link appears further down the page
|
||||
const upperLimit = 1000;
|
||||
|
||||
// Our scroll link element
|
||||
const scrollElem = $('#totop');
|
||||
|
||||
// Scroll to top speed
|
||||
const scrollSpeed = 1600;
|
||||
|
||||
// Show and hide the scroll to top link based on scroll position
|
||||
scrollElem.hide();
|
||||
$('.content').scroll(function () {
|
||||
const scrollTop = $('.content').scrollTop();
|
||||
if (scrollTop > upperLimit) {
|
||||
$(scrollElem).stop().fadeTo(200, .6); // fade back in
|
||||
} else {
|
||||
$(scrollElem).stop().fadeTo(200, 0); // fade out
|
||||
}
|
||||
});
|
||||
|
||||
// Scroll to top animation on click
|
||||
$(scrollElem).click(function () {
|
||||
$('.content').animate({ scrollTop: 0 }, scrollSpeed); return false;
|
||||
});
|
||||
})();
|
||||
|
||||
// Mobile Nav
|
||||
const $content = $('.content'),
|
||||
$sidebar = $('.sidebar');
|
||||
|
||||
$('.navbar-toggle').on('click', function () {
|
||||
$content.toggleClass('on');
|
||||
$sidebar.toggleClass('on');
|
||||
});
|
||||
|
||||
$content.click(() => {
|
||||
$content.removeClass('on');
|
||||
$sidebar.removeClass('on');
|
||||
});
|
||||
|
||||
if (window.matchMedia("(min-width: 768px)").matches) {
|
||||
$content.addClass('on');
|
||||
$sidebar.addClass('on');
|
||||
}
|
||||
|
||||
// Reward
|
||||
$('#reward-btn').click(() => {
|
||||
$('#reward').fadeIn(150)
|
||||
$('#mask').fadeIn(150)
|
||||
});
|
||||
$('#reward .close, #mask').click(() => {
|
||||
$('#mask').fadeOut(100)
|
||||
$('#reward').fadeOut(100)
|
||||
})
|
||||
|
||||
// DarkMode
|
||||
if (sessionStorage.getItem('darkmode') == 1) {
|
||||
$('body').addClass('darkmode')
|
||||
$('#todark i').removeClass('ri-moon-line').addClass('ri-sun-line')
|
||||
} else {
|
||||
$('body').removeClass('darkmode')
|
||||
$('#todark i').removeClass('ri-sun-line').addClass('ri-moon-line')
|
||||
}
|
||||
$('#todark').click(() => {
|
||||
if (sessionStorage.getItem('darkmode') == 1) {
|
||||
$('body').removeClass('darkmode')
|
||||
$('#todark i').removeClass('ri-sun-line').addClass('ri-moon-line')
|
||||
sessionStorage.removeItem('darkmode')
|
||||
} else {
|
||||
$('body').addClass('darkmode')
|
||||
$('#todark i').removeClass('ri-moon-line').addClass('ri-sun-line')
|
||||
sessionStorage.setItem('darkmode', 1)
|
||||
}
|
||||
})
|
||||
})(jQuery);
|
||||
|
||||
|
67
source-src/js/share.js
Normal file
67
source-src/js/share.js
Normal file
@@ -0,0 +1,67 @@
|
||||
|
||||
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));
|
||||
|
||||
window.open(url);
|
||||
}
|
||||
|
||||
function showWX() {
|
||||
$('.wx-share-modal').addClass('in ready')
|
||||
$('#share-mask').show()
|
||||
}
|
||||
|
||||
function hideWX() {
|
||||
$('.wx-share-modal').removeClass('in ready')
|
||||
$('#share-mask').hide()
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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');
|
||||
let sPic = $img.length ? document.querySelector('.article-entry img').getAttribute('src') : '';
|
||||
if ((sPic !== '') && !/^(http:|https:)?\/\//.test(sPic)) {
|
||||
sPic = window.location.origin + sPic
|
||||
}
|
||||
$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('.modal-close').onclick = hideWX
|
||||
}
|
||||
|
||||
share_init()
|
Reference in New Issue
Block a user