From f20300244d231f43536a0dbdf24060ad81d726ce Mon Sep 17 00:00:00 2001 From: sunkencity Date: Tue, 9 Nov 2010 22:42:52 +0100 Subject: [PATCH 1/6] moved config for back button text to main config options --- js/jquery.mobile.js | 3 +++ js/jquery.mobile.page.js | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/js/jquery.mobile.js b/js/jquery.mobile.js index b9d8a07ecc4..27893972749 100644 --- a/js/jquery.mobile.js +++ b/js/jquery.mobile.js @@ -42,6 +42,9 @@ //show loading message during Ajax requests //if false, message will not appear, but loading classes will still be toggled on html el loadingMessage: "loading", + + //set text for back buttons + backBtnText: "Back", //configure meta viewport tag's content attr: metaViewportContent: "width=device-width, minimum-scale=1, maximum-scale=1", diff --git a/js/jquery.mobile.page.js b/js/jquery.mobile.page.js index 7f4ea9cfe33..ea7199e4615 100644 --- a/js/jquery.mobile.page.js +++ b/js/jquery.mobile.page.js @@ -2,7 +2,6 @@ jQuery.widget( "mobile.page", jQuery.mobile.widget, { options: { - backBtnText: "Back", addBackBtn: true, degradeInputs: { color: true, @@ -71,7 +70,7 @@ jQuery.widget( "mobile.page", jQuery.mobile.widget, { (jQuery.mobile.urlStack.length > 1 || jQuery(".ui-page").length > 1) && !leftbtn && !$this.data( "noBackBtn" ) ) { - jQuery( ""+ o.backBtnText +"" ) + jQuery( ""+ jQuery.mobile.backBtnText +"" ) .click(function() { history.back(); return false; From 6cb78c844064bb0695ed9a93f4755e48bfed1cdb Mon Sep 17 00:00:00 2001 From: sunkencity Date: Tue, 16 Nov 2010 18:40:24 +0100 Subject: [PATCH 2/6] reverted changes to i18n --- js/jquery.mobile.js | 3 --- js/jquery.mobile.page.js | 3 ++- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/js/jquery.mobile.js b/js/jquery.mobile.js index de5878be1dd..379da9650a0 100644 --- a/js/jquery.mobile.js +++ b/js/jquery.mobile.js @@ -42,9 +42,6 @@ //show loading message during Ajax requests //if false, message will not appear, but loading classes will still be toggled on html el loadingMessage: "loading", - - //set text for back buttons - backBtnText: "Back", //configure meta viewport tag's content attr: metaViewportContent: "width=device-width, minimum-scale=1, maximum-scale=1", diff --git a/js/jquery.mobile.page.js b/js/jquery.mobile.page.js index 4ff740c59a6..ad199273ed8 100644 --- a/js/jquery.mobile.page.js +++ b/js/jquery.mobile.page.js @@ -8,6 +8,7 @@ $.widget( "mobile.page", $.mobile.widget, { options: { + backBtnText: "Back" addBackBtn: true, degradeInputs: { color: false, @@ -76,7 +77,7 @@ $.widget( "mobile.page", $.mobile.widget, { ($.mobile.urlStack.length > 1 || $(".ui-page").length > 1) && !leftbtn && !$this.data( "noBackBtn" ) ) { - $( ""+ $.mobile.backBtnText +"" ) + $( ""+ o.backBtnText +"" ) .click(function() { history.back(); return false; From a7b6114e5000d73028d0be22d1eb826b6a50bead Mon Sep 17 00:00:00 2001 From: sunkencity Date: Wed, 17 Nov 2010 09:23:41 +0100 Subject: [PATCH 3/6] whoops - missing comma --- js/jquery.mobile.page.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/jquery.mobile.page.js b/js/jquery.mobile.page.js index ad199273ed8..b2e7a22346c 100644 --- a/js/jquery.mobile.page.js +++ b/js/jquery.mobile.page.js @@ -8,7 +8,7 @@ $.widget( "mobile.page", $.mobile.widget, { options: { - backBtnText: "Back" + backBtnText: "Back", addBackBtn: true, degradeInputs: { color: false, From 277673ccaba3710a00b2e3f0afa6d819e1df7a9f Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Thu, 4 Nov 2010 22:03:21 +0100 Subject: [PATCH 4/6] Added possibility to control a page's cache/validity through a data- property, like so: - cache expiry (data-cache holds number of seconds)
- page not being allowed to cache
Maintains default behaviour of pages being kept around.(cherry picked from commit b3e766f7f7a7041e64667744846c036e2abb0cfa) --- js/jquery.mobile.js | 49 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/js/jquery.mobile.js b/js/jquery.mobile.js index 379da9650a0..da9ca1ddb04 100644 --- a/js/jquery.mobile.js +++ b/js/jquery.mobile.js @@ -284,7 +284,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,48 @@ return url.match( '&' + $.mobile.subPageUrlKey ) ? url.split( '&' + $.mobile.subPageUrlKey )[0] : url; } + // Marks the page for a timed cache expiry + function markPageCache( to ) { + pageCacheStrategy = to.data('cache'); + if( pageCacheStrategy != undefined && pageCacheStrategy != 'never' ) { + pageCacheExpiry = parseInt(pageCacheStrategy, 10); + pageCacheExpiration = parseInt(to.data('cache-expiration'), 10); + currentTime = new Date().getTime(); + if( !isNaN(pageCacheExpiry) && isNaN(pageCacheExpiration) ) { + // Page cache expiration isn't there. Put it there for future reference. + to.data('cache-expiration', ((pageCacheExpiry * 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 ) { + pageCacheStrategy = to.data('cache'); + forcePageReload = false; + + if( pageCacheStrategy != undefined ) { + forcePageReload = ( pageCacheStrategy == 'never' ); + + if( !forcePageReload ) { + // Page is allowed to cache. Check if the expiration time is there. + pageCacheExpiry = parseInt(pageCacheStrategy, 10); + pageCacheExpiration = parseInt(to.data('cache-expiration'), 10); + currentTime = new Date().getTime(); + if( !isNaN(pageCacheExpiry) && !isNaN(pageCacheExpiration) && pageCacheExpiration < 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 +469,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); } From 879477af289f71d3f24cc20b446c00d32c92c66f Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Thu, 4 Nov 2010 22:36:15 +0100 Subject: [PATCH 5/6] Use vars; code cleanup;(cherry picked from commit ba32a4b9482bce548d119cebd45b519f23d2a800) --- js/jquery.mobile.js | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/js/jquery.mobile.js b/js/jquery.mobile.js index da9ca1ddb04..3d47ed064a5 100644 --- a/js/jquery.mobile.js +++ b/js/jquery.mobile.js @@ -415,14 +415,12 @@ // Marks the page for a timed cache expiry function markPageCache( to ) { - pageCacheStrategy = to.data('cache'); - if( pageCacheStrategy != undefined && pageCacheStrategy != 'never' ) { - pageCacheExpiry = parseInt(pageCacheStrategy, 10); - pageCacheExpiration = parseInt(to.data('cache-expiration'), 10); - currentTime = new Date().getTime(); - if( !isNaN(pageCacheExpiry) && isNaN(pageCacheExpiration) ) { + 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', ((pageCacheExpiry * 1000) + currentTime)); + to.data('cache-expiration', ((pageCacheStrategy * 1000) + currentTime)); } } } @@ -434,18 +432,15 @@ // - page not being allowed to cache //
function invalidatePageCache( to ) { - pageCacheStrategy = to.data('cache'); - forcePageReload = false; + var pageCacheStrategy = to.data('cache'), + forcePageReload = false; - if( pageCacheStrategy != undefined ) { + if( pageCacheStrategy ) { forcePageReload = ( pageCacheStrategy == 'never' ); - if( !forcePageReload ) { // Page is allowed to cache. Check if the expiration time is there. - pageCacheExpiry = parseInt(pageCacheStrategy, 10); - pageCacheExpiration = parseInt(to.data('cache-expiration'), 10); - currentTime = new Date().getTime(); - if( !isNaN(pageCacheExpiry) && !isNaN(pageCacheExpiration) && pageCacheExpiration < currentTime ) { + 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; } From 5ccadc3c4e9da24fd0f238839f15c07646a17c49 Mon Sep 17 00:00:00 2001 From: sunkencity Date: Wed, 17 Nov 2010 21:25:55 +0100 Subject: [PATCH 6/6] added flash message widget for growl style notifications --- Makefile | 4 ++- js/jquery.mobile.flashMessage.js | 29 +++++++++++++++++++ themes/default/jquery.mobile.flashMessage.css | 4 +++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 js/jquery.mobile.flashMessage.js create mode 100644 themes/default/jquery.mobile.flashMessage.css diff --git a/Makefile b/Makefile index 57892cb0b46..aed9b0fdae0 100755 --- a/Makefile +++ b/Makefile @@ -29,6 +29,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 \ @@ -46,7 +47,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/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;}