From 4f070d5b8e547b6e359dd8edd029d4e0c8710ddc Mon Sep 17 00:00:00 2001 From: xufei Date: Thu, 19 Jun 2014 20:15:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=EF=BC=8C=E5=8F=82=E8=A7=81staff.html?= =?UTF-8?q?=E4=B8=ADok=E6=8C=89=E9=92=AE=E7=9A=84=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/staff.html | 2 +- js/modules/core/binding.js | 44 ++++++++++++++++++++-------- js/modules/role/vm/staffViewModel.js | 10 +++++++ js/thin.js | 19 ------------ 4 files changed, 42 insertions(+), 33 deletions(-) diff --git a/demo/staff.html b/demo/staff.html index e341bde..29ad495 100644 --- a/demo/staff.html +++ b/demo/staff.html @@ -64,7 +64,7 @@

Detail

- +
diff --git a/js/modules/core/binding.js b/js/modules/core/binding.js index 2ae37f4..8bb2285 100644 --- a/js/modules/core/binding.js +++ b/js/modules/core/binding.js @@ -28,6 +28,8 @@ thin.define("DOMBinding", ["_"], function (_) { }; var vmMap = {}; + + var changeHandlers = []; function parseElement(element, vm) { var model = vm; @@ -108,31 +110,35 @@ thin.define("DOMBinding", ["_"], function (_) { vm.$watch(key, function (value, oldValue) { element.value = value || ""; }); - - /* - switch () { - case "TextInput": { - - } - } - */ - bindTextValue(element, key, vm); + + switch (element.tagName) { + case "SELECT": { + bindSelectValue(element, key, vm); + break; + } + default: { + bindTextValue(element, key, vm); + break; + } + } function bindTextValue(el, key, model) { - el.onkeyup = function () { model[key] = el.value; + thin.fire({type: "vmchange"}); }; el.onpaste = function () { model[key] = el.value; + thin.fire({type: "vmchange"}); }; } function bindSelectValue(el, key, model) { el.onchange = function () { vm[key] = el.value; - } + thin.fire({type: "vmchange"}); + }; } } @@ -160,6 +166,7 @@ thin.define("DOMBinding", ["_"], function (_) { vm.$initializer = (function (model) { return function () { model[key](); + thin.fire({type: "vmchange"}); }; })(vm); } @@ -169,6 +176,7 @@ thin.define("DOMBinding", ["_"], function (_) { element.onclick = function () { vm[key](); + thin.fire({type: "vmchange"}); }; } @@ -176,7 +184,7 @@ thin.define("DOMBinding", ["_"], function (_) { thin.log("binding enable: " + key); if (typeof vm[key] == "function") { - thin.schedule(function() { + changeHandlers.push(function() { element.disabled = vm[key]() ^ direction ? true : false; }); } @@ -191,7 +199,7 @@ thin.define("DOMBinding", ["_"], function (_) { thin.log("binding visible: " + key); if (typeof vm[key] == "function") { - thin.schedule(function() { + changeHandlers.push(function() { element.style.display = vm[key]() ^ direction ? "none" : ""; }); } @@ -201,6 +209,16 @@ thin.define("DOMBinding", ["_"], function (_) { }); } } + + function apply() { + for (var i=0; i= 5)) { + return true; + } + else { + return false; + } } }; diff --git a/js/thin.js b/js/thin.js index 65c9d01..ec635e3 100644 --- a/js/thin.js +++ b/js/thin.js @@ -3,8 +3,6 @@ var fileMap = {}; var readyFunctions = []; - var scheduleList = []; - var noop = function () { }; @@ -158,17 +156,6 @@ catch (ex) { } - }, - - nextTick: function(func) { - var timer = setTimeout(function(){ - func(); - clearTimeout(timer); - }, 50); - }, - - schedule: function(func) { - scheduleList.push(func); } }); @@ -176,12 +163,6 @@ win.thin = thin; - var timer = setInterval(function(){ - for (var i=0; i