Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit ef5bc6c

Browse files
Julien Bouquillonpetebacondarwin
Julien Bouquillon
authored andcommitted
fix($sniffer): detect transition/animation on older Android browsers
The stock Android browser doesn't support the current for-in body/style detection for animations and transitions but we can manually fix this. This is useful for PhoneGap web-views or traditional web-apps using the stock browser.
1 parent 22b9b47 commit ef5bc6c

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/ng/sniffer.js

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ function $SnifferProvider() {
3737
}
3838
transitions = !!(('transition' in bodyStyle) || (vendorPrefix + 'Transition' in bodyStyle));
3939
animations = !!(('animation' in bodyStyle) || (vendorPrefix + 'Animation' in bodyStyle));
40+
41+
if (android && (!transitions||!animations)) {
42+
transitions = isString(document.body.style.webkitTransition);
43+
animations = isString(document.body.style.webkitAnimation);
44+
}
4045
}
4146

4247

test/ng/snifferSpec.js

+44
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,28 @@ describe('$sniffer', function() {
179179
expect($sniffer.animations).toBe(true);
180180
});
181181
});
182+
183+
it('should be true on android with older body style properties', function() {
184+
module(function($provide) {
185+
var doc = {
186+
body : {
187+
style : {
188+
webkitAnimation: ''
189+
}
190+
}
191+
};
192+
var win = {
193+
navigator: {
194+
userAgent: 'android 2'
195+
}
196+
};
197+
$provide.value('$document', jqLite(doc));
198+
$provide.value('$window', win);
199+
});
200+
inject(function($sniffer) {
201+
expect($sniffer.animations).toBe(true);
202+
});
203+
});
182204
});
183205

184206
describe('transitions', function() {
@@ -238,5 +260,27 @@ describe('$sniffer', function() {
238260
});
239261
});
240262

263+
it('should be true on android with older body style properties', function() {
264+
module(function($provide) {
265+
var doc = {
266+
body : {
267+
style : {
268+
webkitTransition: ''
269+
}
270+
}
271+
};
272+
var win = {
273+
navigator: {
274+
userAgent: 'android 2'
275+
}
276+
};
277+
$provide.value('$document', jqLite(doc));
278+
$provide.value('$window', win);
279+
});
280+
inject(function($sniffer) {
281+
expect($sniffer.transitions).toBe(true);
282+
});
283+
});
284+
241285
});
242286
});

0 commit comments

Comments
 (0)