2015-07-29 19:34:48 +08:00
|
|
|
$( document ).ready(function() {
|
|
|
|
|
2015-09-05 23:26:17 +08:00
|
|
|
// url
|
|
|
|
var url = window.location.pathname;
|
|
|
|
|
2015-09-25 04:32:41 +08:00
|
|
|
// Fix back button cache problem
|
|
|
|
window.onunload = function(){};
|
2015-09-24 22:47:33 +08:00
|
|
|
|
2015-09-14 14:39:53 +08:00
|
|
|
// Set theme
|
|
|
|
var theme = localStorage.getItem('theme');
|
|
|
|
if (theme == null) { theme = 'light'; }
|
|
|
|
|
|
|
|
set_theme(theme);
|
|
|
|
|
2015-09-24 22:47:33 +08:00
|
|
|
|
2015-08-06 00:28:59 +08:00
|
|
|
// Syntax highlighting Configuration
|
|
|
|
hljs.configure({
|
|
|
|
tabReplace: ' ', // 4 spaces
|
|
|
|
languages: [], // Languages used for auto-detection
|
|
|
|
});
|
|
|
|
|
|
|
|
$('code').each(function(i, block) {
|
|
|
|
hljs.highlightBlock(block);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2015-07-29 19:34:48 +08:00
|
|
|
// Interesting DOM Elements
|
2015-09-24 22:47:33 +08:00
|
|
|
var html = $("html");
|
2015-07-29 19:34:48 +08:00
|
|
|
var sidebar = $("#sidebar");
|
|
|
|
var page_wrapper = $("#page-wrapper");
|
|
|
|
|
2015-09-24 22:47:33 +08:00
|
|
|
|
|
|
|
// Toggle sidebar
|
2015-07-29 19:34:48 +08:00
|
|
|
$("#sidebar-toggle").click(function(event){
|
2015-09-24 22:47:33 +08:00
|
|
|
if ( html.hasClass("sidebar-hidden") ) {
|
|
|
|
html.removeClass("sidebar-hidden").addClass("sidebar-visible");
|
|
|
|
localStorage.setItem('sidebar', 'visible');
|
|
|
|
} else if ( html.hasClass("sidebar-visible") ) {
|
|
|
|
html.removeClass("sidebar-visible").addClass("sidebar-hidden");
|
|
|
|
localStorage.setItem('sidebar', 'hidden');
|
2015-07-29 19:34:48 +08:00
|
|
|
} else {
|
2015-09-24 22:47:33 +08:00
|
|
|
if(sidebar.position().left === 0){
|
|
|
|
html.addClass("sidebar-hidden");
|
|
|
|
localStorage.setItem('sidebar', 'hidden');
|
|
|
|
} else {
|
|
|
|
html.addClass("sidebar-visible");
|
|
|
|
localStorage.setItem('sidebar', 'visible');
|
|
|
|
}
|
2015-07-29 19:34:48 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-09-24 22:47:33 +08:00
|
|
|
|
2015-12-27 11:45:50 +08:00
|
|
|
// Scroll sidebar to current active section
|
|
|
|
var activeSection = sidebar.find(".active");
|
|
|
|
if(activeSection.length) {
|
|
|
|
sidebar.scrollTop(activeSection.offset().top);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-05 23:26:17 +08:00
|
|
|
// Print button
|
|
|
|
$("#print-button").click(function(){
|
|
|
|
var printWindow = window.open("print.html");
|
|
|
|
});
|
|
|
|
|
|
|
|
if( url.substring(url.lastIndexOf('/')+1) == "print.html" ) {
|
|
|
|
window.print();
|
|
|
|
}
|
|
|
|
|
2015-09-24 22:47:33 +08:00
|
|
|
|
2015-09-11 07:16:29 +08:00
|
|
|
// Theme button
|
|
|
|
$("#theme-toggle").click(function(){
|
|
|
|
if($('.theme-popup').length) {
|
|
|
|
$('.theme-popup').remove();
|
|
|
|
} else {
|
|
|
|
var popup = $('<div class="theme-popup"></div>')
|
|
|
|
.append($('<div class="theme" id="light">Light (default)<div>'))
|
2015-09-14 17:25:42 +08:00
|
|
|
.append($('<div class="theme" id="rust">Rust</div>'))
|
2015-09-14 14:39:53 +08:00
|
|
|
.append($('<div class="theme" id="coal">Coal</div>'))
|
|
|
|
.append($('<div class="theme" id="navy">Navy</div>'));
|
2015-09-11 07:16:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
$(this).append(popup);
|
|
|
|
|
|
|
|
$('.theme').click(function(){
|
|
|
|
var theme = $(this).attr('id');
|
2015-09-14 14:39:53 +08:00
|
|
|
|
|
|
|
set_theme(theme)
|
2015-09-11 07:16:29 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-09-14 14:39:53 +08:00
|
|
|
function set_theme(theme) {
|
|
|
|
if (theme == 'coal' || theme == 'navy') {
|
|
|
|
$("[href='tomorrow-night.css']").prop('disabled', false);
|
|
|
|
$("[href='highlight.css']").prop('disabled', true);
|
|
|
|
} else {
|
|
|
|
$("[href='tomorrow-night.css']").prop('disabled', true);
|
|
|
|
$("[href='highlight.css']").prop('disabled', false);
|
|
|
|
}
|
|
|
|
|
|
|
|
localStorage.setItem('theme', theme);
|
|
|
|
|
|
|
|
$('body').removeClass().addClass(theme);
|
|
|
|
}
|
2015-07-29 19:34:48 +08:00
|
|
|
});
|