fixed scrolling, dont redirect to start state when not needed, caching headers
This commit is contained in:
parent
afaa8f6ba0
commit
7f3b7e0308
@ -131,7 +131,7 @@ SYSTEM.prototype.handle_call_pages_page = function (html,entry,id,forced,cached,
|
||||
this.state[entry['div']] = url;
|
||||
callback();
|
||||
};
|
||||
SYSTEM.prototype.handle_call_pages_entry = function (entry,id,forced,cached, callback) {
|
||||
SYSTEM.prototype.handle_call_pages_entry = function (entry,id,forced,cached,hash, 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 || system.state[entry['div']] !== url || !$(entry['div']).length || $(entry['div']).html() === ''){
|
||||
@ -139,10 +139,19 @@ SYSTEM.prototype.handle_call_pages_entry = function (entry,id,forced,cached, cal
|
||||
system.call_url(url,function(data){system.handle_call_pages_page(data,entry,id,forced,cached,callback);},{},'html',true);
|
||||
} else {
|
||||
system.log_info('load page: '+id+entry['div']+' '+url+' - cached');
|
||||
system.scroll(hash);
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
SYSTEM.prototype.scroll = function (element){
|
||||
if(element && $('#'+element).length){
|
||||
$('html,body').animate({scrollTop: $('#'+element).offset().top},'slow');
|
||||
} else {
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//internal function to handle pagestate results
|
||||
SYSTEM.prototype.handle_call_pages = function (data,id,forced,cached) {
|
||||
var hash = null;
|
||||
@ -164,33 +173,26 @@ SYSTEM.prototype.handle_call_pages = function (data,id,forced,cached) {
|
||||
//cache state info data
|
||||
this.state_info[id] = data;
|
||||
//update history?
|
||||
if( !(id === this.start_state && this.cur_state() === '') && //avoid start state in url unless called explicit
|
||||
if( !(id === this.start_state || this.cur_state() === '') && //avoid start state in url unless called explicit
|
||||
id !== this.cur_state()){//new state?
|
||||
window.history.pushState(null, "", '#!'+id+(hash ? '#'+hash : ''));}
|
||||
|
||||
//Syncronous Call to system.handle_call_pages_entry and done-function
|
||||
var done = function(){
|
||||
if(hash && $('#'+hash).length){
|
||||
$(document.body).animate({'scrollTop': $('#'+hash).offset().top-50}, 750);
|
||||
} else {
|
||||
$(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() {
|
||||
var loop = function(data_, i, process) {
|
||||
process(data_[i], id,forced,cached,hash, function() {
|
||||
if (++i < data_.length) {
|
||||
loop(data_, i, process, done);
|
||||
loop(data_, i, process, system.scroll);
|
||||
} else {
|
||||
done();
|
||||
system.scroll(hash);
|
||||
}
|
||||
});
|
||||
};
|
||||
loop(data_, 0, process, done);
|
||||
loop(data_, 0, process);
|
||||
} else {
|
||||
done();
|
||||
system.scroll(hash);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -56,7 +56,7 @@ class HEADER {
|
||||
*/
|
||||
public static function PNG(){
|
||||
if(self::checkHeader()){
|
||||
//header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 7*4*52))); // 1 week
|
||||
header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 7*4*52))); // 1 week
|
||||
header('content-type:image/png');}}
|
||||
/**
|
||||
* Send JPG Headers, if Header was not sent yet
|
||||
@ -83,7 +83,7 @@ class HEADER {
|
||||
*/
|
||||
public static function GIF(){
|
||||
if(self::checkHeader()){
|
||||
//header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 7))); // 1 week
|
||||
header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 7))); // 1 week
|
||||
header('content-type:image/gif');}}
|
||||
/**
|
||||
* Send JS Headers, if Header was not sent yet
|
||||
@ -119,6 +119,7 @@ class HEADER {
|
||||
* @return null Returns null
|
||||
*/
|
||||
public static function FILE($filename){
|
||||
header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 7))); // 1 week
|
||||
header("Content-type: application/octet-stream");
|
||||
header("Content-Disposition: attachment; filename=\"".$filename."\"");}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user