Created
April 22, 2013 15:09
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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