-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
273 lines (151 loc) · 7.16 KB
/
index.html
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<!doctype html>
<html lang = "en" >
<head>
<meta charset = "utf-8" >
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name = description content = "File wrangler. Default index.html file. Opens HTML or Markdown files. Passes location.hash." >
<meta name = keywords content = "ShowDown,Markdown,AJAX,JavaScript,HTML,CSS,GitHub,FOSS" >
<meta name = date content = "2017-08-16" >
<title></title>
<style id = "foo" >
/* items in mostly in order of: tag/class/id then alphabetical */
html { --mnu-back-col: lightgray; --menu-width: 250px; }
body, html { background-color: #fefefe; font: 12pt monospace; height: 100%; margin: 0; }
a { color: crimson; }
blockquote, pre { background-color: #eee; padding: 10px; }
button, input[type=button] { background-color: #ddd; border: none; color: #322; cursor: pointer; padding: 3px 20px; }
button:hover { background: #ccc; color: #fff }
input[type=range] { -webkit-appearance: none; -moz-appearance: none; background-color: #ddd; width: 160px; }
input[type=range]::-moz-range-thumb { background-color: #888; border-radius: 0; width: 10px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; background-color: #888; height: 20px; width: 10px; }
.contents { border: 0px solid red; left: 0; margin: 0 auto; max-width: 800px; position: absolute; right: 0; }
.contentsContainer { height: 100%; width: 100%; }
.iframeMenu { border-width: 0; height: 100%; margin: 0; width: 100%; }
.iframeContents { border-width: 0; height: 100%; margin: 0; width: 100%; }
.menuContainer { padding: 0 10px 0 15px; }
.menuContainer a { text-decoration: none; }
.menuContainer a:hover, .menuContainer a:focus{ color: #f1f1f1; }
#divContentsContainer { box-sizing: border-box; height: 100%; margin-left: var( --menu-width ); transition: margin-left .5s;
position: absolute; top: 0; width: calc( 100% - var( --menu-width ) );
}
#divEditFile {
background-color: #555; color: #fff; opacity: 0.5; padding: 8px; position: fixed; right: 20px; top: 20px;
vertical-align: middle; z-index: 1;
}
#divEditFile:hover { cursor: pointer; opacity: 1; }
#divEditFile img { vertical-align: middle; width: 24px; }
#divHamburger {
background-color: #edd; cursor:pointer; font-size:30px; left: var( --menu-width ); line-height: 35px; margin: 0; opacity: 0.5;
padding: 5px 15px 8px 10px; position: fixed; top: 80px; transition: left .5s; z-index: 1;
}
#divHamburger:hover { cursor: pointer; opacity: 1; }
#divMenu {
background-color: var( --mnu-back-col ); box-sizing: border-box; height: 100%; left: 0; overflow: auto;
position: fixed; top: 0; transition: 0.5s; width: var( --menu-width ); z-index: 1;
}
#divMenu p { margin: 0 }
@media screen and ( max-height: 450px ) {
.menu {padding-top: 15px;}
.menu a {font-size: 18px;}
}
</style>
</head>
<body>
<script src = "index.js" ></script>
<script src = "https://cdn.rawgit.com/showdownjs/showdown/1.8.5/dist/showdown.min.js" ></script>
<div id = "divMenu" class = "menu" >
<div id = "divMenuContainer" class = "menuContainer" >
<div id = "divMenuContents" class = "menuContents" ></div>
</div>
</div>
<div id = "divContentsContainer" class = "contentsContainer" ></div>
<div id = "divHamburger" onclick = "onClickSlideMenu();" > ☰ slide</div>
<div id = "divEditFile" onclick = "onclickEditButton();" title = "Update this file on GitHub" ><img src = "https://status.github.com/images/invertocat.png" > Edit this file</div>
<script>
var defaults = defaults || {};
const menuFile = defaults.menuFile ? defaults.menuFile : 'index-menu.md';
const menuWidth = defaults.menuWidth ? defaults.menuWidth : 250;
const menuPrefix = defaults.menuPrefix ? defaults.menuPrefix : 'menu';
const userGitHub = defaults.user ? defaults.user : '';
const folderGitHub = defaults.folder ? defaults.folder : '';
const fileGitHub = defaults.file ? defaults.file : 'README.md';
document.body.style.setProperty( '--menu-width', menuWidth + 'px' );
init();
function init() {
showdown.setFlavor( 'github' );
requestFile( menuFile, divMenuContents );
window.addEventListener( 'resize', onWindowResize, false );
onWindowResize();
window.addEventListener( 'hashchange', onHashChange, false );
onHashChange();
}
function onHashChange() {
if ( !location.hash.length ) {
location.hash = fileGitHub;
return;
}
let url = location.hash.slice( 1 );
let app = location.hash.split( '#' )[ 1 ];
//console.log( 'url', url );
if ( url.startsWith( menuPrefix ) || url.startsWith ( menuFile ) ) {
requestFile( url, divMenuContents );
if ( divSubMenu ) { divSubMenu.innerHTML = ''; }
} else if ( app.endsWith( '.md' ) ) {
divContentsContainer.innerHTML = '<div id = "divContents" class = "contents" src=' + url + ' ></div>';
requestFile( url, divContents );
divContentsContainer.style.overflow = 'auto';
if ( parent.divSubMenu ) { divSubMenu.innerHTML = ''; }
} else if ( app.includes( '.htm' ) ) {
divContentsContainer.innerHTML = '<iframe id=ifrContents class=iframeContents src=' + url + ' ></iframe>';
divContentsContainer.style.overflow = 'hidden';
} else {
// get to here with intent only - following don't exist at load time
if ( parent.ifrMenuSub ) { ifrMenuSub.contentWindow.location.hash = url; }
if ( parent.divContents ) { divContents.contentWindow.location.hash = url; }
ifrContents.contentWindow.location.hash = url;
}
}
function onWindowResize(){
const iframes = document.getElementsByClassName( 'iframeReadMe' );
const display = window.innerWidth < 1350 ? 'none' : '';
for ( let i = 0; i < iframes.length; i++ ) {
if ( iframes[ i ].className === 'iframeReadMe' ) {
iframes[ i ].style.display = display;
}
}
divEditFile.style.display = display;
divHamburger.innerHTML = display === 'none' ? '☰' : '☰ slide';
divHamburger.style.top = display === 'none' ? '0' : '80px';
if ( !divMenu.style.width || divMenu.style.width === '250px' ) {
divContentsContainer.style.width = ( window.clientWidth - menuWidth ) + 'px';
} else {
divContentsContainer.style.width = window.clientWidth + 'px';
}
}
function onClickSlideMenu() {
const visible = !divMenu.style.width || divMenu.style.width === menuWidth + 'px' ? false : true;
divMenu.style.width = visible ? menuWidth + 'px' : '0';
divHamburger.style.left = visible ? menuWidth + 'px' : '0';
divContentsContainer.style.marginLeft = visible ? menuWidth + 'px' : '0';
divContentsContainer.style.width = visible ? ( window.innerWidth - menuWidth ) + 'px' : window.innerWidth + 'px';
}
function onclickEditButton(){
const file = location.hash.slice( 1 ) ? location.hash.slice( 1 ) : fileGitHub;
window.open( 'https://github.com/' + userGitHub + '/' + folderGitHub + '/' + file );
}
function requestFile( url, target ) {
const converter = new showdown.Converter();
const xhr = new XMLHttpRequest();
xhr.open( 'get', url, true );
xhr.onload = function() {
target.innerHTML = converter.makeHtml( xhr.responseText );
title = url.split( '/' ).pop().replace( /-|.md|.html/g, ' ' );
document.title = title + ' - ' + userGitHub;
window.scrollTo( 0, 0 );
onWindowResize();
};
xhr.send( null );
}
</script>
</body>
</html>