Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/core/util/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ angular.module('material.core')
* Factory function that creates the grab-bag $mdConstant service.
* @ngInject
*/
function MdConstantFactory($sniffer, $window, $document) {
function MdConstantFactory() {

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

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

return hasStyleProperty(name) ? name : // The current browser supports the un-prefixed property
hasStyleProperty(ucPrefix) ? ucPrefix : // The current browser only supports the prefixed property.
hasStyleProperty(lcPrefix) ? lcPrefix : name; // Some browsers are only supporting the prefix in lowercase.
return hasStyleProperty(prefixTestEl, name) ? name : // The current browser supports the un-prefixed property
hasStyleProperty(prefixTestEl, ucPrefix) ? ucPrefix : // The current browser only supports the prefixed property.
hasStyleProperty(prefixTestEl, lcPrefix) ? lcPrefix : name; // Some browsers are only supporting the prefix in lowercase.
}

function hasStyleProperty(property) {
return angular.isDefined(prefixTestEl.style[property]);
function hasStyleProperty(testElement, property) {
return angular.isDefined(testElement.style[property]);
}

function camelCase(input) {
Expand All @@ -33,6 +33,17 @@ function MdConstantFactory($sniffer, $window, $document) {
});
}

function getVendorPrefix(testElement) {
var prop, match;
var vendorRegex = /^(Moz|webkit|ms)(?=[A-Z])/;

for (prop in testElement.style) {
if (match = vendorRegex.exec(prop)) {
return match[0];
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is returned if not a match? "" ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's undefined. That's what got returned before as well.


var self = {
isInputKey : function(e) { return (e.keyCode >= 31 && e.keyCode <= 90); },
isNumPadKey : function (e){ return (3 === e.location && e.keyCode >= 97 && e.keyCode <= 105); },
Expand Down