Skip to content

Commit

Permalink
try harder to work in node
Browse files Browse the repository at this point in the history
  • Loading branch information
mdarens committed Jan 15, 2016
1 parent 9d5cc7d commit 16298ee
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "buryem",
"version": "1.2.0",
"version": "1.2.1",
"description": "got style conflicts? bury 'em!",
"main": "lib/buryem.js",
"author": "Mark D'Arensbourg",
Expand Down
2 changes: 1 addition & 1 deletion src/buryem.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { rulesToString, ruleToString } from './converter';
import hash from './hash';
import getVendorPrefix from "react-kit/getVendorPrefix";
import getVendorPrefix from "./prefix";

const oHash = (obj) => hash(JSON.stringify(obj));

Expand Down
2 changes: 1 addition & 1 deletion src/converter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import escape from './escape';
import isValidValue from './validator';
import getVendorPropertyName from 'react-kit/getVendorPropertyName';
import getVendorPropertyName from './property-name';

const _uppercasePattern = /([A-Z])/g;
const msPattern = /^ms-/;
Expand Down
19 changes: 19 additions & 0 deletions src/prefix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// based on react-kit/getVendorPrefix

let cssVendorPrefix;

export default () => {

if (cssVendorPrefix) {
return cssVendorPrefix;
}

if (!(window && document)) {
return '';
}

let styles = window.getComputedStyle(document.documentElement, '');
let pre = (Array.prototype.slice.call(styles).join('').match(/-(moz|webkit|ms)-/) || (styles.OLink === '' && ['', 'o']))[1];

return cssVendorPrefix = `-${pre}-`;
}
40 changes: 40 additions & 0 deletions src/property-name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// based on react-kit/getVendorPropertyName

let builtinStyle = document ? document.createElement('div').style : null;
let prefixes = ['Moz', 'Webkit', 'O', 'ms'];
let domVendorPrefix;

// Helper function to get the proper vendor property name. (transition => WebkitTransition)
export default (prop, isSupportTest) => {
if (!document) {
return '';
}

let vendorProp;
if (prop in builtinStyle) return prop;

let UpperProp = prop.charAt(0).toUpperCase() + prop.substr(1);

if (domVendorPrefix) {

vendorProp = domVendorPrefix + UpperProp;
if (vendorProp in builtinStyle) {
return vendorProp;
}
} else {

for (let i = 0; i < prefixes.length; ++i) {
vendorProp = prefixes[i] + UpperProp;
if (vendorProp in builtinStyle) {
domVendorPrefix = prefixes[i];
return vendorProp;
}
}
}

// if support test, not fallback to origin prop name
if (!isSupportTest) {
return prop;
}

}

0 comments on commit 16298ee

Please sign in to comment.