From d42db4d4ee0c8259515861462ea47c61c885f6b8 Mon Sep 17 00:00:00 2001 From: scottjehl Date: Tue, 2 Aug 2011 17:11:00 -0400 Subject: [PATCH] This change moves the ajax navigation opt-out list (which contains, mainly, browsers that have broken history tracking of hash changes) over to the support.js file, and added a multi-tierd Nokia condition that checks a number of UA conditions to try and pinpoint Nokia + Symbian + Webkit + 7.3-or-older. Big thanks to Bryan and Stephanie at Yiibu for their helpful article on Nokia device detection. That said, we would LOVE to find a non-UA based way to handle this detection. Reluctantly, this seems to do what we need at the moment, while assuming hash history will be improved in any post-7.3 release. Also included in this commit is a Nokia-specific condition that re-appends existing stylesheets to force them to render, as all pre-7.3 devices we tested would not render the CSS if it was referenced before the JavaScript (as we'd recommend doing). There may be a non-JS way to work around this problem, but for now, this seems to do the trick. --- js/jquery.mobile.init.js | 4 ++-- js/jquery.mobile.support.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/js/jquery.mobile.init.js b/js/jquery.mobile.init.js index b855dd66..1da3de32 100644 --- a/js/jquery.mobile.init.js +++ b/js/jquery.mobile.init.js @@ -24,7 +24,7 @@ // override ajaxEnabled on platforms that have known conflicts with hash history updates // or generally work better browsing in regular http for full page refreshes (BB5, Opera Mini) - if( window.blackberry && !window.WebKitPoint || window.operamini && Object.prototype.toString.call( window.operamini ) === "[object OperaMini]" ){ + if( $.mobile.ajaxBlacklist ){ $.mobile.ajaxEnabled = false; } @@ -117,7 +117,7 @@ //note that this initial scroll won't hide the address bar. It's just for the check. $(function(){ window.scrollTo( 0, 1 ); - + //if defaultHomeScroll hasn't been set yet, see if scrollTop is 1 //it should be 1 in most browsers, but android treats 1 as 0 (for hiding addr bar) //so if it's 1, use 0 from now on diff --git a/js/jquery.mobile.support.js b/js/jquery.mobile.support.js index dfb42c32..127e8ad1 100644 --- a/js/jquery.mobile.support.js +++ b/js/jquery.mobile.support.js @@ -79,6 +79,41 @@ $.extend( $.support, { fakeBody.remove(); + +// $.mobile.ajaxBlacklist is used to override ajaxEnabled on platforms that have known conflicts with hash history updates (BB5, Symbian) +// or that generally work better browsing in regular http for full page refreshes (Opera Mini) +// Note: This detection below is used as a last resort. +// We recommend only using these detection methods when all other more reliable/forward-looking approaches are not possible +var nokiaLTE7_3 = function(){ + + var ua = window.navigator.userAgent; + + //The following is an attempt to match Nokia browsers that are running Symbian/s60, with webkit, version 7.3 or older + return ua.indexOf( "Nokia" ) > -1 + && ( ua.indexOf( "Symbian/3" ) > -1 || ua.indexOf( "Series60/5" ) > -1 ) + && ua.indexOf( "AppleWebKit" ) > -1 + && ua.match( /(BrowserNG|NokiaBrowser)\/7\.[0-3]/ ); +}(); + +$.mobile.ajaxBlacklist = + // BlackBerry browsers, pre-webkit + window.blackberry && !window.WebKitPoint + // Opera Mini + || window.operamini && Object.prototype.toString.call( window.operamini ) === "[object OperaMini]" + // Symbian webkits pre 7.3 + || nokiaLTE7_3; + +// Lastly, this workaround is the only way we've found so far to get pre 7.3 Symbian webkit devices +// to render the stylesheets when they're referenced before this script, as we'd recommend doing. +// This simply reappends the CSS in place, which for some reason makes it apply +if( nokiaLTE7_3 ){ + $(function(){ + $( "head link[rel=stylesheet]" ).each(function(){ + $( this ).attr( "rel", "alternate stylesheet" ).attr( "rel", "stylesheet" ); + }); + }); +} + // For ruling out shadows via css if ( !$.support.boxShadow ){ $( "html" ).addClass( "ui-mobile-nosupport-boxshadow" );