2019-12-03 11:37:44 +00:00
|
|
|
(function ($) {
|
|
|
|
//
|
|
|
|
// Search ------------
|
|
|
|
var $searchWrap = $('.search-form-wrap'),
|
|
|
|
isSearchAnim = false,
|
|
|
|
searchAnimDuration = 200;
|
|
|
|
|
|
|
|
var startSearchAnim = function () {
|
|
|
|
isSearchAnim = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
var stopSearchAnim = function (callback) {
|
|
|
|
setTimeout(function () {
|
|
|
|
isSearchAnim = false;
|
|
|
|
callback && callback();
|
|
|
|
}, searchAnimDuration);
|
|
|
|
};
|
|
|
|
|
|
|
|
$('.nav-item-search').on('click', function () {
|
|
|
|
if (isSearchAnim) return;
|
|
|
|
startSearchAnim();
|
|
|
|
$searchWrap.addClass('on');
|
|
|
|
stopSearchAnim(function () {
|
|
|
|
$('.local-search-input').focus();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).mouseup(function (e) {
|
|
|
|
var _con = $('.local-search');
|
|
|
|
if (!_con.is(e.target) && _con.has(e.target).length === 0) {
|
|
|
|
$searchWrap.removeClass('on');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
//
|
|
|
|
// 移动设备侦测
|
|
|
|
var 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());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// 建议在移动端不初始化,其实 /search.xml 文件还挺大的,
|
|
|
|
if ($('.local-search').size() && !isMobile.any()) {
|
|
|
|
$.getScript('/js/search.js', function () {
|
|
|
|
searchFunc("/search.xml", 'local-search-input', 'local-search-result');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Share
|
|
|
|
$('body').on('click', function () {
|
|
|
|
$('.article-share-box.on').removeClass('on');
|
|
|
|
}).on('click', '.article-share-link', function (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
var $this = $(this),
|
|
|
|
url = $this.attr('data-url'),
|
|
|
|
encodedUrl = encodeURIComponent(url),
|
|
|
|
id = 'article-share-box-' + $this.attr('data-id'),
|
|
|
|
offset = $this.offset();
|
|
|
|
|
|
|
|
if ($('#' + id).length) {
|
|
|
|
var box = $('#' + id);
|
|
|
|
|
|
|
|
if (box.hasClass('on')) {
|
|
|
|
box.removeClass('on');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var html = [
|
|
|
|
'<div id="' + id + '" class="article-share-box">',
|
|
|
|
'<input class="article-share-input" value="' + url + '">',
|
|
|
|
'<div class="article-share-links">',
|
|
|
|
'<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="article-share-twitter" target="_blank" title="Twitter"></a>',
|
|
|
|
'<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="article-share-facebook" target="_blank" title="Facebook"></a>',
|
|
|
|
'<a href="http://pinterest.com/pin/create/button/?url=' + encodedUrl + '" class="article-share-pinterest" target="_blank" title="Pinterest"></a>',
|
|
|
|
'<a href="https://plus.google.com/share?url=' + encodedUrl + '" class="article-share-google" target="_blank" title="Google+"></a>',
|
|
|
|
'</div>',
|
|
|
|
'</div>'
|
|
|
|
].join('');
|
|
|
|
|
|
|
|
var box = $(html);
|
|
|
|
$('body').append(box);
|
|
|
|
}
|
|
|
|
$('.article-share-box.on').hide();
|
|
|
|
|
|
|
|
box.css({
|
|
|
|
top: offset.top + 25,
|
|
|
|
left: offset.left
|
|
|
|
}).addClass('on');
|
|
|
|
}).on('click', '.article-share-box', function (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
}).on('click', '.article-share-box-input', function () {
|
|
|
|
$(this).select();
|
|
|
|
}).on('click', '.article-share-box-link', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
window.open(this.href, 'article-share-box-window-' + Date.now(), 'width=500,height=450');
|
|
|
|
});
|
|
|
|
|
|
|
|
//
|
|
|
|
// fancybox
|
|
|
|
if ($.fancybox) {
|
|
|
|
$('[data-fancybox]').fancybox({
|
|
|
|
protect: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// lazyload
|
|
|
|
$("img.lazy").lazyload({
|
2019-12-04 11:27:58 +00:00
|
|
|
effect: "fadeIn"
|
2019-12-03 11:37:44 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
//
|
|
|
|
// justifiedGallery
|
|
|
|
$('#gallery').justifiedGallery({
|
2019-12-04 11:27:58 +00:00
|
|
|
rowHeight: 200,
|
|
|
|
margins: 5
|
2019-12-03 11:37:44 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
//
|
|
|
|
$(document).ready(function ($) {
|
|
|
|
$('.anchor').click(function (event) {
|
|
|
|
event.preventDefault();
|
2019-12-04 11:27:58 +00:00
|
|
|
$('main').animate({ scrollTop: $(this.hash).offset().top }, 'smooth');
|
2019-12-03 11:37:44 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// To top
|
2019-12-04 11:27:58 +00:00
|
|
|
(function ($) {
|
2019-12-03 11:37:44 +00:00
|
|
|
// When to show the scroll link
|
|
|
|
// higher number = scroll link appears further down the page
|
|
|
|
var upperLimit = 1000;
|
|
|
|
|
|
|
|
// Our scroll link element
|
|
|
|
var scrollElem = $('#totop');
|
|
|
|
|
|
|
|
// Scroll to top speed
|
|
|
|
var scrollSpeed = 1600;
|
|
|
|
|
|
|
|
// Show and hide the scroll to top link based on scroll position
|
|
|
|
scrollElem.hide();
|
|
|
|
$('.content').scroll(function () {
|
|
|
|
var scrollTop = $('.content').scrollTop();
|
2019-12-04 11:27:58 +00:00
|
|
|
if (scrollTop > upperLimit) {
|
2019-12-03 11:37:44 +00:00
|
|
|
$(scrollElem).stop().fadeTo(300, 1); // fade back in
|
2019-12-04 11:27:58 +00:00
|
|
|
} else {
|
2019-12-03 11:37:44 +00:00
|
|
|
$(scrollElem).stop().fadeTo(300, 0); // fade out
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Scroll to top animation on click
|
2019-12-04 11:27:58 +00:00
|
|
|
$(scrollElem).click(function () {
|
|
|
|
$('.content').animate({ scrollTop: 0 }, scrollSpeed); return false;
|
2019-12-03 11:37:44 +00:00
|
|
|
});
|
|
|
|
})(jQuery);
|
|
|
|
|
|
|
|
// Mobile nav
|
|
|
|
var $content = $('.content'),
|
|
|
|
$sidebar = $('.sidebar'),
|
|
|
|
isMobileNavAnim = false,
|
|
|
|
mobileNavAnimDuration = 200;
|
|
|
|
|
|
|
|
var startMobileNavAnim = function () {
|
|
|
|
isMobileNavAnim = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
var stopMobileNavAnim = function () {
|
|
|
|
setTimeout(function () {
|
|
|
|
isMobileNavAnim = false;
|
|
|
|
}, mobileNavAnimDuration);
|
|
|
|
};
|
|
|
|
|
|
|
|
$('.navbar-toggle').on('click', function () {
|
|
|
|
if (isMobileNavAnim) return;
|
|
|
|
startMobileNavAnim();
|
|
|
|
$content.toggleClass('on');
|
|
|
|
$sidebar.toggleClass('on');
|
|
|
|
stopMobileNavAnim();
|
|
|
|
});
|
|
|
|
|
|
|
|
$($content).on('click', function () {
|
|
|
|
if (isMobileNavAnim || !$content.hasClass('on')) return;
|
|
|
|
$content.removeClass('on');
|
|
|
|
$sidebar.removeClass('on');
|
|
|
|
});
|
|
|
|
|
2019-12-04 11:27:58 +00:00
|
|
|
if (window.matchMedia("(min-width: 768px)").matches) {
|
|
|
|
$content.addClass('on');
|
|
|
|
$sidebar.addClass('on');
|
|
|
|
}
|
2019-12-05 15:31:52 +00:00
|
|
|
// 赞赏
|
|
|
|
$('.tooltip-item').hover(function () {
|
|
|
|
$('.tooltip-content').slideDown(150)
|
|
|
|
}, function () {
|
|
|
|
$('.tooltip-content').slideUp(150)
|
|
|
|
})
|
2019-12-03 11:37:44 +00:00
|
|
|
})(jQuery);
|
|
|
|
|
|
|
|
|