From a2e5b6039f5814e5bdac9765a849865491d36290 Mon Sep 17 00:00:00 2001 From: Ward Meremans Date: Fri, 28 Mar 2014 09:10:38 +0100 Subject: [PATCH 1/2] fix($sniffer): check for older webkit browsers (< 534) Older webkit browsers have a problem with the history.pushState, which causes them to end up in an endless loop as soon as the angular app starts. Following browsers have this issue: native Android browser, Safari 5 and lower. --- src/ng/sniffer.js | 6 +++++- test/ng/snifferSpec.js | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/ng/sniffer.js b/src/ng/sniffer.js index c225ab8c1ff2..f94d90279664 100644 --- a/src/ng/sniffer.js +++ b/src/ng/sniffer.js @@ -21,6 +21,9 @@ function $SnifferProvider() { android = int((/android (\d+)/.exec(lowercase(($window.navigator || {}).userAgent)) || [])[1]), boxee = /Boxee/i.test(($window.navigator || {}).userAgent), + webkit = + int((/[a-z]*?webkit\/(\d+)/i.exec(lowercase(($window.navigator || {}).userAgent)) + || [])[1]), document = $document[0] || {}, documentMode = document.documentMode, vendorPrefix, @@ -63,7 +66,8 @@ function $SnifferProvider() { // so let's not use the history API also // We are purposefully using `!(android < 4)` to cover the case when `android` is undefined // jshint -W018 - history: !!($window.history && $window.history.pushState && !(android < 4) && !boxee), + history : !!($window.history && $window.history.pushState && !(android < 4) && !boxee + && !(webkit < 534)), // jshint +W018 hashchange: 'onhashchange' in $window && // IE8 compatible mode lies diff --git a/test/ng/snifferSpec.js b/test/ng/snifferSpec.js index 3f8d33510273..cd3b4e1d6b2a 100644 --- a/test/ng/snifferSpec.js +++ b/test/ng/snifferSpec.js @@ -332,6 +332,29 @@ describe('$sniffer', function() { expect($sniffer.history).toBe(false); }); }); + + it('should be false on Webkit versions older then 534.x.x', function() { + module(function($provide) { + var doc = { + body : { + style : {} + } + }; + var win = { + history : { + pushState : noop + }, + navigator : { + userAgent : 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; nl-nl) AppleWebkit/533.18.1 (KHTML, like Gecko) Version/5.0.2 Safari/533.18.5' + } + }; + $provide.value('$document', jqLite(doc)); + $provide.value('$window', win); + }); + inject(function($sniffer) { + expect($sniffer.history).toBe(false); + }); + }); }); it('should provide the android version', function() { From 7a31a15d1f17a640d1c7531099f54b944fcbd62f Mon Sep 17 00:00:00 2001 From: Ward Meremans Date: Fri, 28 Mar 2014 09:12:57 +0100 Subject: [PATCH 2/2] fix(input): add 5 milliseconds delay to the timeout function on change iOS7 fires the change event before the value gets updated in the input field, this causes validation errors and sometimes submits of incomplete data. Adding the extra 5 milliseconds solves this issue. --- src/ng/directive/input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index 2f78db049edd..cd9dfb22477f 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -933,7 +933,7 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) { timeout = $browser.defer(function() { listener(); timeout = null; - }); + },5); // Adding 5 milliseconds for iOS7 } };