Created
November 10, 2010 13:52
-
-
Save andremedeiros/670865 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ( jQuery ) { | |
$( 'body' ).delegate( ".ui-page", "pagebeforeshow", function( event, opts ) { | |
var $page = $(event.target), | |
reloadPage = false, | |
cacheStrategy = $page.data('cache'), | |
pageInstance = $page.data('page'), | |
invalidateCache = pageInstance.dirtyCache; | |
// Check if page never gets cached | |
if ( cacheStrategy == 'never' ) { | |
reloadPage = true; | |
// Check if data-cache has a number. | |
} else if ( !isNaN( cacheStrategy ) ) { | |
var currentTime = +new Date; | |
if ( invalidateCache && currentTime > invalidateCache ) | |
reloadPage = true; | |
else if( !invalidateCache ) | |
pageInstance.dirtyCache = (cacheStrategy * 1000) + currentTime; | |
} | |
if ( reloadPage ) { | |
var url = $page.attr( 'id' ) || '/'; | |
$page.page( 'destroy' ); | |
$.ajax({ | |
url: url, | |
async: false, | |
cache: false, | |
context: $page, | |
success: function(data) { | |
this.html($(data).html()).page(); | |
} | |
}); | |
} | |
return true; | |
}); | |
})( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment