Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

start working on <input> tags bindings

  • Loading branch information...
commit acd3890681705f09a43583028ca4bb7a9fd584d3 1 parent da83f5f
yufeiliu authored
Showing with 8 additions and 4 deletions.
  1. +3 −0  demo.html
  2. +5 −4 src/_var.js
3  demo.html
View
@@ -24,12 +24,15 @@
<div id="clock-container">
It has been <strong id="clock-view"></strong> seconds since you refereshed this page.
+ <br/>
+ Works on input box as well: <input type="text" id="textbox" />
</div>
<script>
counter = 0;
_var("counter")
.bind(document.getElementById("clock-view"))
+ .bind(document.getElementById("textbox"))
//Remove binding after 30 seconds
.bind(function(val) {
if (val==30) {
9 src/_var.js
View
@@ -9,18 +9,19 @@ if (typeof(_var)==="undefined") {
(function() {
bindings = {};
_var = function() {
-
if (arguments.length<1) return this.bindings;
var vname = arguments[0];
var self = this;
var handler = {
bind: function(target) {
-
var triggerSingle = function(val,cur) {
- if (cur && {}.toString.call(cur)==='[object Function]') {
+ if (!cur) return;
+ if ({}.toString.call(cur)==='[object Function]') {
cur(val);
- } else if (cur && cur.tagName && cur.nodeName) {
+ } else if (cur.tagName.toUpperCase()==='INPUT' && cur.nodeName) {
+ cur.value = val;
+ } else if (cur.tagName && cur.nodeName) {
cur.innerHTML = val;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.