|
From: Lasse Kärkkäi. <tr...@us...> - 2012-11-15 02:08:25
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Thu Nov 15 04:07:37 2012 +0200
Javascript cleanup and bugfix.
---
htdocs-binary/js/main.js | 40 ++++++++++++++++++++++++++++++++++++++++
htdocs-source/Model.htm | 28 +---------------------------
2 files changed, 41 insertions(+), 27 deletions(-)
diff --git a/htdocs-binary/js/main.js b/htdocs-binary/js/main.js
new file mode 100644
index 0000000..2318d70
--- /dev/null
+++ b/htdocs-binary/js/main.js
@@ -0,0 +1,40 @@
+var currentPage = window.location.href;
+
+$('document').ready(function() {
+ $('#sitebox').videoBG({
+ position:"fixed",
+ zIndex:-1,
+ fullscreen:true,
+ mp4:'/bgs/GoldenDust.mp4',
+ ogv:'/bgs/GoldenDust.ogv',
+ webm:'/bgs/GoldenDust.webm',
+ poster:'/bgs/GoldenDust.jpg'
+ });
+ $('a').live('click', function(ev) {
+ // We don't handle external links...
+ if (ev.target.hostname != window.location.hostname) return;
+ // Instead of following link, manipulate history (location) and call switchPage to do the loading
+ history.pushState(null, "xhr", ev.target.href);
+ if (switchPage()) ev.preventDefault();
+ });
+ function switchPage() {
+ var href = window.location.href;
+ if (href == currentPage) return false; // Nothing to be done
+ currentPage = href;
+ $.ajax({
+ type: 'GET',
+ url: href,
+ success: function(data) {
+ // Update page content with data
+ $('#page').html($('#page', data).html());
+ },
+ error: function() {
+ window.location.href = href; // Fallback to old-fashion way
+ }
+ });
+ return true;
+ }
+ $(window).on("popstate", switchPage);
+});
+
+
diff --git a/htdocs-source/Model.htm b/htdocs-source/Model.htm
index c24d09e..c12746f 100644
--- a/htdocs-source/Model.htm
+++ b/htdocs-source/Model.htm
@@ -8,6 +8,7 @@
<link rel="icon" type="image/png" href="icon.png"/>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.videoBG.js"></script>
+ <script type="text/javascript" src="js/main.js"></script>
<script type="text/javascript" src="js/index-page.js"></script>
</head>
@@ -31,31 +32,4 @@
</div>
</body>
- <script type="text/javascript">
- $('#sitebox').videoBG({
- position:"fixed",
- zIndex:-1,
- fullscreen:true,
- mp4:'/bgs/GoldenDust.mp4',
- ogv:'/bgs/GoldenDust.ogv',
- webm:'/bgs/GoldenDust.webm',
- poster:'/bgs/GoldenDust.jpg'
- });
- $('a').live('click', function(ev) {
- if (ev.target.hostname != window.location.hostname) return;
- ev.preventDefault();
- var href = ev.target.href;
- $.ajax({
- type: 'GET',
- url: href,
- success: function(data) {
- history.pushState(null, "xhr", href);
- $('#page').html($('#page', data).html());
- },
- error: function() {
- window.location.href = href;
- }
- });
- });
- </script>
</html>
|