diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2016-10-17 23:09:21 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2017-05-29 21:01:53 +0200 |
commit | 599b6aab677439ae1bdea2cdca3233d0b763fd3f (patch) | |
tree | 8766f124271d056c8e8c22fd1a8a1ada08284275 /website2/resources/js/main.js | |
parent | 4e75ed8f8661033662b2d26c4a42fafa9d61b75f (diff) | |
download | lombok-599b6aab677439ae1bdea2cdca3233d0b763fd3f.tar.gz lombok-599b6aab677439ae1bdea2cdca3233d0b763fd3f.tar.bz2 lombok-599b6aab677439ae1bdea2cdca3233d0b763fd3f.zip |
Updated just about all of the pages to the template-based redesign.
Added ajaxified loading for feature pages.
Diffstat (limited to 'website2/resources/js/main.js')
-rw-r--r-- | website2/resources/js/main.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/website2/resources/js/main.js b/website2/resources/js/main.js new file mode 100644 index 00000000..497b310c --- /dev/null +++ b/website2/resources/js/main.js @@ -0,0 +1,54 @@ +"use strict"; + +(function($) { + swfobject.registerObject("player", "9.0.98", "videos/expressInstall.swf"); + + function toKey(href) { + var lnk = "__savedContent_" + href.replace(/\//g, '_'); + if (lnk.substring(lnk.length - 5) === ".html") lnk = lnk.substring(0, lnk.length - 5); + return lnk; + } + + function ajaxFeaturePages() { + if (!History.enabled) return; + History.replaceState({urlPath: window.location.pathname}, $("title").text(), History.getState().urlpath); + + $("a").each(function() { + var self = $(this); + var href = self.attr("href"); + if (!href) return; + if (href.substring(0, 10) !== "/features/") return; + self.on("click", function(evt) { + evt.preventDefault(); + var key = toKey(window.location.pathname); + if ($("#" + key).length < 1) { + var d = $("<div />").attr("id", key).append($("#featureContent").contents()).hide(); + $("body").append(d); + } + History.pushState({urlPath: href}, self.text(), href); + }); + }); + + $(window).on("statechange", function() { + var hs = History.getState(); + var u = hs.data.urlPath; + if (u.substring(u.length - 5) !== ".html") u += ".html"; + var key = toKey(u); + var sc = $("#" + key); + if (sc.length > 0) { + var a = $("#featureContent"); + sc.show().attr("id", "featureContent"); + a.replaceWith(sc); + } else { + $.ajax({ + url: u, + success: function(response) { + $("#featureContent").replaceWith($(response).find("#featureContent")); + } + }); + } + }); + } + + $(ajaxFeaturePages); +})($);
\ No newline at end of file |