made load substates syncronous to ensure everything is loaded in the right order
This commit is contained in:
parent
c9300ae1ef
commit
7136212b5e
@ -140,6 +140,33 @@ SYSTEM.prototype.handle_call_pages_entry = function (entry,id,forced,cached, cal
|
|||||||
callback();
|
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
|
//internal function to handle pagestate results
|
||||||
SYSTEM.prototype.handle_call_pages = function (data,id,forced,cached) {
|
SYSTEM.prototype.handle_call_pages = function (data,id,forced,cached) {
|
||||||
var hash = null;
|
var hash = null;
|
||||||
@ -165,22 +192,32 @@ SYSTEM.prototype.handle_call_pages = function (data,id,forced,cached) {
|
|||||||
id !== this.cur_state()){//new state?
|
id !== this.cur_state()){//new state?
|
||||||
window.history.pushState(null, "", '#!'+id+(hash ? '#'+hash : null));}
|
window.history.pushState(null, "", '#!'+id+(hash ? '#'+hash : null));}
|
||||||
|
|
||||||
var count = [];
|
//Syncronous Call to system.handle_call_pages_entry and done-function
|
||||||
data['result'].forEach(
|
var done = function(){
|
||||||
function(entry){
|
|
||||||
system.handle_call_pages_entry(entry,id,forced,cached,
|
|
||||||
function(d){
|
|
||||||
count.push(true);
|
|
||||||
if(count.length === data['result'].length){
|
|
||||||
if(hash && $('#'+hash).length){
|
if(hash && $('#'+hash).length){
|
||||||
$(document.body).animate({'scrollTop': $('#'+hash).offset().top-50}, 750);
|
$(document.body).animate({'scrollTop': $('#'+hash).offset().top-50}, 750);
|
||||||
} else {
|
} else {
|
||||||
$(document.body).animate({'scrollTop': 0}, 750);
|
$(document.body).animate({'scrollTop': 0}, 750);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
var data_ = data['result'];
|
||||||
|
var process = system.handle_call_pages_entry;
|
||||||
|
if (data_.length > 0) {
|
||||||
|
var loop = function(data_, i, process, done) {
|
||||||
|
process(data_[i], id,forced,cached, function() {
|
||||||
|
if (++i < data_.length) {
|
||||||
|
loop(data_, i, process, done);
|
||||||
|
} else {
|
||||||
|
done();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
loop(data_, 0, process, done);
|
||||||
|
} else {
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.log_info('Problem with your Pages: '+data['result']['message']);
|
this.log_info('Problem with your Pages: '+data['result']['message']);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user