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 // attach history events
if(settings.history) { if(settings.history) {
module.debug('Initializing page state');
if( $.address === undefined ) { if( $.address === undefined ) {
module.error(error.state); module.error(error.state);
return false; return false;
} }
else if(settings.path === false) {
module.error(error.path);
return false;
}
else { 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 $.address
.state(settings.path)
.unbind('change') .unbind('change')
.bind('change', module.event.history.change) .bind('change', module.event.history.change)
; ;
@ -110,15 +118,16 @@
event: { event: {
click: function(event) { click: function(event) {
module.debug('Navigation clicked');
var var
tabPath = $(this).data(metadata.tab) tabPath = $(this).data(metadata.tab)
; ;
if(tabPath !== undefined) { if(tabPath !== undefined) {
if(settings.history) { if(settings.history) {
module.verbose('Updating page state', event);
$.address.value(tabPath); $.address.value(tabPath);
} }
else { else {
module.verbose('Changing tab without state management', event);
module.changeTab(tabPath); module.changeTab(tabPath);
} }
event.preventDefault(); event.preventDefault();
@ -172,6 +181,12 @@
} }
}, },
set: {
state: function(url) {
$.address.value(url);
}
},
changeTab: function(tabPath) { changeTab: function(tabPath) {
var var
pushStateAvailable = (window.history && window.history.pushState), pushStateAvailable = (window.history && window.history.pushState),
@ -649,7 +664,8 @@
// uses pjax style endpoints fetching content from same url with remote-content headers // uses pjax style endpoints fetching content from same url with remote-content headers
auto : false, auto : false,
history : false,
history : true,
historyType : 'hash',
path : false, path : false,
context : 'body', context : 'body',

Loading…
Cancel
Save