1
0
Fork 0

Implement routing

This commit is contained in:
Alex Kotov 2023-03-25 21:25:56 +04:00
parent da5d97fbc2
commit 893a35506a
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
3 changed files with 25 additions and 15 deletions

View File

@ -6,12 +6,12 @@
<link rel="stylesheet" href="../bundle.css"/> <link rel="stylesheet" href="../bundle.css"/>
</head> </head>
<body> <body>
<div id="words-xxxxx"></div> <div id="app"></div>
<script <script
src="https://code.jquery.com/jquery-3.6.3.min.js" src="https://code.jquery.com/jquery-3.6.3.min.js"
integrity="sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU=" integrity="sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU="
crossorigin="anonymous"></script> crossorigin="anonymous"></script>
<script src="../bundle.js"></script> <script src="bundle.js"></script>
</body> </body>
</html> </html>

View File

@ -7,16 +7,26 @@ window.leqsikoni = {
} }
}, },
words_xxxxx: function() { app: function() {
window.leqsikoni.words_xxxxx_template() if ($('#app').length === 0) return;
var word_id = Number(window.location.hash.substring(1)) var path = String(window.location.hash).substring(1)
var match = null
if ((match = /^\/words\/(\d+)$/.exec(path))) {
window.leqsikoni.words_xxxxx(Number(match[1]))
}
},
words_xxxxx: function(word_id) {
window.leqsikoni.words_xxxxx_template()
$.getJSON( $.getJSON(
'http://localhost:4567/words/' + word_id, 'http://localhost:4567/words/' + word_id,
function(data) { function(data) {
document.title = window.leqsikoni.maybe_text(data.primary_form) || '' document.title = window.leqsikoni.maybe_text(data.primary_form) || ''
$('#words-xxxxx').html(window.leqsikoni.words_xxxxx_template(data)) $('#app').html(window.leqsikoni.words_xxxxx_template(data))
}, },
) )
}, },
@ -103,7 +113,7 @@ window.leqsikoni = {
if (other_word_id !== null) { if (other_word_id !== null) {
value = value =
'<a href="xxxxx.html#' + other_word_id + '">' + value + '</a>' '<a href="app.html#/words/' + other_word_id + '">' + value + '</a>'
} }
items_html.push( items_html.push(
@ -164,6 +174,6 @@ window.leqsikoni = {
} }
$(function() { $(function() {
$('#words-xxxxx').each(window.leqsikoni.words_xxxxx) window.addEventListener('hashchange', window.leqsikoni.app, false)
window.addEventListener('hashchange', window.leqsikoni.words_xxxxx, false) window.leqsikoni.app()
}) })

View File

@ -10,12 +10,12 @@
<h2>Глаголы</h2> <h2>Глаголы</h2>
<ol> <ol>
<li><a href="words/xxxxx.html#1">არის</a> - быть</li> <li><a href="app.html#/words/1">არის</a> - быть</li>
<li><a href="words/xxxxx.html#2">აქვს</a> - иметь (неодушевлённое)</li> <li><a href="app.html#/words/2">აქვს</a> - иметь (неодушевлённое)</li>
<li><a href="words/xxxxx.html#3">ყავს</a> - иметь (одушевлённое)</li> <li><a href="app.html#/words/3">ყავს</a> - иметь (одушевлённое)</li>
<li><a href="words/xxxxx.html#4">აქებს</a> - хвалить</li> <li><a href="app.html#/words/4">აქებს</a> - хвалить</li>
<li><a href="words/xxxxx.html#5">ცემს</a> - бить</li> <li><a href="app.html#/words/5">ცემს</a> - бить</li>
<li><a href="words/xxxxx.html#6">ხატავს</a> - рисовать</li> <li><a href="app.html#/words/6">ხატავს</a> - рисовать</li>
</ol> </ol>
<h2>Существительные</h2> <h2>Существительные</h2>