Skip to content

Commit 03f7f74

Browse files
committed
Added capability to pass default home page - v1.1
1 parent f796a38 commit 03f7f74

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

Example/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@
1414
</body>
1515
<script src="js/jquery.min.js"></script>
1616
<script src="js/liteweb.min.js?v=1.0"></script>
17+
<!-- pass a defualt home page. -->
18+
<!-- <script src="js/liteweb.min.js?v=1.0&d=about"></script> -->
1719
</html>

Example/js/liteweb.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

liteweb.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,30 @@
44
* @since 1.0
55
* @copyright MIT License
66
* @file: liteweb.js
7-
* @version 1.0
7+
* @version 1.1
88
* @author Robin Alex Panicker
99
**/
1010

1111
/** IMPORTANT: NEED TO DEPLOY THE SITE IN A WEBSERVER TO GET ROUTING WORKING **/
1212

13+
// Get params
14+
const q = new URLSearchParams (document.currentScript.src.split('?')[1]);
15+
1316
// current version
14-
const v = (new URLSearchParams (document.currentScript.src.split('?')[1])).get('v');
17+
const v = q.get('v');
1518

1619
// default page (home page) _home.html
17-
const d = "home";
20+
const d = q.get('d') != null ? q.get('d') : "home";
1821

1922
const g = function(f) {$.get('_'+f+'.html?v='+v, function(c){$('page').html(c)})}
2023

21-
const l = function(f) {
24+
const l = function() {
2225
let p = window.location.hash;
2326
g((p === null || p.length <= 1) ? d : p.substring(1, p.length));
2427
}
2528

26-
const r = function(){l()};
27-
2829
// load home page
29-
$(document).ready(r);
30+
$(document).ready(l);
3031

3132
// routing based on hash change
32-
$(window).on('hashchange',r);
33+
$(window).on('hashchange',l);

liteweb.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)