Skip to content

Commit fe09848

Browse files
committed
Introduce TypeScript
Set up TypeScript (add source directory and config file). The JavaScript files in `javascripts` can now be generated by running `tsc` in the root directory. This might be useful for future changes of the JavaScript. It does not affect the normal build process of the site.
1 parent eea7718 commit fe09848

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ exclude:
1818
- lib
1919
- test
2020
- vendor
21+
- tsconfig.json
2122

2223
url: https://www.ruby-lang.org
2324

_javascripts_src/examples.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var Examples = {
2+
names: ['cities', 'greeter', 'i_love_ruby', 'hello_world'],
3+
4+
random: function () {
5+
return Examples.names[Math.floor(Math.random() * Examples.names.length)];
6+
},
7+
8+
choose: function () {
9+
var lang = document.location.pathname.split('/')[1];
10+
var name = Examples.random();
11+
12+
$("#code").load('/' + lang + '/examples/' + name + '/');
13+
}
14+
};
15+
16+
$(document).ready(Examples.choose);

_javascripts_src/page.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var Page = {
2+
SiteLinks: {
3+
highlight: function () {
4+
var current_page = location.pathname;
5+
$("#header div.site-links a:not(.home)").each(function (i) {
6+
if (current_page.indexOf($(this).attr('href')) == 0) {
7+
$(this).addClass('selected');
8+
}
9+
});
10+
11+
$("#home-page-layout #header div.site-links a.home").addClass('selected');
12+
},
13+
14+
menu: function () {
15+
$("#header div.site-links a.menu").on('click touchstart', function (event) {
16+
$(this).closest("div.site-links").toggleClass("open");
17+
event.preventDefault();
18+
});
19+
}
20+
}
21+
};
22+
23+
$(Page.SiteLinks.highlight);
24+
$(Page.SiteLinks.menu);

tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "./javascripts",
4+
5+
"target": "es5",
6+
"strict": true
7+
},
8+
"include": ["./_javascripts_src/**/*"]
9+
}

0 commit comments

Comments
 (0)