|
62 | 62 | -->
|
63 | 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>
|
64 | 64 | </li>
|
65 |
| - <li> |
66 |
| - <span id="current-version"></span> |
| 65 | + <li x-data="alp_Versions()" x-init="init()"> |
| 66 | + <span id="current-version" x-text="`Current Version ${current}`"></span> |
67 | 67 | <ul id="versions-list">
|
| 68 | + <template x-for="v in versions"> |
| 69 | + <li class="k-item k-state-default k-first"> |
| 70 | + <a class="k-link" |
| 71 | + x-bind:href="v.url" |
| 72 | + x-text="`Version ${v.version}`" |
| 73 | + ></a> |
| 74 | + </li> |
| 75 | + </template> |
68 | 76 | </ul>
|
69 | 77 | </li>
|
70 | 78 | </ul>
|
71 | 79 | </div>
|
| 80 | +<script src=" https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine.min.js" defer></script> |
72 | 81 | <script>
|
73 |
| - 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 } |
74 |
| - 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=/" } |
75 |
| - var urlJSON = window.location.origin.concat("/docs_versions.json"); |
76 |
| - $.getJSON(urlJSON, function (data) { |
77 |
| - var varray = data[`versions`].sort((a, b) => parseFloat(a[`version`]) - parseFloat(b[`version`])); |
78 |
| - var docsUrl = window.location.href; |
79 |
| - var baseUrl = window.location.origin; |
80 |
| - var currentvfound = false; |
81 |
| - var name = "ns-current-base-url"; |
82 |
| - for (var i = 0; i < varray.length-1; i++) { |
83 |
| - var currentversion = (varray[i]['version'].replace(/\s/g, "")).replace(".", "-"); |
84 |
| - var itemUrl = baseUrl + "/" + currentversion; |
85 |
| - if ((docsUrl.indexOf(currentversion) >= 0) && (!currentvfound)) { |
86 |
| - currentvfound = true |
87 |
| - $('#current-version').text("Current version " + varray[i]['version']); |
88 |
| - setCookie(name, itemUrl, 1); |
| 82 | + function alp_Versions() { |
| 83 | + return { |
| 84 | + init() { |
| 85 | + const versionsJSON = window.location.origin.concat("/docs_versions.json"); |
| 86 | + const versionJSON = window.location.origin.concat("/version.json"); |
89 | 87 |
|
90 |
| - } |
91 |
| - $('#versions-list').append("<li class='k-item k-state-default k-first'><a class='k-link' id='" + itemUrl + "'>Version " + varray[i]['version'] + "</a></li>"); |
92 |
| - } |
93 |
| - var lastindex = varray.length - 1; |
94 |
| - $('#versions-list').append("<li class='k-item k-state-default k-first'><a class='k-link' id='" + baseUrl + "'>Version " + varray[lastindex]['version'] + "</a></li>"); |
95 |
| - if (!currentvfound) { |
96 |
| - currentvfound = true; |
97 |
| - $('#current-version').text("Current version " + varray[lastindex]['version']); |
98 |
| - setCookie(name, baseUrl, 1); |
| 88 | + // const versions = { |
| 89 | + // "versions": [ |
| 90 | + // { |
| 91 | + // "version": "7.0", |
| 92 | + // "url": "https://docs.nativescript.org" |
| 93 | + // }, |
| 94 | + // { |
| 95 | + // "version": "6.0", |
| 96 | + // "url": "https://v6.docs.nativescript.org" |
| 97 | + // }, |
| 98 | + // ] |
| 99 | + // } |
| 100 | + // this.versions = versions.versions; |
| 101 | + |
| 102 | + $.getJSON(versionsJSON, function (data) { |
| 103 | + this.versions = data.versions; |
| 104 | + }) |
| 105 | + $.getJSON(versionJSON, function (data) { |
| 106 | + this.current = data.current |
| 107 | + }) |
| 108 | + }, |
| 109 | + |
| 110 | + // data |
| 111 | + versions: [], |
| 112 | + current: 'x.x', |
99 | 113 | }
|
100 |
| - $('#versions-list a').click(function (ev) { |
101 |
| - ev.preventDefault(); |
102 |
| - var name = "ns-current-base-url"; |
103 |
| - var newBaseUrl = event.target.id; |
104 |
| - var currentBaseUrl = getCookie(name); |
105 |
| - var url = window.location.href; |
106 |
| - if (newBaseUrl != currentBaseUrl) { |
| 114 | + } |
| 115 | + // 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 } |
| 116 | + // 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=/" } |
| 117 | + // var urlJSON = window.location.origin.concat("/docs_versions.json"); |
| 118 | + // $.getJSON(urlJSON, function (data) { |
| 119 | + // var varray = data[`versions`].sort((a, b) => parseFloat(a[`version`]) - parseFloat(b[`version`])); |
| 120 | + // var docsUrl = window.location.href; |
| 121 | + // var baseUrl = window.location.origin; |
| 122 | + // var currentvfound = false; |
| 123 | + // var name = "ns-current-base-url"; |
| 124 | + // for (var i = 0; i < varray.length-1; i++) { |
| 125 | + // var currentversion = (varray[i]['version'].replace(/\s/g, "")).replace(".", "-"); |
| 126 | + // var itemUrl = baseUrl + "/" + currentversion; |
| 127 | + // if ((docsUrl.indexOf(currentversion) >= 0) && (!currentvfound)) { |
| 128 | + // currentvfound = true |
| 129 | + // $('#current-version').text("Current version " + varray[i]['version']); |
| 130 | + // setCookie(name, itemUrl, 1); |
| 131 | + |
| 132 | + // } |
| 133 | + // $('#versions-list').append("<li class='k-item k-state-default k-first'><a class='k-link' id='" + itemUrl + "'>Version " + varray[i]['version'] + "</a></li>"); |
| 134 | + // } |
| 135 | + // var lastindex = varray.length - 1; |
| 136 | + // $('#versions-list').append("<li class='k-item k-state-default k-first'><a class='k-link' id='" + baseUrl + "'>Version " + varray[lastindex]['version'] + "</a></li>"); |
| 137 | + // if (!currentvfound) { |
| 138 | + // currentvfound = true; |
| 139 | + // $('#current-version').text("Current version " + varray[lastindex]['version']); |
| 140 | + // setCookie(name, baseUrl, 1); |
| 141 | + // } |
| 142 | + // $('#versions-list a').click(function (ev) { |
| 143 | + // ev.preventDefault(); |
| 144 | + // var name = "ns-current-base-url"; |
| 145 | + // var newBaseUrl = event.target.id; |
| 146 | + // var currentBaseUrl = getCookie(name); |
| 147 | + // var url = window.location.href; |
| 148 | + // if (newBaseUrl != currentBaseUrl) { |
107 | 149 |
|
108 |
| - var newUrl = url.replace(currentBaseUrl, newBaseUrl); |
109 |
| - setCookie(name, newBaseUrl, 1); |
110 |
| - $.ajax({ |
111 |
| - type: 'HEAD', |
112 |
| - url: newUrl, |
113 |
| - success: function () { |
114 |
| - window.location.href = newUrl; |
115 |
| - }, |
116 |
| - error: function (err) { |
117 |
| - window.location.href = newBaseUrl; |
118 |
| - } |
119 |
| - }); |
| 150 | + // var newUrl = url.replace(currentBaseUrl, newBaseUrl); |
| 151 | + // setCookie(name, newBaseUrl, 1); |
| 152 | + // $.ajax({ |
| 153 | + // type: 'HEAD', |
| 154 | + // url: newUrl, |
| 155 | + // success: function () { |
| 156 | + // window.location.href = newUrl; |
| 157 | + // }, |
| 158 | + // error: function (err) { |
| 159 | + // window.location.href = newBaseUrl; |
| 160 | + // } |
| 161 | + // }); |
120 | 162 |
|
121 |
| - } |
122 |
| - }); |
123 |
| - }) |
| 163 | + // } |
| 164 | + // }); |
| 165 | + // }) |
124 | 166 | </script>
|
125 | 167 | <script>
|
126 | 168 | window.nsMenu = $(".ns-menu").remove();
|
|
0 commit comments