From 797ee7c38aa90083e69afe36feafa0019dcdafbd Mon Sep 17 00:00:00 2001 From: xuexb Date: Sun, 3 Apr 2016 00:43:46 +0800 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E4=B8=AD=E6=9C=89=E5=8F=8C=E5=B1=82=E9=94=9A=E7=82=B9=E6=97=B6?= =?UTF-8?q?=E4=B8=8A=E4=B8=8B=E4=B8=80=E7=AB=A0=E6=8C=89=E9=92=AE=E6=AD=BB?= =?UTF-8?q?=E9=93=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/ditto.js | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/js/ditto.js b/js/ditto.js index 1841abe..b40793d 100644 --- a/js/ditto.js +++ b/js/ditto.js @@ -18,6 +18,30 @@ var ditto = { run: initialize }; +/** + * 获取当前hash + * + * @param {string} hash 要解析的hash,默认取当前页面的hash,如: nav#类目 => {nav:nav, anchor:类目} + * @description 分导航和页面锚点 + * @return {Object} {nav:导航, anchor:页面锚点} + */ +var getHash = function (hash) { + hash = hash || window.location.hash.substr(1); + + if (!hash) { + return { + nav: '', + anchor: '' + } + } + + hash = hash.split('#'); + return { + nav: hash[0], + anchor: decodeURIComponent(hash[1] || '') + } +}; + var disqusCode = '

留言

'; var menu = new Array(); @@ -56,16 +80,18 @@ function init_sidebar_section() { menu.push(this.href.slice(this.href.indexOf('#'))); }); $('#pageup').on('click', function() { + var hash = getHash().nav; for (var i = 0; i < menu.length; i++) { - if (location.hash === '') break; - if (menu[i] === location.hash) break; + if (hash === '') break; + if (menu[i] === '#' + hash) break; } location.hash = menu[i - 1] }); $('#pagedown').on('click', function() { + var hash = getHash().nav; for (var i = 0; i < menu.length; i++) { - if (location.hash === '') break; - if (menu[i] === location.hash) break; + if (hash === '') break; + if (menu[i] === '#' + hash) break; } location.hash = menu[i + 1]; }); @@ -260,7 +286,7 @@ function show_loading() { return loading; } -function router() { +function router() { var path = location.hash.replace(/#([^#]*)(#.*)?/, './$1'); var hashArr = location.hash.split('#'); From 072df734f1fb22e2c2ba9f22d84e848c01bbf0bc Mon Sep 17 00:00:00 2001 From: xuexb Date: Sun, 3 Apr 2016 00:47:15 +0800 Subject: [PATCH 2/5] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E4=B8=AD=E6=9C=89=E5=8F=8C=E5=B1=82=E9=94=9A=E7=82=B9=E6=97=B6?= =?UTF-8?q?=E6=9C=80=E5=90=8E=E7=AB=A0=E9=A1=B5=E9=9D=A2=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E5=88=A4=E6=96=AD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/ditto.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/js/ditto.js b/js/ditto.js index b40793d..a5b00eb 100644 --- a/js/ditto.js +++ b/js/ditto.js @@ -373,14 +373,13 @@ function router() { } } } - - if (location.hash === '' || location.hash === menu[0]) { + if (location.hash === '' || '#' + getHash().nav === menu[0]) { $('#pageup').css('display', 'none'); } else { $('#pageup').css('display', 'inline-block'); } - if (location.hash === menu[(menu.length - 1)]) { + if ('#' + getHash().nav === menu[(menu.length - 1)]) { $('#pagedown').css('display', 'none'); } else { $('#pagedown').css('display', 'inline-block'); From d8493f7550cfc942269e516cb09a668ef7bf3b7d Mon Sep 17 00:00:00 2001 From: w-halo Date: Fri, 8 Apr 2016 17:41:12 +0800 Subject: [PATCH 3/5] Update regex.md --- docs/regex.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/regex.md b/docs/regex.md index d71c444..11490ad 100644 --- a/docs/regex.md +++ b/docs/regex.md @@ -23,7 +23,7 @@ var regex = /xyz/i; 但是,ES5不允许此时使用第二个参数,添加修饰符,否则会报错。 ```javascript -var regex = new RegExp(/xyz/, i); +var regex = new RegExp(/xyz/, 'i'); // Uncaught TypeError: Cannot supply flags when constructing one RegExp from another ``` From 690d5531a047a2ef47bb987c72d16e50b206574a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B7=A6=E4=BC=A6?= Date: Wed, 13 Apr 2016 11:23:05 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=80=E5=A4=84?= =?UTF-8?q?=E5=AE=B9=E6=98=93=E4=BA=A7=E7=94=9F=E8=AF=AF=E8=A7=A3=E7=9A=84?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/promise.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/promise.md b/docs/promise.md index 3659ba6..053be71 100644 --- a/docs/promise.md +++ b/docs/promise.md @@ -45,7 +45,7 @@ Promise实例生成以后,可以用then方法分别指定Resolved状态和Reje ```javascript promise.then(function(value) { // success -}, function(value) { +}, function(error) { // failure }); ``` From 8f588d02c5c2b50955df8619006970af27f8e954 Mon Sep 17 00:00:00 2001 From: zaxlct Date: Wed, 13 Apr 2016 15:23:27 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E7=BB=9F=E4=B8=80=20if=20=E8=AF=AD?= =?UTF-8?q?=E5=8F=A5=E6=8B=AC=E5=8F=B7=E9=87=8C=E7=9A=84=E7=A9=BA=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit handle() 函数里 有两个 if ,为什么里面的空格不同? --- docs/promise.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/promise.md b/docs/promise.md index 3659ba6..3674d97 100644 --- a/docs/promise.md +++ b/docs/promise.md @@ -122,7 +122,7 @@ var getJSON = function(url) { client.send(); function handler() { - if ( this.readyState !== 4 ) { + if (this.readyState !== 4) { return; } if (this.status === 200) {