1
0
mirror of https://github.com/ruanyf/es6tutorial.git synced 2025-05-25 19:22:21 +00:00

Merge branch 'gh-pages' of github.com:ruanyf/es6tutorial into gh-pages

This commit is contained in:
ruanyf 2016-05-11 07:48:09 +08:00
commit 9322419906
2 changed files with 35 additions and 10 deletions

View File

@ -45,7 +45,7 @@ Promise实例生成以后可以用then方法分别指定Resolved状态和Reje
```javascript
promise.then(function(value) {
// success
}, function(value) {
}, function(error) {
// failure
});
```
@ -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) {

View File

@ -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 = '<h3>留言</h3><div id="disqus_thread"></div>';
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('#');
@ -347,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');