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

Commit c1eceaf

Browse files
crisbetojelbourn
authored andcommitted
fix(constant): remove dependency on $sniffer (#9875)
The `$mdConstant` service uses Angular's `$sniffer` service to determine the browser's prefix via the `vendorPrefix`. `vendorPrefix` was removed with angular/angular.js@35482ba. These changes provide the same functionality, without depending on `$sniffer`. They also fix the current CI failures.
1 parent e3619e6 commit c1eceaf

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/core/util/constant.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@ angular.module('material.core')
55
* Factory function that creates the grab-bag $mdConstant service.
66
* @ngInject
77
*/
8-
function MdConstantFactory($sniffer, $window, $document) {
8+
function MdConstantFactory() {
99

10-
var vendorPrefix = $sniffer.vendorPrefix;
10+
var prefixTestEl = document.createElement('div');
11+
var vendorPrefix = getVendorPrefix(prefixTestEl);
1112
var isWebkit = /webkit/i.test(vendorPrefix);
1213
var SPECIAL_CHARS_REGEXP = /([:\-_]+(.))/g;
13-
var prefixTestEl = document.createElement('div');
1414

1515
function vendorProperty(name) {
1616
// Add a dash between the prefix and name, to be able to transform the string into camelcase.
1717
var prefixedName = vendorPrefix + '-' + name;
1818
var ucPrefix = camelCase(prefixedName);
1919
var lcPrefix = ucPrefix.charAt(0).toLowerCase() + ucPrefix.substring(1);
2020

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.
21+
return hasStyleProperty(prefixTestEl, name) ? name : // The current browser supports the un-prefixed property
22+
hasStyleProperty(prefixTestEl, ucPrefix) ? ucPrefix : // The current browser only supports the prefixed property.
23+
hasStyleProperty(prefixTestEl, lcPrefix) ? lcPrefix : name; // Some browsers are only supporting the prefix in lowercase.
2424
}
2525

26-
function hasStyleProperty(property) {
27-
return angular.isDefined(prefixTestEl.style[property]);
26+
function hasStyleProperty(testElement, property) {
27+
return angular.isDefined(testElement.style[property]);
2828
}
2929

3030
function camelCase(input) {
@@ -33,6 +33,17 @@ function MdConstantFactory($sniffer, $window, $document) {
3333
});
3434
}
3535

36+
function getVendorPrefix(testElement) {
37+
var prop, match;
38+
var vendorRegex = /^(Moz|webkit|ms)(?=[A-Z])/;
39+
40+
for (prop in testElement.style) {
41+
if (match = vendorRegex.exec(prop)) {
42+
return match[0];
43+
}
44+
}
45+
}
46+
3647
var self = {
3748
isInputKey : function(e) { return (e.keyCode >= 31 && e.keyCode <= 90); },
3849
isNumPadKey : function (e){ return (3 === e.location && e.keyCode >= 97 && e.keyCode <= 105); },

0 commit comments

Comments
 (0)