You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by so...@apache.org on 2017/06/07 08:08:07 UTC

[08/50] incubator-weex git commit: + [html5] add style util for css transform

+ [html5] add style util for css transform


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/b3f49bf6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/b3f49bf6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/b3f49bf6

Branch: refs/heads/0.14-dev
Commit: b3f49bf69becb6082b7ab55c61f8f6e32861e22c
Parents: 4b856ae
Author: MrRaindrop <te...@gmail.com>
Authored: Sat May 27 15:20:34 2017 +0800
Committer: MrRaindrop <te...@gmail.com>
Committed: Sat May 27 15:20:34 2017 +0800

----------------------------------------------------------------------
 html5/render/vue/utils/style.js | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b3f49bf6/html5/render/vue/utils/style.js
----------------------------------------------------------------------
diff --git a/html5/render/vue/utils/style.js b/html5/render/vue/utils/style.js
index c4f7d18..013ca82 100644
--- a/html5/render/vue/utils/style.js
+++ b/html5/render/vue/utils/style.js
@@ -162,6 +162,35 @@ export function normalizeStyle (style: {}) {
 }
 
 /**
+ * get transformObj
+ */
+export function getTransformObj (elm: HTMLElement): any {
+  let styleObj = {}
+  if (!elm) { return styleObj }
+  const transformStr = elm.style.webkitTransform || elm.style.transform
+  if (transformStr && transformStr.match(/(?: *(?:translate|rotate|scale)[^(]*\([^(]+\))+/i)) {
+    styleObj = transformStr.trim().replace(/, +/g, ',').split(' ').reduce(function (pre, str) {
+      ['translate', 'scale', 'rotate'].forEach(function (name) {
+        if (new RegExp(name, 'i').test(str)) {
+          pre[name] = str
+        }
+      })
+      return pre
+    }, {})
+  }
+  return styleObj
+}
+
+/**
+ * translate a transform string from a transformObj.
+ */
+export function getTransformStr (obj: {}): string {
+  return Object.keys(obj).reduce(function (pre, key) {
+    return pre + obj[key] + ' '
+  }, '')
+}
+
+/**
  * add transform style to element.
  * @param {HTMLElement} elm
  * @param {object} style: transform object, format is like this: