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

Commit 6aa9e08

Browse files
devversionThomasBurleson
authored andcommitted
fix(constants): prefixes for properties should be correct.
* Some Android Browsers are requiring different prefixes * IE requires in some versions a lower-case prefix. * Old Firefox Versions are requiring a `Moz` prefix. * Chrome and latest Firefox are now supporting the un-prefixed property. This commit, checks the properties on the browser and validates the correct property. This makes sure, that the properties are working properly. Closes #8186. Closes #8187
1 parent bc2fac0 commit 6aa9e08

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/core/util/constant.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,30 @@ angular.module('material.core')
77
*/
88
function MdConstantFactory($sniffer) {
99

10-
var webkit = /webkit/i.test($sniffer.vendorPrefix);
10+
var vendorPrefix = $sniffer.vendorPrefix;
11+
var isWebkit = /webkit/i.test(vendorPrefix);
12+
var SPECIAL_CHARS_REGEXP = /([:\-_]+(.))/g;
13+
var prefixTestEl = document.createElement('div');
14+
1115
function vendorProperty(name) {
12-
return webkit ? ('webkit' + name.charAt(0).toUpperCase() + name.substring(1)) : name;
16+
// Add a dash between the prefix and name, to be able to transform the string into camelcase.
17+
var prefixedName = vendorPrefix + '-' + name;
18+
var ucPrefix = camelCase(prefixedName);
19+
var lcPrefix = ucPrefix.charAt(0).toLowerCase() + ucPrefix.substring(1);
20+
21+
return hasStyleProperty(name) ? name : // The current browser supports the un-prefixed property
22+
hasStyleProperty(ucPrefix) ? ucPrefix : // The current browser only supports the prefixed property.
23+
hasStyleProperty(lcPrefix) ? lcPrefix : name; // Some browsers are only supporting the prefix in lowercase.
24+
}
25+
26+
function hasStyleProperty(property) {
27+
return angular.isDefined(prefixTestEl.style[property]);
28+
}
29+
30+
function camelCase(input) {
31+
return input.replace(SPECIAL_CHARS_REGEXP, function(matches, separator, letter, offset) {
32+
return offset ? letter.toUpperCase() : letter;
33+
});
1334
}
1435

1536
return {
@@ -33,8 +54,8 @@ function MdConstantFactory($sniffer) {
3354
},
3455
CSS: {
3556
/* Constants */
36-
TRANSITIONEND: 'transitionend' + (webkit ? ' webkitTransitionEnd' : ''),
37-
ANIMATIONEND: 'animationend' + (webkit ? ' webkitAnimationEnd' : ''),
57+
TRANSITIONEND: 'transitionend' + (isWebkit ? ' webkitTransitionEnd' : ''),
58+
ANIMATIONEND: 'animationend' + (isWebkit ? ' webkitAnimationEnd' : ''),
3859

3960
TRANSFORM: vendorProperty('transform'),
4061
TRANSFORM_ORIGIN: vendorProperty('transformOrigin'),

0 commit comments

Comments
 (0)