Skip to content

Commit 0e3946a

Browse files
committed
sepearte language setup from lesson.js to langauges.js
1 parent ad4c752 commit 0e3946a

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

build/templates/index.template

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5858
<link rel="stylesheet" href="/webgl/lessons/resources/base.css" type="text/css" />
5959
<link rel="stylesheet" href="/webgl/lessons/resources/lesson.css" type="text/css" />
6060
<link rel="stylesheet" href="/webgl/lessons/resources/index.css" type="text/css" />
61-
<script src="/webgl/resources/webgl-utils.js"></script>
62-
<script src="/webgl/resources/webgl-3d-math.js"></script>
63-
<script src="/webgl/resources/primitives.js"></script>
64-
<script src="/webgl/resources/same-code-02.js"></script>
6561
</head>
6662
<body>
6763
<div id="canvas">
@@ -70,6 +66,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7066
<div class="row">
7167
<div class="not-jumbotron">
7268
<h1>{{title}} <span class="rss"><a href="http://webglfundamentals.org/atom.xml"><img src="/webgl/lessons/resources/rss-icon.svg" /></a></span></h1>
69+
{{{langs}}}
7370
{{{content}}}
7471
</div>
7572
</div>
@@ -136,6 +133,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
136133
</style>
137134
<div id="forkongithub"><a href="https://github.com/greggman/webgl-fundamentals">Fix or Fork me on GitHub</a></div>
138135
</body>
136+
<script src="/webgl/resources/webgl-utils.js"></script>
137+
<script src="/webgl/resources/webgl-3d-math.js"></script>
138+
<script src="/webgl/resources/primitives.js"></script>
139+
<script src="/webgl/resources/same-code-02.js"></script>
140+
<script src="/3rdparty/jquery-1.11.2.min.js"></script>
141+
<script src="/webgl/lessons/resources/languages.js"></script>
139142
{{{include "build/templates/analytics.template" }}}
140143
</html>
141144

build/templates/lesson.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9999
<script src="/3rdparty/jquery-1.11.2.min.js"></script>
100100
<script src="/webgl/lessons/resources/prettify.js"></script>
101101
<script src="/webgl/lessons/resources/lesson.js"></script>
102+
<script src="/webgl/lessons/resources/languages.js"></script>
102103
{{{include "build/templates/analytics.template" }}}
103104
</html>
104105

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!-- Licensed under a BSD license. See license.html for license -->
2+
(function($){
3+
$(document).ready(function($){
4+
var m = /webgl\/lessons\/(.*?)\//.exec(window.location.pathname);
5+
var lang = "en";
6+
if (m) {
7+
lang = m[1];
8+
}
9+
$('#language').val(lang);
10+
$('#language').on('change', function() {
11+
var lastSlash = window.location.pathname.lastIndexOf("/");
12+
var theRest = window.location.pathname.substr(lastSlash);
13+
var lang = this.value;
14+
var path = "/webgl/lessons";
15+
lang = lang === "en" ? "" : ("/" + lang);
16+
if (theRest.length < 2) { // it's probably at the root
17+
theRest = "/index.html";
18+
} else if (theRest === "/index.html") {
19+
if (lang === "") {
20+
path = "";
21+
}
22+
}
23+
window.location.href = path + lang + theRest + window.location.search + window.location.hash;
24+
});
25+
});
26+
}(jQuery));
27+

webgl/lessons/resources/lesson.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,6 @@ $(document).ready(function($){
4646
return $('<pre class="prettyprint showlinemods">' + this.innerHTML + '</pre>')
4747
});
4848
prettyPrint();
49-
var m = /webgl\/lessons\/(.*?)\//.exec(window.location.pathname);
50-
var lang = "en";
51-
if (m) {
52-
lang = m[1];
53-
}
54-
$('#language').val(lang);
55-
$('#language').on('change', function() {
56-
var lang = this.value;
57-
lang = lang === "en" ? "" : ("/" + lang);
58-
var lastSlash = window.location.pathname.lastIndexOf("/");
59-
var theRest = window.location.pathname.substr(lastSlash);
60-
window.location.href = "/webgl/lessons" + lang + theRest + window.location.search + window.location.hash;
61-
});
6249
});
6350
}(jQuery));
6451

0 commit comments

Comments
 (0)