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

Commit ac6d46e

Browse files
committed
removal($sniffer): remove $sniffer.vendorPrefix
Previously, Angular tried to detect the CSS prefix the browser supports and then use the saved one. This strategy is not ideal as currently some browsers are supporting more than one vendor prefix. The best example is Microsoft Edge that added -webkit- prefixes to be more Web-compatible; Firefox is doing a similar thing on mobile. Some of the -webkit--prefixed things are now even getting into specs to sanction that they're now required for Web compatibility. In some cases Edge even supports only the -webkit--prefixed property; one example is -webkit-appearance. $sniffer.vendorPrefix is no longer used in Angular core outside of $sniffer itself; taking that and the above problems into account, it's better to just remove it. The only remaining use case was an internal use in detection of support for transitions/animations but we can directly check the webkit prefix there manually; no other prefix matters for them anyway. $sniffer is undocumented API so this removal is not a breaking change. However, if you've previously been using it in your code, just paste the following to get the same function: var vendorPrefix = (function() { var prefix, prop, match; var vendorRegex = /^(Moz|webkit|ms)(?=[A-Z])/; for (prop in document.createElement('div').style) { if ((match = vendorRegex.exec(prop))) { prefix = match[0]; break; } } return prefix; })(); The vendorPrefix variable will contain what $sniffer.vendorPrefix used to. Note that we advise to not check for vendor prefixes this way; if you have to do it, it's better to check it separately for each CSS property used for the reasons described at the beginning. If you use jQuery, you don't have to do anything; it automatically adds vendor prefixes to CSS prefixes for you in the .css() method. Fixes #13690
1 parent 1997360 commit ac6d46e

File tree

4 files changed

+20
-71
lines changed

4 files changed

+20
-71
lines changed

src/ng/sniffer.js

+5-24
Original file line numberDiff line numberDiff line change
@@ -34,33 +34,15 @@ function $SnifferProvider() {
3434
toInt((/android (\d+)/.exec(lowercase(($window.navigator || {}).userAgent)) || [])[1]),
3535
boxee = /Boxee/i.test(($window.navigator || {}).userAgent),
3636
document = $document[0] || {},
37-
vendorPrefix,
38-
vendorRegex = /^(Moz|webkit|ms)(?=[A-Z])/,
3937
bodyStyle = document.body && document.body.style,
4038
transitions = false,
41-
animations = false,
42-
match;
39+
animations = false;
4340

4441
if (bodyStyle) {
45-
for (var prop in bodyStyle) {
46-
if ((match = vendorRegex.exec(prop))) {
47-
vendorPrefix = match[0];
48-
vendorPrefix = vendorPrefix[0].toUpperCase() + vendorPrefix.substr(1);
49-
break;
50-
}
51-
}
52-
53-
if (!vendorPrefix) {
54-
vendorPrefix = ('WebkitOpacity' in bodyStyle) && 'webkit';
55-
}
56-
57-
transitions = !!(('transition' in bodyStyle) || (vendorPrefix + 'Transition' in bodyStyle));
58-
animations = !!(('animation' in bodyStyle) || (vendorPrefix + 'Animation' in bodyStyle));
59-
60-
if (android && (!transitions || !animations)) {
61-
transitions = isString(bodyStyle.webkitTransition);
62-
animations = isString(bodyStyle.webkitAnimation);
63-
}
42+
// Support: Android <5, Blackberry Browser 10, default Chrome in Android 4.4.x
43+
// Mentioned browsers need a -webkit- prefix for transitions & animations.
44+
transitions = !!('transition' in bodyStyle || 'webkitTransition' in bodyStyle);
45+
animations = !!('animation' in bodyStyle || 'webkitAnimation' in bodyStyle);
6446
}
6547

6648

@@ -90,7 +72,6 @@ function $SnifferProvider() {
9072
return eventSupport[event];
9173
},
9274
csp: csp(),
93-
vendorPrefix: vendorPrefix,
9475
transitions: transitions,
9576
animations: animations,
9677
android: android

test/helpers/privateMocks.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function browserSupportsCssAnimations() {
3636
return !(window.document.documentMode < 10);
3737
}
3838

39-
function createMockStyleSheet(doc, prefix) {
39+
function createMockStyleSheet(doc) {
4040
doc = doc ? doc[0] : window.document;
4141

4242
var node = doc.createElement('style');
@@ -57,13 +57,17 @@ function createMockStyleSheet(doc, prefix) {
5757
},
5858

5959
addPossiblyPrefixedRule: function(selector, styles) {
60-
if (prefix) {
61-
var prefixedStyles = styles.split(/\s*;\s*/g).map(function(style) {
62-
return !style ? '' : prefix + style;
60+
// Support: Android <5, Blackberry Browser 10, default Chrome in Android 4.4.x
61+
// Mentioned browsers need a -webkit- prefix for transitions & animations.
62+
var prefixedStyles = styles.split(/\s*;\s*/g)
63+
.filter(function(style) {
64+
return style && /^(?:transition|animation)\b/.test(style);
65+
})
66+
.map(function(style) {
67+
return '-webkit-' + style;
6368
}).join('; ');
6469

65-
this.addRule(selector, prefixedStyles);
66-
}
70+
this.addRule(selector, prefixedStyles);
6771

6872
this.addRule(selector, styles);
6973
},

test/ng/snifferSpec.js

+4-39
Original file line numberDiff line numberDiff line change
@@ -172,39 +172,6 @@ describe('$sniffer', function() {
172172
});
173173

174174

175-
describe('vendorPrefix', function() {
176-
it('should return the correct vendor prefix based on the browser', function() {
177-
inject(function($sniffer, $window) {
178-
var expectedPrefix;
179-
var ua = $window.navigator.userAgent.toLowerCase();
180-
if (/edge/i.test(ua)) {
181-
expectedPrefix = 'Ms';
182-
} else if (/chrome/i.test(ua) || /safari/i.test(ua) || /webkit/i.test(ua)) {
183-
expectedPrefix = 'Webkit';
184-
} else if (/firefox/i.test(ua)) {
185-
expectedPrefix = 'Moz';
186-
} else if (/ie/i.test(ua) || /trident/i.test(ua)) {
187-
expectedPrefix = 'Ms';
188-
}
189-
expect($sniffer.vendorPrefix).toBe(expectedPrefix);
190-
});
191-
});
192-
193-
194-
it('should still work for an older version of Webkit', function() {
195-
var mockDocument = {
196-
body: {
197-
style: {
198-
WebkitOpacity: '0'
199-
}
200-
}
201-
};
202-
203-
expect(sniffer({}, mockDocument).vendorPrefix).toBe('webkit');
204-
});
205-
});
206-
207-
208175
describe('animations', function() {
209176
it('should be either true or false', inject(function($sniffer) {
210177
expect($sniffer.animations).toBeDefined();
@@ -222,13 +189,12 @@ describe('$sniffer', function() {
222189
});
223190

224191

225-
it('should be true with vendor-specific animations', function() {
192+
it('should be true with -webkit-prefixed animations', function() {
226193
var animationStyle = 'some_animation 2s linear';
227194
var mockDocument = {
228195
body: {
229196
style: {
230-
WebkitAnimation: animationStyle,
231-
MozAnimation: animationStyle
197+
webkitAnimation: animationStyle
232198
}
233199
}
234200
};
@@ -299,13 +265,12 @@ describe('$sniffer', function() {
299265
});
300266

301267

302-
it('should be true with vendor-specific transitions', function() {
268+
it('should be true with -webkit-prefixed transitions', function() {
303269
var transitionStyle = '1s linear all';
304270
var mockDocument = {
305271
body: {
306272
style: {
307-
WebkitTransition: transitionStyle,
308-
MozTransition: transitionStyle
273+
webkitTransition: transitionStyle
309274
}
310275
}
311276
};

test/ngAnimate/animateCssSpec.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ describe('ngAnimate $animateCss', function() {
4343
var ss, prefix, triggerAnimationStartFrame;
4444
beforeEach(module(function() {
4545
return function($document, $sniffer, $$rAF, $animate) {
46-
prefix = '-' + $sniffer.vendorPrefix.toLowerCase() + '-';
47-
ss = createMockStyleSheet($document, prefix);
46+
ss = createMockStyleSheet($document);
4847

4948
$animate.enabled(true);
5049
triggerAnimationStartFrame = function() {

0 commit comments

Comments
 (0)