Skip to content

Commit b703e66

Browse files
authored
Merge pull request #2714 from stomar/typescript
Introduce TypeScript
2 parents 41c3d06 + 3b3c677 commit b703e66

File tree

6 files changed

+76
-31
lines changed

6 files changed

+76
-31
lines changed

_config.yml

+1
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

+16
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

+24
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);

javascripts/examples.js

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1+
"use strict";
12
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-
}
3+
names: ['cities', 'greeter', 'i_love_ruby', 'hello_world'],
4+
random: function () {
5+
return Examples.names[Math.floor(Math.random() * Examples.names.length)];
6+
},
7+
choose: function () {
8+
var lang = document.location.pathname.split('/')[1];
9+
var name = Examples.random();
10+
$("#code").load('/' + lang + '/examples/' + name + '/');
11+
}
1412
};
15-
1613
$(document).ready(Examples.choose);

javascripts/page.js

+16-18
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1+
"use strict";
12
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');
3+
SiteLinks: {
4+
highlight: function () {
5+
var current_page = location.pathname;
6+
$("#header div.site-links a:not(.home)").each(function (i) {
7+
if (current_page.indexOf($(this).attr('href')) == 0) {
8+
$(this).addClass('selected');
9+
}
10+
});
11+
$("#home-page-layout #header div.site-links a.home").addClass('selected');
12+
},
13+
menu: function () {
14+
$("#header div.site-links a.menu").on('click touchstart', function (event) {
15+
$(this).closest("div.site-links").toggleClass("open");
16+
event.preventDefault();
17+
});
818
}
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-
});
1919
}
20-
}
2120
};
22-
2321
$(Page.SiteLinks.highlight);
2422
$(Page.SiteLinks.menu);

tsconfig.json

+9
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)