Browse Source

Adds setting for type of history event to use, adds set state behavior

pull/2229/head
jlukic 11 years ago
parent
commit
262aa13065
1 changed files with 24 additions and 8 deletions
  1. 32
      src/modules/tab.js

32
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',

Loading…
Cancel
Save