fixes to make statesystem work again, fixed hashchange user callback to include complete state - processing is up to the user now

This commit is contained in:
Ulf Gebhardt 2017-05-04 15:02:31 +02:00
parent 52f71e4165
commit 7e79b07f8c
2 changed files with 6 additions and 30 deletions

View File

@ -51,7 +51,7 @@ SYSTEM.prototype.hashchange = function () {
system.go_state(system.start_state);
//user callback
if(system.hash_change){
system.hash_change(system.cur_state().split(';')[0].split('(')[0]);}
system.hash_change(system.cur_state());}
};
SYSTEM.prototype.handle_call_pages_page = function (html,entry,id,forced,cached,callback) {
var url = entry['url']+(window.location.search.substr(1) ? '&'+window.location.search.substr(1) : '' );
@ -132,41 +132,15 @@ SYSTEM.prototype.handle_call_pages_page = function (html,entry,id,forced,cached,
SYSTEM.prototype.handle_call_pages_entry = function (entry,id,forced,cached, callback) {
var url = entry['url']+(window.location.search.substr(1) ? '&'+window.location.search.substr(1) : '' );
//check loaded state of div - reload only if required
if(forced || this.state[entry['div']] !== url || !$(entry['div']).length || $(entry['div']).html() === ''){
if(forced || system.state[entry['div']] !== url || !$(entry['div']).length || $(entry['div']).html() === ''){
//load page
this.call_url(url,function(data){system.handle_call_pages_page(data,entry,id,forced,cached,callback);},{},'html',true);
system.call_url(url,function(data){system.handle_call_pages_page(data,entry,id,forced,cached,callback);},{},'html',true);
} else {
this.log_info('load page: '+id+entry['div']+' '+url+' - cached');
system.log_info('load page: '+id+entry['div']+' '+url+' - cached');
callback();
}
}
/**
* Process an array of data synchronously.
*
* @param data An array of data.
* @param processData A function that processes an item of data.
* Signature: function(item, i, callback), where {@code item} is the i'th item,
* {@code i} is the loop index value and {@code calback} is the
* parameterless function to call on completion of processing an item.
*/
function doSynchronousLoop(data, processData, done) {
if (data.length > 0) {
var loop = function(data, i, processData, done) {
processData(data[i], i, function() {
if (++i < data.length) {
loop(data, i, processData, done);
} else {
done();
}
});
};
loop(data, 0, processData, done);
} else {
done();
}
}
//internal function to handle pagestate results
SYSTEM.prototype.handle_call_pages = function (data,id,forced,cached) {
var hash = null;

View File

@ -9,6 +9,8 @@ $(document).ready(function() {
});
function sys_hashchange(state){
console.log(state);
state = state ? state.split(';')[0].split('(')[0] : state;
$('.nav li,#sai_navbar li, #project_navbar li').each(function(){
$(this).removeClass('active');});
if($('#menu_'+state).parent().length){