diff --git a/Makefile b/Makefile index 42729b51e34..c472b63d6d5 100755 --- a/Makefile +++ b/Makefile @@ -30,6 +30,7 @@ FILES = js/jquery.ui.widget.js \ js/jquery.mobile.dialog.js \ js/jquery.mobile.navbar.js \ js/jquery.mobile.grid.js \ + js/jquery.mobile.flashMessage.js \ js/jquery.mobile.js CSSFILES = themes/default/jquery.mobile.theme.css \ @@ -47,7 +48,8 @@ CSSFILES = themes/default/jquery.mobile.theme.css \ themes/default/jquery.mobile.forms.select.css \ themes/default/jquery.mobile.forms.textinput.css \ themes/default/jquery.mobile.listview.css \ - themes/default/jquery.mobile.forms.slider.css + themes/default/jquery.mobile.forms.slider.css \ + themes/default/jquery.mobile.flashMessage.css all: mobile min css cssmin diff --git a/js/jquery.mobile.flashMessage.js b/js/jquery.mobile.flashMessage.js new file mode 100644 index 00000000000..3b9620fe886 --- /dev/null +++ b/js/jquery.mobile.flashMessage.js @@ -0,0 +1,29 @@ +/* +* jQuery Mobile Framework : "flashMessage" plugin +* flashes a brief message displaying whatever is in a +* container with data-role=flash, useful for short notices +* like "Your settings has been saved" +*/ + +(function($, undefined ) { + +$.widget( "mobile.flashMessage", $.mobile.widget, { + options: { + fadeOutTime: 1000 + }, + _create: function(o){ + $elem = this.element; + $elem.addClass('ui-flash'); + $elem.fadeOut( this.options.fadeOutTime, function(){ + $elem.remove(); + }); + } +}); + +$('.ui-page').live('pageshow', function(){ + $("[data-role='flash']").flashMessage(); +}); + +})( jQuery ); + + diff --git a/js/jquery.mobile.js b/js/jquery.mobile.js index 389f1ce0a3f..86f84727447 100644 --- a/js/jquery.mobile.js +++ b/js/jquery.mobile.js @@ -281,7 +281,7 @@ //wrap page and transfer data-attrs if it has an ID function wrapNewPage( newPage ){ - var copyAttrs = ['data-role', 'data-theme', 'data-fullscreen'], //TODO: more page-level attrs? + var copyAttrs = ['data-role', 'data-theme', 'data-fullscreen', 'data-cache'], //TODO: more page-level attrs? wrapper = newPage.wrap( "
" ).parent(); $.each(copyAttrs,function(i){ @@ -403,6 +403,7 @@ //shared page enhancements function enhancePage(){ + markPageCache( to ); setPageRole( to ); to.page(); } @@ -412,6 +413,43 @@ return url.match( '&' + $.mobile.subPageUrlKey ) ? url.split( '&' + $.mobile.subPageUrlKey )[0] : url; } + // Marks the page for a timed cache expiry + function markPageCache( to ) { + var pageCacheStrategy = to.data('cache'); + if( pageCacheStrategy && pageCacheStrategy != 'never' ) { + var currentTime = +new Date; + if( !isNaN(pageCacheStrategy) && !to.data('cache-expiration') ) { + // Page cache expiration isn't there. Put it there for future reference. + to.data('cache-expiration', ((pageCacheStrategy * 1000) + currentTime)); + } + } + } + + // Checks if the page should be removed due to: + // - cache expiry (data-cache holds number of seconds) + //
+ // + // - page not being allowed to cache + //
+ function invalidatePageCache( to ) { + var pageCacheStrategy = to.data('cache'), + forcePageReload = false; + + if( pageCacheStrategy ) { + forcePageReload = ( pageCacheStrategy == 'never' ); + if( !forcePageReload ) { + // Page is allowed to cache. Check if the expiration time is there. + var currentTime = +new Date; + if( !isNaN(pageCacheStrategy) && !isNaN(to.data('cache-expiration')) && to.data('cache-expiration') < currentTime ) { + // Page cache expiration is there and page has expired. Mark it for reload. + forcePageReload = true; + } + } + } + + return forcePageReload; + } + //if url is a string if( url ){ to = $( "[id='" + url + "']" ), @@ -426,8 +464,10 @@ } } + forcePageReload = invalidatePageCache(to); + // find the "to" page, either locally existing in the dom or by creating it through ajax - if ( to.length && !isFormRequest ) { + if ( !forcePageReload && to.length && !isFormRequest ) { if( fileUrl ){ setBaseURL(fileUrl); } diff --git a/themes/default/jquery.mobile.flashMessage.css b/themes/default/jquery.mobile.flashMessage.css new file mode 100644 index 00000000000..b32c9e5c542 --- /dev/null +++ b/themes/default/jquery.mobile.flashMessage.css @@ -0,0 +1,4 @@ +.ui-flash { position: absolute; opacity: .85; z-index: 10; top: 75px; left: 50%; width: 200px; margin-left: -130px; padding: 20px 30px; } +.ui-flash.error { background:#FBE3E4;color:#8a1f11;border-color:#FBC2C4;} +.ui-flash.notice { background:#FFF6BF;color:#514721;border-color:#FFD324;} +.ui-flash.success { background:#E6EFC2;color:#264409;border-color:#C6D880;}