Created
October 20, 2014 22:27
-
-
Save jb55/4ab65579e9fdfe92bc68 to your computer and use it in GitHub Desktop.
Extensible view in bquery
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
Ratio = require('ratio') | |
EditableRatioPlugin = (v) -> | |
v.defaults 'editable-ratio', | |
rawTemplate: require('./template') | |
noModel: true | |
v.set "setFrac", (n, d) -> | |
r = if n instanceof Ratio then n else Ratio(n,d) | |
@model.set("value", r) | |
v.on("click .frac-one-half", -> @setFrac(1,2)) | |
v.on("click .frac-one-third", -> @setFrac(1,3)) | |
v.on("click .frac-one-sixth", -> @setFrac(1,6)) | |
v.on("click .frac-two-thirds", -> @setFrac(2,3)) | |
v.boundVal "value", ".ratio", | |
toView: (v) -> v.toString() | |
fromView: (v) -> Ratio(v) | |
EditableRatio = module.exports = bQuery.view().use(EditableRatioPlugin).make() | |
module.exports.EditableRatioPlugin = EditableRatioPlugin | |
## Extended view | |
EditableUserRatioPlugin = (v) -> | |
v.use EditableRatioPlugin | |
v.init -> | |
@on 'render', => | |
@$('.js-buttons').append("<button class='btn btn-small rest'>rest</button>") | |
v.on("click .rest", -> @trigger 'rest') | |
EditableUserRatio = bQuery.view().use(EditableUserRatioPlugin).make() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment