Skip to content

Instantly share code, notes, and snippets.

@sixFingers
Created April 22, 2013 15:09
Show Gist options
  • Save sixFingers/5435795 to your computer and use it in GitHub Desktop.
Save sixFingers/5435795 to your computer and use it in GitHub Desktop.
Make rivets.js publish data to model when elements with "data-text" attribute get blur.
rivets.binders.text = (function() {
var handler = function(e) {
return rivets.config.adapter.publish(e.data.model, e.data.keypath, $(e.currentTarget).text());
}
var binding = {
publishes: true,
bind: function(el) {
return $(el).on("blur", null, this, handler);
},
unbind: function(el) {
return $(el).off("blur", null, this, handler);
},
routine: function(el, value) {
if (el.innerText != null) {
return el.innerText = value != null ? value : "";
} else {
return el.textContent = value != null ? value : "";
}
}
}
return binding;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment