aboutsummaryrefslogtreecommitdiffhomepage
path: root/js/bootstrap-history-tabs.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/bootstrap-history-tabs.js')
-rw-r--r--js/bootstrap-history-tabs.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/js/bootstrap-history-tabs.js b/js/bootstrap-history-tabs.js
new file mode 100644
index 0000000..9dfc49b
--- /dev/null
+++ b/js/bootstrap-history-tabs.js
@@ -0,0 +1,29 @@
++function ($) {
+ 'use strict';
+ $.fn.historyTabs = function() {
+ var that = this;
+ window.addEventListener('popstate', function(event) {
+ console.log(event);
+ if (event.state) {
+ $(that).filter('[href="' + event.state.url + '"]').tab('show');
+ } else {
+ $(that).filter('[href="#authentication"]').tab('show');
+ }
+ });
+ return this.each(function(index, element) {
+ $(element).on('show.bs.tab', function() {
+ var stateObject = {'url' : $(this).attr('href')};
+
+ if (stateObject.url !== window.location.hash) {
+ window.history.pushState(stateObject, document.title, window.location.pathname + $(this).attr('href'));
+ }
+ });
+ if (!window.location.hash && $(element).is('.active')) {
+ // Shows the first element if there are no query parameters.
+ $(element).tab('show');
+ } else if ($(this).attr('href') === window.location.hash) {
+ $(element).tab('show');
+ }
+ });
+ };
+}(jQuery); \ No newline at end of file