diff --git a/index.html b/index.html
index b752ca1..f19f923 100644
--- a/index.html
+++ b/index.html
@@ -8,6 +8,7 @@
+
@@ -34,7 +35,7 @@
ditto.sidebar_file = "sidebar.md",
ditto.document_title = "ECMAScript 6入门",
// 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
ditto.run();
diff --git a/js/ditto.js b/js/ditto.js
index 6f90b6b..cd82774 100644
--- a/js/ditto.js
+++ b/js/ditto.js
@@ -11,6 +11,7 @@ var ditto = {
sidebar: true,
edit_button: true,
back_to_top_button: true,
+ save_progress: true, // 保存阅读进度
// initialize function
run: initialize
@@ -195,6 +196,11 @@ function router() {
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
if (location.pathname === "/index.html") {
path = location.pathname.replace("index.html", ditto.index);
@@ -240,12 +246,6 @@ function router() {
})();
})();
- if(location.hash !== ''){
- $('html, body').animate({
- scrollTop: $('#content').offset().top
- }, 200);
- }
-
if(location.hash==='' || location.hash===menu[0]){
$('#pageup').css('display','none');
}else{
@@ -264,16 +264,22 @@ function router() {
var wh = $w.height();
var h = $('body').height();
var sHeight = h - wh;
- $w.off('scroll');
- $w.on('scroll', function(){
+ var perc = ditto.save_progress ? store.get('page-progress') || 0 : 0;
+
+ $w.off('scroll').on('scroll', function(){
var perc = Math.max(0, Math.min(1, $w.scrollTop()/sHeight));
updateProgress(perc);
});
function updateProgress(perc){
$prog2.css({width : perc*100 + '%'});
+ ditto.save_progress && store.set('page-progress', perc);
}
+ updateProgress(perc);
+ $('html, body').animate({
+ scrollTop: sHeight * perc
+ }, 200);
}());
}).fail(function() {
diff --git a/js/store.js b/js/store.js
new file mode 100644
index 0000000..915283b
--- /dev/null
+++ b/js/store.js
@@ -0,0 +1,2 @@
+/* Copyright (c) 2010-2013 Marcus Westin */
+this.JSON||(this.JSON={}),function(){function f(e){return e<10?"0"+e:e}function quote(e){return escapable.lastIndex=0,escapable.test(e)?'"'+e.replace(escapable,function(e){var t=meta[e];return typeof t=="string"?t:"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+e+'"'}function str(e,t){var n,r,i,s,o=gap,u,a=t[e];a&&typeof a=="object"&&typeof a.toJSON=="function"&&(a=a.toJSON(e)),typeof rep=="function"&&(a=rep.call(t,e,a));switch(typeof a){case"string":return quote(a);case"number":return isFinite(a)?String(a):"null";case"boolean":case"null":return String(a);case"object":if(!a)return"null";gap+=indent,u=[];if(Object.prototype.toString.apply(a)==="[object Array]"){s=a.length;for(n=0;ndocument.w=window"+i+'>'),a.close(),u=a.w.frames[0].document,s=u.createElement("div")}catch(f){s=n.createElement("div"),u=n.body}function l(e){return function(){var n=Array.prototype.slice.call(arguments,0);n.unshift(s),u.appendChild(s),s.addBehavior("#default#userData"),s.load(r);var i=e.apply(t,n);return u.removeChild(s),i}}var c=new RegExp("[!\"#$%&'()*+,/\\\\:;<=>?@[\\]^`{|}~]","g");function h(e){return e.replace(/^d/,"___$&").replace(c,"___")}t.set=l(function(e,n,i){return n=h(n),i===undefined?t.remove(n):(e.setAttribute(n,t.serialize(i)),e.save(r),i)}),t.get=l(function(e,n){return n=h(n),t.deserialize(e.getAttribute(n))}),t.remove=l(function(e,t){t=h(t),e.removeAttribute(t),e.save(r)}),t.clear=l(function(e){var t=e.XMLDocument.documentElement.attributes;e.load(r);for(var n=0,i;i=t[n];n++)e.removeAttribute(i.name);e.save(r)}),t.getAll=function(e){var n={};return t.forEach(function(e,t){n[e]=t}),n},t.forEach=l(function(e,n){var r=e.XMLDocument.documentElement.attributes;for(var i=0,s;s=r[i];++i)n(s.name,t.deserialize(e.getAttribute(s.name)))})}try{var p="__storejs__";t.set(p,p),t.get(p)!=p&&(t.disabled=!0),t.remove(p)}catch(f){t.disabled=!0}t.enabled=!t.disabled,typeof module!="undefined"&&module.exports&&this.module!==module?module.exports=t:typeof define=="function"&&define.amd?define(t):e.store=t}(Function("return this")())
\ No newline at end of file