Skip to content
This repository was archived by the owner on Nov 17, 2022. It is now read-only.

Commit ea24ba9

Browse files
committed
script edit
1 parent 7b24132 commit ea24ba9

File tree

2 files changed

+57
-43
lines changed

2 files changed

+57
-43
lines changed

build/_includes/header.html

+54-42
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
<li>
66
<span>Framework</span>
77
<ul>
8-
<li><a href="{{site.headerbaseurl}}/nativescript-is-how-you-build-native-mobile-apps-with-angular">Angular Integration</a></li>
8+
<li><a href="{{site.headerbaseurl}}/nativescript-is-how-you-build-native-mobile-apps-with-angular">Angular
9+
Integration</a></li>
910
<li><a href="{{site.headerbaseurl}}/vue">Vue.js Integration</a></li>
1011
<li><a href="{{site.headerbaseurl}}/showcases">Customer Showcases</a></li>
1112
<li><a href="{{site.headerbaseurl}}/roadmap-and-releases">Roadmap &amp; Release Notes</a></li>
@@ -16,9 +17,12 @@
1617
<span>Developers</span>
1718
<ul>
1819
<li><a href="https://play.nativescript.org">Playground</a></li>
19-
<li><a href="https://market.nativescript.org/?tab=samples&framework=all_frameworks&category=all_samples">Code Samples</a></li>
20+
<li><a
21+
href="https://market.nativescript.org/?tab=samples&framework=all_frameworks&category=all_samples">Code
22+
Samples</a></li>
2023
<li><a href="{{site.headerbaseurl}}/books-and-videos">Books &amp; Videos</a></li>
21-
<li><a href="https://market.nativescript.org/?tab=templates&category=all_templates">App Templates</a></li>
24+
<li><a href="https://market.nativescript.org/?tab=templates&category=all_templates">App Templates</a>
25+
</li>
2226
</ul>
2327
</li>
2428
<li>
@@ -34,7 +38,8 @@
3438
<li>
3539
<span>Support</span>
3640
<ul>
37-
<li><a href="https://stackoverflow.com/questions/tagged/nativescript" target="_blank">Stack Overflow</a></li>
41+
<li><a href="https://stackoverflow.com/questions/tagged/nativescript" target="_blank">Stack Overflow</a>
42+
</li>
3843
<li><a href="{{site.headerbaseurl}}/faq">FAQs</a></li>
3944
<li><a href="{{site.headerbaseurl}}/slack-invitation-form">Slack</a></li>
4045
<li><a href="{{site.headerbaseurl}}/developer-support">Professional Support</a></li>
@@ -54,13 +59,13 @@
5459
<a href="{{site.headerbaseurl}}/blog">Blogs</a>
5560
</li>
5661
<li>
57-
<span class="k-link -github"><a href="https://github.com/NativeScript/NativeScript"><i class="fab fa-github"></i></a></span>
62+
<span class="k-link -github"><a href="https://github.com/NativeScript/NativeScript"><i
63+
class="fab fa-github"></i></a></span>
5864
</li>
5965
<li>
60-
<!--
66+
6167
<a class="ns-button -action" href="https://play.nativescript.org/?utm_medium=website&utm_campaign=useownrealestate&utm_source=docsnativescriptdotcom&utm_content=topnavgreenbutton">Get Started</a>
62-
-->
63-
<a class="ns-button -action" href="https://www.nativescript.org/getting-started-with-nativescript?utm_medium=website&utm_campaign=useownrealestate&utm_source=docsnativescriptdotcom&utm_content=topnavgreenbutton">Get Started</a>
68+
6469
</li>
6570
<li>
6671
<span id="current-version"></span>
@@ -70,49 +75,56 @@
7075
</ul>
7176
</div>
7277
<script>
73-
$.getJSON( "https://raw.githubusercontent.com/tsonevn/docstest/master/versions.json", function( data ) {
74-
var baseUrl = document.location.origin;
75-
data["versions"].forEach( function( val ) {
76-
if(baseUrl.indexOf(val['url']) >= 0){
77-
$('#current-version').text("Current version "+val['version']);
78-
$('#versions-list').append("<li class='k-item k-state-active k-first'><a class='k-link' id='" + val['url'] + "'>Version "+val['version']+"</a></li>")
79-
} else{
80-
$('#versions-list').append("<li class='k-item k-state-default k-first'><a class='k-link' id='" + val['url'] + "'>Version "+val['version']+"</a></li>")
78+
function getCookie(n) { for (var t = n + "=", e = document.cookie.split(";"), r = 0; r < e.length; r++) { for (var i = e[r]; " " === i.charAt(0);)i = i.substring(1, i.length); if (0 === i.indexOf(t)) return i.substring(t.length, i.length) } return null }
79+
function setCookie(e, t, i) { var o; if (i) { var n = new Date; n.setTime(n.getTime() + 24 * i * 60 * 60 * 1e3), o = "; expires=" + n.toGMTString() } else o = ""; document.cookie = e + "=" + t + o + "; path=/" }
80+
$.getJSON("https://raw.githubusercontent.com/tsonevn/docstest/master/versions.json", function (data) {
81+
var varray = data[`versions`].sort((a, b) => parseFloat(a[`version`]) - parseFloat(b[`version`]));
82+
var docsUrl = window.location.href;
83+
var baseUrl = window.location.origin;
84+
var currentvfound = false;
85+
var name = "ns-current-base-url";
86+
for (var i = 0; i < varray.length-1; i++) {
87+
var currentversion = (varray[i]['version'].replace(/\s/g, "")).replace(".", "_");
88+
var itemUrl = baseUrl + "/" + currentversion;
89+
if ((docsUrl.indexOf(currentversion) >= 0) && (!currentvfound)) {
90+
currentvfound = true
91+
$('#current-version').text("Current version " + varray[i]['version']);
92+
setCookie(name, itemUrl, 1);
93+
8194
}
82-
});
83-
$('#versions-list a').click(function(ev) {
95+
$('#versions-list').append("<li class='k-item k-state-default k-first'><a class='k-link' id='" + itemUrl + "'>Version " + varray[i]['version'] + "</a></li>");
96+
}
97+
var lastindex = varray.length - 1;
98+
$('#versions-list').append("<li class='k-item k-state-default k-first'><a class='k-link' id='" + baseUrl + "'>Version " + varray[lastindex]['version'] + "</a></li>");
99+
if (!currentvfound) {
100+
currentvfound = true;
101+
$('#current-version').text("Current version " + varray[lastindex]['version']);
102+
setCookie(name, baseUrl, 1);
103+
}
104+
$('#versions-list a').click(function (ev) {
84105
ev.preventDefault();
106+
var name = "ns-current-base-url";
107+
var newBaseUrl = event.target.id;
108+
var currentBaseUrl = getCookie(name);
85109
var url = window.location.href;
86-
var baseUrlPattern = /^https?:\/\/[a-z\:0-9.]+/;
87-
var result = "";
88-
89-
var match = baseUrlPattern.exec(url);
90-
if (match != null) {
91-
result = match[0];
92-
}
93-
var targetURL = undefined;
94-
if ((result.length > 0) && (event.target.id) && (result != event.target.id)) {
95-
targetURL = event.target.id;
96-
url = url.replace(result, targetURL);
110+
if (newBaseUrl != currentBaseUrl) {
111+
112+
var newUrl = url.replace(currentBaseUrl, newBaseUrl);
113+
setCookie(name, newBaseUrl, 1);
97114
$.ajax({
98115
type: 'HEAD',
99-
url: url,
100-
success: function(){
101-
window.location.replace(url);
102-
window.location.href = url;
116+
url: newUrl,
117+
success: function () {
118+
window.location.href = newUrl;
103119
},
104-
error: function(err) {
105-
window.location.href=targetURL;
120+
error: function (err) {
121+
window.location.href = newBaseUrl;
106122
}
107123
});
108-
} else {
109-
console.log("Error: no targetURL")
124+
110125
}
111-
112-
// document.getElementById(divId).className = '';
113-
});
126+
});
114127
})
115-
116128
</script>
117129
<script>
118130
window.nsMenu = $(".ns-menu").remove();
@@ -133,4 +145,4 @@ <h1>Documentation</h1>
133145
</div>
134146
</div>
135147
</div>
136-
-->
148+
-->

build/nginx.conf

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ http {
4747
}
4848

4949
rewrite ^/$ /start/landing.html last;
50-
50+
51+
rewrite ^/(.*)/$ $proto://$host_and_port/$1/start/landing.html permanent;
52+
5153
{% for directory in site.redirect_directories %}
5254
rewrite ^/{{ directory.path }}/?$ $proto://$host_and_port/{{ directory.url }} permanent;
5355
{% endfor %}

0 commit comments

Comments
 (0)