Просмотр исходного кода

refactor: get the vendor style name in the style directive (#5856)

laoxiong 9 лет назад
Родитель
Сommit
603d5fb894
1 измененных файлов с 9 добавлено и 9 удалено
  1. 9 9
      src/platforms/web/runtime/modules/style.js

+ 9 - 9
src/platforms/web/runtime/modules/style.js

@@ -26,20 +26,20 @@ const setProp = (el, name, val) => {
   }
 }
 
-const prefixes = ['Webkit', 'Moz', 'ms']
+const vendorNames = ['Webkit', 'Moz', 'ms']
 
-let testEl
+let emptyStyle
 const normalize = cached(function (prop) {
-  testEl = testEl || document.createElement('div')
+  emptyStyle = emptyStyle || document.createElement('div').style
   prop = camelize(prop)
-  if (prop !== 'filter' && (prop in testEl.style)) {
+  if (prop !== 'filter' && (prop in emptyStyle)) {
     return prop
   }
-  const upper = prop.charAt(0).toUpperCase() + prop.slice(1)
-  for (let i = 0; i < prefixes.length; i++) {
-    const prefixed = prefixes[i] + upper
-    if (prefixed in testEl.style) {
-      return prefixed
+  const capName = prop.charAt(0).toUpperCase() + prop.slice(1)
+  for (let i = 0; i < vendorNames.length; i++) {
+    const name = vendorNames[i] + capName
+    if (name in emptyStyle) {
+      return name
     }
   }
 })