|
4 | 4 | if(!String.prototype.startsWith){
|
5 | 5 | Object.defineProperty(String.prototype,'startsWith',{
|
6 | 6 | value:function(search,rawPos){
|
7 |
| -varpos=rawPos>0 ?rawPos|0 :0; |
| 7 | +constpos=rawPos>0 ?rawPos|0 :0; |
8 | 8 | returnthis.substring(pos,pos+search.length)===search;
|
9 | 9 | }
|
10 | 10 | });
|
11 | 11 | }
|
12 | 12 |
|
13 | 13 | // Parses versions in URL segments like:
|
14 | 14 | // "3", "dev", "release/2.7" or "3.6rc2"
|
15 |
| -varversion_regexs=[ |
| 15 | +constversion_regexs=[ |
16 | 16 | '(?:\\d)',
|
17 | 17 | '(?:\\d\\.\\d[\\w\\d\\.]*)',
|
18 | 18 | '(?:dev)',
|
19 | 19 | '(?:release/\\d.\\d[\\x\\d\\.]*)'];
|
20 | 20 |
|
21 |
| -varall_versions=$VERSIONS; |
22 |
| -varall_languages=$LANGUAGES; |
| 21 | +constall_versions=$VERSIONS; |
| 22 | +constall_languages=$LANGUAGES; |
23 | 23 |
|
24 | 24 | functionquote_attr(str){
|
25 | 25 | return'"'+str.replace('"','\\"')+'"';
|
26 | 26 | }
|
27 | 27 |
|
28 | 28 | functionbuild_version_select(release){
|
29 |
| -varbuf=['<select>']; |
30 |
| -varmajor_minor=release.split(".").slice(0,2).join("."); |
| 29 | +letbuf=['<select>']; |
| 30 | +constmajor_minor=release.split(".").slice(0,2).join("."); |
31 | 31 |
|
32 |
| -$.each(all_versions,function(version,title){ |
33 |
| -if(version==major_minor) |
| 32 | +Object.entries(all_versions).forEach(function([version,title]){ |
| 33 | +if(version===major_minor){ |
34 | 34 | buf.push('<option value='+quote_attr(version)+' selected="selected">'+release+'</option>');
|
35 |
| -else |
| 35 | +}else{ |
36 | 36 | buf.push('<option value='+quote_attr(version)+'>'+title+'</option>');
|
| 37 | +} |
37 | 38 | });
|
38 | 39 |
|
39 | 40 | buf.push('</select>');
|
40 | 41 | returnbuf.join('');
|
41 | 42 | }
|
42 | 43 |
|
43 | 44 | functionbuild_language_select(current_language){
|
44 |
| -varbuf=['<select>']; |
| 45 | +letbuf=['<select>']; |
45 | 46 |
|
46 |
| -$.each(all_languages,function(language,title){ |
47 |
| -if(language==current_language) |
48 |
| -buf.push('<option value="'+language+'" selected="selected">'+ |
49 |
| -all_languages[current_language]+'</option>'); |
50 |
| -else |
| 47 | +Object.entries(all_languages).forEach(function([language,title]){ |
| 48 | +if(language===current_language){ |
| 49 | +buf.push('<option value="'+language+'" selected="selected">'+title+'</option>'); |
| 50 | +}else{ |
51 | 51 | buf.push('<option value="'+language+'">'+title+'</option>');
|
| 52 | +} |
52 | 53 | });
|
53 | 54 | if(!(current_languageinall_languages)){
|
54 | 55 | // In case we're browsing a language that is not yet in all_languages.
|
|
62 | 63 |
|
63 | 64 | functionnavigate_to_first_existing(urls){
|
64 | 65 | // Navigate to the first existing URL in urls.
|
65 |
| -varurl=urls.shift(); |
| 66 | +consturl=urls.shift(); |
66 | 67 | if(urls.length==0||url.startsWith("file:///")){
|
67 | 68 | window.location.href=url;
|
68 | 69 | return;
|
69 | 70 | }
|
70 |
| -$.ajax({ |
71 |
| -url:url, |
72 |
| -success:function(){ |
73 |
| -window.location.href=url; |
74 |
| -}, |
75 |
| -error:function(){ |
| 71 | +fetch(url) |
| 72 | +.then(function(response){ |
| 73 | +if(response.ok){ |
| 74 | +window.location.href=url; |
| 75 | +}else{ |
| 76 | +navigate_to_first_existing(urls); |
| 77 | +} |
| 78 | +}) |
| 79 | +.catch(function(error){ |
76 | 80 | navigate_to_first_existing(urls);
|
77 |
| -} |
78 |
| -}); |
| 81 | +}); |
79 | 82 | }
|
80 | 83 |
|
81 | 84 | functionon_version_switch(){
|
82 |
| -varselected_version=$(this).children('option:selected').attr('value')+'/'; |
83 |
| -varurl=window.location.href; |
84 |
| -varcurrent_language=language_segment_from_url(); |
85 |
| -varcurrent_version=version_segment_from_url(); |
86 |
| -varnew_url=url.replace('/'+current_language+current_version, |
87 |
| -'/'+current_language+selected_version); |
| 85 | +constselected_version=this.options[this.selectedIndex].value+'/'; |
| 86 | +consturl=window.location.href; |
| 87 | +constcurrent_language=language_segment_from_url(); |
| 88 | +constcurrent_version=version_segment_from_url(); |
| 89 | +constnew_url=url.replace('/'+current_language+current_version, |
| 90 | +'/'+current_language+selected_version); |
88 | 91 | if(new_url!=url){
|
89 | 92 | navigate_to_first_existing([
|
90 | 93 | new_url,
|
|
98 | 101 | }
|
99 | 102 |
|
100 | 103 | functionon_language_switch(){
|
101 |
| -varselected_language=$(this).children('option:selected').attr('value')+'/'; |
102 |
| -varurl=window.location.href; |
103 |
| -varcurrent_language=language_segment_from_url(); |
104 |
| -varcurrent_version=version_segment_from_url(); |
105 |
| -if(selected_language=='en/')// Special 'default' case forenglish. |
| 104 | +letselected_language=this.options[this.selectedIndex].value+'/'; |
| 105 | +consturl=window.location.href; |
| 106 | +constcurrent_language=language_segment_from_url(); |
| 107 | +constcurrent_version=version_segment_from_url(); |
| 108 | +if(selected_language=='en/')// Special 'default' case forEnglish. |
106 | 109 | selected_language='';
|
107 |
| -varnew_url=url.replace('/'+current_language+current_version, |
| 110 | +letnew_url=url.replace('/'+current_language+current_version, |
108 | 111 | '/'+selected_language+current_version);
|
109 | 112 | if(new_url!=url){
|
110 | 113 | navigate_to_first_existing([
|
|
117 | 120 | // Returns the path segment of the language as a string, like 'fr/'
|
118 | 121 | // or '' if not found.
|
119 | 122 | functionlanguage_segment_from_url(){
|
120 |
| -varpath=window.location.pathname; |
121 |
| -varlanguage_regexp='/((?:'+Object.keys(all_languages).join("|")+')/)' |
122 |
| -varmatch=path.match(language_regexp); |
| 123 | +constpath=window.location.pathname; |
| 124 | +constlanguage_regexp='/((?:'+Object.keys(all_languages).join("|")+')/)' |
| 125 | +constmatch=path.match(language_regexp); |
123 | 126 | if(match!==null)
|
124 | 127 | returnmatch[1];
|
125 | 128 | return'';
|
|
128 | 131 | // Returns the path segment of the version as a string, like '3.6/'
|
129 | 132 | // or '' if not found.
|
130 | 133 | functionversion_segment_from_url(){
|
131 |
| -varpath=window.location.pathname; |
132 |
| -varlanguage_segment=language_segment_from_url(); |
133 |
| -varversion_segment='(?:(?:'+version_regexs.join('|')+')/)'; |
134 |
| -varversion_regexp=language_segment+'('+version_segment+')'; |
135 |
| -varmatch=path.match(version_regexp); |
| 134 | +constpath=window.location.pathname; |
| 135 | +constlanguage_segment=language_segment_from_url(); |
| 136 | +constversion_segment='(?:(?:'+version_regexs.join('|')+')/)'; |
| 137 | +constversion_regexp=language_segment+'('+version_segment+')'; |
| 138 | +constmatch=path.match(version_regexp); |
136 | 139 | if(match!==null)
|
137 | 140 | returnmatch[1];
|
138 | 141 | return''
|
139 | 142 | }
|
140 | 143 |
|
141 | 144 | functioncreate_placeholders_if_missing(){
|
142 |
| -varversion_segment=version_segment_from_url(); |
143 |
| -varlanguage_segment=language_segment_from_url(); |
144 |
| -varindex="/"+language_segment+version_segment; |
| 145 | +constversion_segment=version_segment_from_url(); |
| 146 | +constlanguage_segment=language_segment_from_url(); |
| 147 | +constindex="/"+language_segment+version_segment; |
145 | 148 |
|
146 |
| -if($('.version_switcher_placeholder').length) |
| 149 | +if(document.querySelectorAll('.version_switcher_placeholder').length>0){ |
147 | 150 | return;
|
| 151 | +} |
148 | 152 |
|
149 |
| -varhtml='<span></span> \ |
| 153 | +consthtml='<span></span> \ |
150 | 154 | <span class="version_switcher_placeholder"></span> \
|
151 | 155 | <a href="/" id="indexlink">Documentation</a> »';
|
152 | 156 |
|
153 |
| -varprobable_places=[ |
| 157 | +constprobable_places=[ |
154 | 158 | "body>div.related>ul>li:not(.right):contains('Documentation'):first",
|
155 | 159 | "body>div.related>ul>li:not(.right):contains('documentation'):first",
|
156 | 160 | ];
|
157 | 161 |
|
158 |
| -for(vari=0;i<probable_places.length;i++){ |
159 |
| -varprobable_place=$(probable_places[i]); |
| 162 | +for(leti=0;i<probable_places.length;i++){ |
| 163 | +letprobable_place=$(probable_places[i]); |
160 | 164 | if(probable_place.length==1){
|
161 | 165 | probable_place.html(html);
|
162 | 166 | document.getElementById('indexlink').href=index;
|
|
165 | 169 | }
|
166 | 170 | }
|
167 | 171 |
|
168 |
| -$(document).ready(function(){ |
169 |
| -varlanguage_segment=language_segment_from_url(); |
170 |
| -varcurrent_language=language_segment.replace(/\/+$/g,'')||'en'; |
171 |
| -varversion_select=build_version_select(DOCUMENTATION_OPTIONS.VERSION); |
| 172 | +document.addEventListener('DOMContentLoaded',function(){ |
| 173 | +constlanguage_segment=language_segment_from_url(); |
| 174 | +constcurrent_language=language_segment.replace(/\/+$/g,'')||'en'; |
| 175 | +constversion_select=build_version_select(DOCUMENTATION_OPTIONS.VERSION); |
172 | 176 |
|
173 | 177 | create_placeholders_if_missing();
|
174 |
| -$('.version_switcher_placeholder').html(version_select); |
175 |
| -$('.version_switcher_placeholder select').bind('change',on_version_switch); |
176 | 178 |
|
177 |
| -varlanguage_select=build_language_select(current_language); |
| 179 | +letplaceholders=document.querySelectorAll('.version_switcher_placeholder'); |
| 180 | +placeholders.forEach(function(placeholder){ |
| 181 | +placeholder.innerHTML=version_select; |
178 | 182 |
|
179 |
| -$('.language_switcher_placeholder').html(language_select); |
180 |
| -$('.language_switcher_placeholder select').bind('change',on_language_switch); |
| 183 | +letselectElement=placeholder.querySelector('select'); |
| 184 | +selectElement.addEventListener('change',on_version_switch); |
| 185 | +}); |
| 186 | + |
| 187 | +constlanguage_select=build_language_select(current_language); |
| 188 | + |
| 189 | +placeholders=document.querySelectorAll('.language_switcher_placeholder'); |
| 190 | +placeholders.forEach(function(placeholder){ |
| 191 | +placeholder.innerHTML=language_select; |
| 192 | + |
| 193 | +letselectElement=placeholder.querySelector('select'); |
| 194 | +selectElement.addEventListener('change',on_language_switch); |
| 195 | +}); |
181 | 196 | });
|
182 | 197 | })();
|