// These functions all do *one* simple thing.
// That way we can _.compose them later in different fun ways
function getElementFromEvent (event) {
return event.currentTarget;
}
function getElementValue (elem) {
return elem.value;
}
function setElementValue (elem, value) {
return elem.value = value;
}
function setModelValue (model, value) {
return elem.value = value;
}
function valueToInt (value) {
return parseInt(value, 10);
}
function clampToMinMax (min, max, value) {
return Math.max(min, Math.min(value, max));
}
function returnValue (value) { return value; }
// Simple functions that return a value, used in the clamping function
var negInfinity = _.partial(returnValue, -Infinity);
var infinity = _.partial(returnValue, Infinity);
// Create functions that simply get the value of a specific element as an int
//var getValue = _.compose(valueToInt, getElementValue);
// Create function that gets a value from an event as a int
var getIntFromEvent = _.compose(valueToInt, getElementValue, getElementFromEvent);
var HighlightModel = Backbone.Model.extend({
defaults: {
min: 0,
max: 20,
start: 3,
end: 6
}
});
var HighlightView = Backbone.View.extend({
tagName: "div",
className : "highlighter",
initialize: function () {
this.template = _.template( $("#highlight_template").html(), {} );
this.render = _.bind(this.render, this);
this.render();
},
events: {
"change input.min": "minEventHandler",
"change input.max": "maxEventHandler",
"change input.hiliteMin": "highlightMinEventHandler",
"change input.hiliteMax": "highlightMaxEventHandler"
},
render: function () {
this.$el.empty();
var modelObj = this.model.toJSON();
modelObj.range = _.range(modelObj.min, modelObj.max + 1);
this.$el.html(this.template(modelObj));
},
minEventHandler: function (event) {
var min = 0;
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.