mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-25 11:12:21 +00:00
commit
8c7635e698
@ -8,6 +8,7 @@
|
|||||||
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.min.js"></script>
|
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.min.js"></script>
|
||||||
|
|
||||||
<script src="js/marked.js"></script>
|
<script src="js/marked.js"></script>
|
||||||
|
<script src="js/store.js"></script>
|
||||||
<script src="js/ditto.js"></script>
|
<script src="js/ditto.js"></script>
|
||||||
<script src="js/prism.js"></script>
|
<script src="js/prism.js"></script>
|
||||||
<link rel="stylesheet" href="app/bower_components/normalize-css/normalize.css">
|
<link rel="stylesheet" href="app/bower_components/normalize-css/normalize.css">
|
||||||
@ -34,7 +35,7 @@
|
|||||||
ditto.sidebar_file = "sidebar.md",
|
ditto.sidebar_file = "sidebar.md",
|
||||||
ditto.document_title = "ECMAScript 6入门",
|
ditto.document_title = "ECMAScript 6入门",
|
||||||
// where the docs are actually stored on github - so you can edit
|
// where the docs are actually stored on github - so you can edit
|
||||||
ditto.base_url = "https://github.com/ruanyf/es6tutorial/edit/gh-pages/"; // <------- EDIT ME!!
|
ditto.base_url = "https://github.com/ruanyf/es6tutorial/edit/gh-pages"; // <------- EDIT ME!!
|
||||||
|
|
||||||
// run
|
// run
|
||||||
ditto.run();
|
ditto.run();
|
||||||
|
27
js/ditto.js
27
js/ditto.js
@ -11,6 +11,7 @@ var ditto = {
|
|||||||
sidebar: true,
|
sidebar: true,
|
||||||
edit_button: true,
|
edit_button: true,
|
||||||
back_to_top_button: true,
|
back_to_top_button: true,
|
||||||
|
save_progress: true, // 保存阅读进度
|
||||||
|
|
||||||
// initialize function
|
// initialize function
|
||||||
run: initialize
|
run: initialize
|
||||||
@ -195,6 +196,11 @@ function router() {
|
|||||||
|
|
||||||
var path = location.hash.replace("#", "./");
|
var path = location.hash.replace("#", "./");
|
||||||
|
|
||||||
|
if (ditto.save_progress && store.get('menu-progress') !== location.hash) {
|
||||||
|
store.set('menu-progress', location.hash);
|
||||||
|
store.set('page-progress', 0);
|
||||||
|
}
|
||||||
|
|
||||||
// default page if hash is empty
|
// default page if hash is empty
|
||||||
if (location.pathname === "/index.html") {
|
if (location.pathname === "/index.html") {
|
||||||
path = location.pathname.replace("index.html", ditto.index);
|
path = location.pathname.replace("index.html", ditto.index);
|
||||||
@ -234,18 +240,14 @@ function router() {
|
|||||||
|
|
||||||
// http://docs.disqus.com/developers/universal/
|
// http://docs.disqus.com/developers/universal/
|
||||||
(function() {
|
(function() {
|
||||||
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
|
var dsq = document.createElement('script');
|
||||||
|
dsq.type = 'text/javascript';
|
||||||
|
dsq.async = true;
|
||||||
dsq.src = 'http://' + window.disqus_shortname + '.disqus.com/embed.js';
|
dsq.src = 'http://' + window.disqus_shortname + '.disqus.com/embed.js';
|
||||||
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
|
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
|
||||||
})();
|
})();
|
||||||
})();
|
})();
|
||||||
|
|
||||||
if(location.hash !== ''){
|
|
||||||
$('html, body').animate({
|
|
||||||
scrollTop: $('#content').offset().top
|
|
||||||
}, 200);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (location.hash === '' || location.hash === menu[0]) {
|
if (location.hash === '' || location.hash === menu[0]) {
|
||||||
$('#pageup').css('display', 'none');
|
$('#pageup').css('display', 'none');
|
||||||
} else {
|
} else {
|
||||||
@ -264,21 +266,26 @@ function router() {
|
|||||||
var wh = $w.height();
|
var wh = $w.height();
|
||||||
var h = $('body').height();
|
var h = $('body').height();
|
||||||
var sHeight = h - wh;
|
var sHeight = h - wh;
|
||||||
$w.off('scroll');
|
var perc = ditto.save_progress ? store.get('page-progress') || 0 : 0;
|
||||||
$w.on('scroll', function(){
|
|
||||||
|
$w.off('scroll').on('scroll', function() {
|
||||||
var perc = Math.max(0, Math.min(1, $w.scrollTop() / sHeight));
|
var perc = Math.max(0, Math.min(1, $w.scrollTop() / sHeight));
|
||||||
updateProgress(perc);
|
updateProgress(perc);
|
||||||
});
|
});
|
||||||
|
|
||||||
function updateProgress(perc) {
|
function updateProgress(perc) {
|
||||||
$prog2.css({width: perc * 100 + '%'});
|
$prog2.css({width: perc * 100 + '%'});
|
||||||
|
ditto.save_progress && store.set('page-progress', perc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateProgress(perc);
|
||||||
|
$('html, body').animate({
|
||||||
|
scrollTop: sHeight * perc
|
||||||
|
}, 200);
|
||||||
}());
|
}());
|
||||||
|
|
||||||
}).fail(function() {
|
}).fail(function() {
|
||||||
show_error();
|
show_error();
|
||||||
|
|
||||||
}).always(function() {
|
}).always(function() {
|
||||||
clearInterval(loading);
|
clearInterval(loading);
|
||||||
$(ditto.loading_id).hide();
|
$(ditto.loading_id).hide();
|
||||||
|
2
js/store.js
Normal file
2
js/store.js
Normal file
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user