-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
57 lines (52 loc) · 1.32 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// 画面の準備ができたら...
jQuery(function($){
window.onhashchange = function(){
showContents();
}
showContents();
showMenu()
// ★marked.js の設定
marked.setOptions({
// 改行を認識する。(スペース×2は不要)
breaks : true,
});
function showContents(){
// add (S) スクロール位置をトップに戻す。
$(window).scrollTop(0);
// add (E)
var url = location.hash.replace('#', '');
if(url){
$.ajax({
url: url,
cache: false,
success: function(md){
var html = marked(md);
$('.st-MainContents').html(html);
/*
// css 用に変換する。
var mdEls = document.querySelectorAll('.st-MainContents');
for(var i in mdEls){
var mdEl = mdEls[i];
var converted = document.createElement('div');
converted.className = 'marked';
converted.innerHTML = marked(mdEl.value);
mdEl.parentNode.replaceChild(converted, mdEl);
}
*/
}
});
}
}
function showMenu(){
// Chrome ローカルファイルにAjaxリクエストを送るとエラーになる。仕様らしい。
// ※ ForeFox と EDGE は動作する。
$.ajax({
url: 'menu.md',
cache: false,
success: function(md){
var html = marked(md);
$('.st-SubMenu').html(html);
}
});
}
});