Evan You 13 лет назад
Родитель
Сommit
646b790863
5 измененных файлов с 35 добавлено и 10 удалено
  1. 0 3
      TODO.md
  2. 2 1
      examples/simple.html
  3. 1 2
      src/config.js
  4. 25 2
      src/directives/index.js
  5. 7 2
      src/main.js

+ 0 - 3
TODO.md

@@ -1,7 +1,4 @@
 - parse textNodes
 - more directives / filters
-    - sd-if
     - sd-with
-    - sd-visible
-    - sd-style="transform:transform"
 - nested properties in scope (kinda hard, maybe later)

+ 2 - 1
examples/simple.html

@@ -6,11 +6,12 @@
         <script src="../dist/seed.js"></script>
     </head>
     <body sd-controller="hello">
-        <span sd-text="hello"></span>
+        <span sd-text="hello" sd-style="text-transform:format"></span>
         <script>
             var Seed = require('seed')
             Seed.controller('hello', function (scope) {
                 scope.hello = 'Hello World!'
+                scope.format = 'uppercase'
             })
             Seed.bootstrap()
         </script>

+ 1 - 2
src/config.js

@@ -1,6 +1,5 @@
 module.exports = {
     prefix: 'sd',
     controllers: {},
-    datum: {},
-    seeds: {}
+    datum: {}
 }

+ 25 - 2
src/directives/index.js

@@ -1,7 +1,17 @@
+var CONVERT_RE = /-(.)/g,
+    converter  = function (m, char) {
+        return char.toUpperCase()
+    }
+    
+function convertCSSProperty (prop) {
+    if (prop.charAt(0) === '-') prop = prop.slice(1)
+    return prop.replace(CONVERT_RE, converter)
+}
+
 module.exports = {
 
-    on   : require('./on'),
-    each : require('./each'),
+    on    : require('./on'),
+    each  : require('./each'),
 
     text: function (value) {
         this.el.textContent =
@@ -12,6 +22,10 @@ module.exports = {
     show: function (value) {
         this.el.style.display = value ? '' : 'none'
     },
+
+    visible: function (value) {
+        this.el.style.visibility = value ? '' : 'hidden'
+    },
     
     focus: function (value) {
         this.el[value ? 'focus' : 'blur']()
@@ -75,5 +89,14 @@ module.exports = {
                 }
             }
         }
+    },
+
+    style: {
+        bind: function () {
+            this.arg = convertCSSProperty(this.arg)
+        },
+        update: function (value) {
+            this.el.style[this.arg] = value
+        }
     }
 }

+ 7 - 2
src/main.js

@@ -5,7 +5,8 @@ var config      = require('./config'),
 
 var controllers = config.controllers,
     datum       = config.datum,
-    api         = {}
+    api         = {},
+    reserved    = ['datum', 'controllers']
 
 /*
  *  Store a piece of plain data in config.datum
@@ -54,7 +55,11 @@ api.filter = function (name, fn) {
  */
 api.bootstrap = function (opts) {
     if (opts) {
-        config.prefix = opts.prefix || config.prefix
+        for (var key in opts) {
+            if (reserved.indexOf(key) === -1) {
+                config[key] = opts[key]
+            }
+        }
     }
     var el,
         ctrlSlt = '[' + config.prefix + '-controller]',