From 262aa1306533aa26bb806859752b8c9c410f96c2 Mon Sep 17 00:00:00 2001 From: jlukic Date: Fri, 18 Oct 2013 16:55:40 -0400 Subject: [PATCH] Adds setting for type of history event to use, adds set state behavior --- src/modules/tab.js | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/modules/tab.js b/src/modules/tab.js index 7bf78a7fe..36c7b7ed3 100755 --- a/src/modules/tab.js +++ b/src/modules/tab.js @@ -65,18 +65,26 @@ // attach history events if(settings.history) { + module.debug('Initializing page state'); if( $.address === undefined ) { module.error(error.state); return false; } - else if(settings.path === false) { - module.error(error.path); - return false; - } else { - module.verbose('Address library found adding state change event'); + if(settings.historyType == 'html5') { + module.debug('Using HTML5 to manage state'); + if(settings.path !== false) { + $.address + .history(true) + .state(settings.path) + ; + } + else { + module.error(error.path); + return false; + } + } $.address - .state(settings.path) .unbind('change') .bind('change', module.event.history.change) ; @@ -110,15 +118,16 @@ event: { click: function(event) { - module.debug('Navigation clicked'); var tabPath = $(this).data(metadata.tab) ; if(tabPath !== undefined) { if(settings.history) { + module.verbose('Updating page state', event); $.address.value(tabPath); } else { + module.verbose('Changing tab without state management', event); module.changeTab(tabPath); } event.preventDefault(); @@ -172,6 +181,12 @@ } }, + set: { + state: function(url) { + $.address.value(url); + } + }, + changeTab: function(tabPath) { var pushStateAvailable = (window.history && window.history.pushState), @@ -649,7 +664,8 @@ // uses pjax style endpoints fetching content from same url with remote-content headers auto : false, - history : false, + history : true, + historyType : 'hash', path : false, context : 'body',