Debian Codegraph @

README.md

raw symbols SCIP
1 [-> **Documentation for current/stable release: 0.9.2**](http://nytimes.github.com/backbone.stickit/)
2
3 **The following is documentation for the code in master/edge version...**
4
5 ## Introduction
6
7 Backbone's philosophy is for a View, the display of a Model's state, to re-render after any changes have been made to the Model. This works beautifully for simple apps, but rich apps often need to render, respond, and synchronize changes with finer granularity.
8
9 Stickit is a Backbone data binding plugin that binds Model attributes to View elements with a myriad of options for fine-tuning a rich app experience. Unlike most model binding plugins, Stickit does not require any extra markup in your html; in fact, Stickit will clean up your templates, as you will need to interpolate fewer variables (if any at all) while rendering. In Backbone style, Stickit has a simple and flexible api which plugs in nicely to a View's lifecycle.
10
11 ## Download + Source
12
13 [download v0.9.2](http://nytimes.github.com/backbone.stickit/downloads/backbone.stickit_0.9.2.zip)
14
15 [download master/edge](https://raw.github.com/NYTimes/backbone.stickit/master/backbone.stickit.js)
16
17 [view annotated source](http://nytimes.github.com/backbone.stickit/docs/annotated/)
18
19 ## Usage
20
21 Similar to `view.events`, you can define `view.bindings` to map selectors to binding configurations. The following bindings configuration will bind the `view.$('#title')` element to the `title` model attribute and the `view.$('#author')` element to the `authorName` model attribute:
22
23 ```javascript
24 bindings: {
25 '#title': 'title',
26 '#author': 'authorName'
27 }
28 ```
29
30 When the view's html is rendered, usually the last call will be to stickit. By convention, and in the following example, stickit will use `view.model` and the `view.bindings` configuration to initialize:
31
32 ```javascript
33 render: function() {
34 this.$el.html('<div id="title"/> <input id="author" type="text">');
35 this.stickit();
36 }
37 ```
38
39 On the initial call, stickit will initialize the innerHTML of `view.$('#title')` with the value of the `title` model attribute, and will setup a one-way binding (model->view) so that any time a model `change:title` event is triggered, the `view.$('#title')` element will reflect those changes. For form elements, like `view.$('#author')`, stickit will configure a two-way binding (model<->view), connecting and reflecting changes in the view elements with changes in bound model attributes.
40
41 ## API
42
43 ### stickit
44 `view.stickit(optionalModel, optionalBindingsConfig)`
45
46 Uses `view.bindings` and `view.model` to setup bindings. Optionally, you can pass in a model and bindings hash. Note, it is safe to re-render or call stickit multiple times, as stickit will match any previously bound selectors and their associated models and unbind them before reinitializing.
47
48 ```javascript
49 render: function() {
50 this.$el.html(/* ... */);
51 // Initialize stickit with view.bindings and view.model
52 this.stickit();
53 // In addition to, or instead, call stickit with a different model and bindings configuration.
54 this.stickit(this.otherModel, this.otherBindings);
55 }
56 ```
57
58 ### addBinding
59 `view.addBinding(optionalModel, selector, configuration)`
60
61 Adds a single binding to the view, using the given model, or `view.model`, and the given `selector` and `configuration`. It's also possible to pass in a bindings hash as the second parameter. If you use a selector that was already used for a binding, then the old binding will be destroyed before initializing the new binding.
62
63 ```javascript
64 // Short-form selector.
65 this.addBinding(null, '#author', 'author');
66 // With configuration.
67 this.addBinding(null, '#author', {observe:'author', onGet: function() {/* ... */}});
68 // Or, with a bindings hash.
69 this.addBinding(null, {
70 '#author': {
71 observe: 'author',
72 onGet: function() {/* ... */}
73 });
74 ```
75
76 ### unstickit
77 `view.unstickit(optionalModel, optionalSelector)`
78
79 Removes event bindings from all models. Optionally, a model can be passed in which will remove events for the given model and its corresponding bindings configuration only. Another option is to pass in a binding selector or bindings hash to granularly remove any bindings that are associated with `this.model` or the given model. Note, Stickit is setup to automatically unbind all bindings associated with a view on `view.remove()`.
80
81 For each model that is unbound, a `stickit:unstuck` event will be triggered, and for each binding that is unbound the `destroy` callback will be executed.
82
83 ## Bindings
84
85 The `view.bindings` is a hash of jQuery or Zepto selector keys with binding configuration values. Similar to the callback definitions configured in `view.events`, bindings callbacks can be defined as the name of a method on the view or a direct function body. `view.bindings` may also be defined as a function.
86
87 Once you are familiarized with the bindings callbacks, use [this reference](#binding-callbacks-flowchart) for a better idea of when they are called.
88
89 ### observe
90
91 A string, function, or array which is used to map a model attribute to a view element. If binding to `observe` is the only configuration needed, then it can be written in short form where the attribute name is the value of the whole binding configuration.
92
93 Notes on binding to an array of attributes: when binding from model->view, this configuration should be paired with an `onGet` callback that can unpack/format the values. When binding from view->model, then `onSet` or `getVal` should be defined and should return an array of values that stickit will set into the model.
94
95 ```javascript
96 bindings: {
97 // Short form binding
98 '#author': 'author',
99
100 // Normal binding
101 '#title': {
102 observe: 'title'
103 },
104
105 // Bind to multiple model attributes
106 '#header': {
107 observe: ['title', 'author'],
108 onGet: function(values) {
109 // onGet called after title *or* author model attributes change.
110 return values[0] + '-' + values[1];
111 },
112 onSet: function(value) {
113 return value.split('-');
114 }
115 }
116 }
117
118 // Defined bindings as a function.
119 bindings: function() {
120 return {
121 '#title': {
122 observe: 'title'
123 }
124 };
125 }
126 ```
127
128 ### :el (selector)
129
130 A special selector value that binds to the view delegate (view.$el).
131
132 ```javascript
133 tagName: 'form',
134 bindings: {
135 ':el': {
136 observe: 'title'
137 onGet: function(value) { /* ... */ }
138 }
139 }
140 ```
141
142 ### onGet
143
144 A callback which returns a formatted version of the model attribute value that is passed in before setting it in the bound view element.
145
146 ```javascript
147 bindings: {
148 '#header': {
149 observe: 'headerName',
150 onGet: 'formatHeader'
151 }
152 },
153 formatHeader: function(value, options) {
154 return options.observe + ': ' + value;
155 }
156 ```
157
158 ### onSet
159
160 A callback which prepares a formatted version of the view value before setting it in the model.
161
162 ```javascript
163 bindings: {
164 '#author': {
165 observe: 'author',
166 onSet: 'addByline'
167 }
168 },
169 addByline: function(val, options) {
170 return 'by ' + val;
171 }
172 ```
173
174 ### getVal
175
176 A callback which overrides stickit's default handling for retrieving the value from the bound view element. Use `onSet` to format values - this is better used in [handlers](#custom-handlers) or when extra/different dom operations need to be handled.
177
178 ```javascript
179 bindings: {
180 '#author': {
181 observe: 'author',
182 getVal: function($el, event, options) { return $el.val(); }
183 }
184 }
185 ```
186
187 ### update
188
189 A callback which overrides stickit's default handling for updating the value of a bound view element. Use `onGet` to format model values - this is better used in [handlers](#custom-handlers) or when extra/different dom operations need to be handled .
190
191 ```javascript
192 bindings: {
193 '#author': {
194 observe: 'author',
195 update: function($el, val, model, options) { $el.val(val); }
196 }
197 }
198 ```
199
200 ### updateModel
201
202 A boolean value or a function that returns a boolean value which controls whether or not the model gets changes/updates from the view (model<-view). This is only relevant to form elements, as they have two-way bindings with changes that can be reflected into the model. Defaults to true.
203
204 ```javascript
205 bindings: {
206 '#title': {
207 observe: 'title',
208 updateModel: 'confirmFormat'
209 }
210 },
211 confirmFormat: function(val, event, options) {
212 // Only update the title attribute if the value starts with "by".
213 return val.startsWith('by ');
214 }
215 ```
216
217 ### updateView
218
219 A boolean value or a function that returns a boolean value which controls whether or not the bound view element gets changes/updates from the model (view<-model). Defaults to true.
220
221 ```javascript
222 bindings: {
223 '#title': {
224 observe: 'title',
225 // Any changes to the model will not be reflected to the view.
226 updateView: false
227 }
228 }
229 ```
230
231 ### afterUpdate
232
233 Called after a value is updated in the dom.
234
235 ```javascript
236 bindings: {
237 '#warning': {
238 observe: 'warningMessage',
239 afterUpdate: 'highlight'
240 }
241 },
242 highlight: function($el, val, options) {
243 $el.fadeOut(500, function() { $(this).fadeIn(500); });
244 }
245 ```
246
247 ### updateMethod
248
249 Method used to update the inner value of the view element. Defaults to 'text', but 'html' may also be used to update the dom element's innerHTML.
250
251 ```javascript
252 bindings: {
253 '#header': {
254 observe: 'headerName',
255 updateMethod: 'html',
256 onGet: function(val) { return '<div id="headerVal">' + val + '</div>'; }
257 }
258 }
259 ```
260
261 ### escape
262
263 A boolean which when true escapes the model before setting it in the view - internally, gets the attribute value by calling `model.escape('attribute')`. This is only useful when `updateMethod` is "html".
264
265 ```javascript
266 bindings: {
267 '#header': {
268 observe: 'headerName',
269 updateMethod: 'html',
270 escape: true
271 }
272 }
273 ```
274
275 ### initialize
276
277 Called for each binding after it is configured in the initial call to `stickit()`. Useful for setting up third-party plugins, see the handlers section for examples.
278
279 ```javascript
280 bindings: {
281 '#album': {
282 observe: 'exai',
283 initialize: function($el, model, options) {
284 // Setup a Chosen or thirdy-party plugin for this bound element.
285 }
286 }
287 }
288 ```
289
290 ### destroy
291
292 Called for each binding after it is unstuck from the model and view. Useful for tearing down third-party plugins or events that were configured in `initialze`.
293
294 ```javascript
295 bindings: {
296 '#album': {
297 observe: 'Tomorrow\'s Harvest',
298 destroy: function($el, model, options) {
299 // Tear down any events or clean up.
300 }
301 }
302 }
303 ```
304
305 ### visible and visibleFn
306
307 When true, `visible` shows or hides the view element based on the model attribute's truthiness. `visible` may also be defined with a callback which should return a truthy value.
308 The `updateView` option defaults to `false` when using `visible`. You must opt-in to `updateView` in order to have both view element visibility and value changes bound to the observed attribute.
309
310 If more than the standard jQuery show/hide is required, then you can manually take control by defining `visibleFn` with a callback.
311
312 ```javascript
313 bindings: {
314 '#author': {
315 observe: 'isDeleuze',
316 visible: true
317 }
318 }
319 ```
320
321 ```javascript
322 bindings: {
323 '#title': {
324 observe: 'title',
325 visible: function(val, options) { return val == 'Mille Plateaux'; },
326 updateView: true
327 }
328 }
329 ```
330
331 ```javascript
332 bindings: {
333 '#body': {
334 observe: 'isWithoutOrgans',
335 visible: true,
336 visibleFn: 'slideFast'
337 }
338 },
339 slideFast: function($el, isVisible, options) {
340 if (isVisible) $el.slideDown('fast');
341 else $el.slideUp('fast');
342 }
343 ```
344
345 ## Form Element Bindings and Contenteditable
346
347 By default, form and contenteditable elements will be configured with two-way bindings, syncing changes in the view elements with model attributes. Optionally, one-way bindings can be configured with `updateView` or `updateModel`. With the `events`, you can specify a different set of events to use for reflecting changes to the model.
348
349 The following is a list of the supported form elements, their binding details, and the default events used for binding:
350
351 - input, textarea, and contenteditable
352 - element value synced with model attribute value
353 - `propertychange`, `input`, `change` events are used for handling
354 - input[type=checkbox]
355 - `checked` property determined by the truthiness of the model attribute or if the checkbox "value" attribute is defined, then its value is used to match against the model. If a binding selector matches multiple checkboxes then it is expected that the observed model attribute will be an array of values to match against the checkbox value attributes.
356 - `change` event is used for handling
357 - input[type=radio]
358 - model attribute value matched to a radio group `value` attribute
359 - `change` event is used for handling
360 - select
361 - (recommended) specify `selectOptions` to have Stickit handle the rendering and option bindings of your select (see `selectOptions`)
362 - if you choose to pre-render your select-options (not recommended) then there are two ways of configuring the bindings:
363 - "data-stickit-bind-val" attributes in the DOM. This allows for binding non-string values from a prerendered &lt;select&gt;, assuming that you are using jQuery or a build of Zepto that includes the "data" module.
364 - "option[value]" attributes in the DOM (used if no data-stickit-bind-val is present)
365 - `change` event is used for handling
366
367 ### events
368
369 Specify a list of events which will override stickit's default events for a form element. Bound events control when the model is updated with changes in the view element.
370
371 ```javascript
372 bindings: {
373 'input#title': {
374 observe: 'title',
375 // Normally, stickit would bind `keyup`, `change`, `cut`, and `paste` events
376 // to an input:text element. The following will override these events and only
377 // update/set the model after the input#title element is blur'ed.
378 events: ['blur']
379 }
380 }
381 ```
382
383 ### selectOptions
384
385 With the given `collection`, creates `<option>`s for the bound `<select>`, and binds their selected values to the observed model attribute. It is recommended to use `selectOptions` instead of pre-rendering select-options since Stickit will render them and can bind Objects, Arrays, and non-String values as data to the `<option>` values. The following are configuration options for binding:
386
387 - `collection`: an object path of a collection relative to `window` or `view`/`this`, or a string function reference which returns a collection of objects. A collection should be an array of objects, a Backbone.Collection or a value/label map.
388 - `labelPath`: the path to the label value for select options within the collection of objects. Default value when undefined is `label`.
389 - `valuePath`: the path to the values for select options within the collection of objects. When an options is selected, the value that is defined for the given option is set in the model. Leave this undefined if the whole object is the value or to use the default `value`.
390 - `defaultOption`: an object or method that returns an object with `label` and `value` keys, used to define a default option value. A common use case would be something like the following: `{label: "Choose one...", value: null}`.
391
392 When bindings are initialized, Stickit will build the `<select>` element with the `<option>`s and bindings configured. `selectOptions` are not required - if left undefined, then Stickit will expect that the `<option>`s are pre-rendered and build the collection from the DOM.
393
394 **Note:** if you are using Zepto and referencing object values for your select options, like in the second example, then you will need to also include the Zepto data module. Also, `<select>` bindings are two-way bindings only - `updateView:false` will be ignored.
395
396 The following example references a collection of stooges at `window.app.stooges` and uses the `age` attribute for labels and the `name` attribute for option values:
397
398 ```javascript
399 window.app.stooges = [{name:'moe', age:40}, {name:'larry', age:50}, {name:'curly', age:60}];
400 ```
401
402 ```javascript
403 bindings: {
404 'select#stooges': {
405 observe: 'stooge',
406 selectOptions: {
407 // Alternatively, `this` can be used to reference anything in the view's scope.
408 // For example: `collection:'this.stooges'` would reference `view.stooges`.
409 collection: 'window.app.stooges',
410 labelPath: 'age',
411 valuePath: 'name'
412 }
413 }
414 ```
415 The following is an example where the default `label` and `value` are used along with a `defaultOption`:
416 ```javascript
417 bindings: {
418 'select#stooges': {
419 observe: 'stooge',
420 selectOptions: {
421 collection: function() {
422 // No need for `labelPath` or `valuePath` since the defaults
423 // `label` and `value` are used in the collection.
424 return [{value:1, label:'OH'}, {value:2, label:{name:'IN'}}];
425 },
426 defaultOption: {
427 label: 'Choose one...',
428 value: null
429 }
430 }
431 }
432 ```
433
434 The following is an example where a collection is returned by callback and the collection objects are used as option values:
435
436 ```javascript
437 bindings: {
438 'select#states': {
439 observe: 'state',
440 selectOptions: {
441 collection: function() {
442 return [{id:1, data:{name:'OH'}}, {id:2, data:{name:'IN'}}];
443 },
444 labelPath: 'data.name'
445 // Leaving `valuePath` undefined so that the collection objects are used
446 // as option values. For example, if the "OH" option was selected, then the
447 // following value would be set into the model: `model.set('state', {id:1, data:{name:'OH'}});`
448 }
449 }
450 ```
451
452 Optgroups are supported, where the collection is formatted into an object with an `opt_labels` key that specifies the opt label names and order.
453
454 ```javascript
455 bindings: {
456 'select#tv-characters': {
457 observe: 'character',
458 selectOptions: {
459 collection: function() {
460 return {
461 'opt_labels': ['Looney Tunes', 'Three Stooges'],
462 'Looney Tunes': [{id: 1, name: 'Bugs Bunny'}, {id: 2, name: 'Donald Duck'}],
463 'Three Stooges': [{id: 3, name: 'moe'}, {id: 4, name: 'larry'}, {id: 5, name: 'curly'}]
464 };
465 },
466 labelPath: 'name',
467 valuePath: 'id'
468 }
469 }
470 }
471 ```
472
473 It is often useful to have a lookup table for converting between underlying values which are actually stored and transmitted and the human-readable labels that represent them. Such a lookup table (an object like `{ value1: label1, value2: label2 }`) can be used to populate a select directly. By default, the options will be sorted alphabetically by label; pass a `comparator`function or property name string to override this ordering (which delegates to `_.sortBy`).
474
475 ```javascript
476 bindings: {
477 'select#sounds': {
478 observe: 'sound',
479 selectOptions: {
480 collection: {
481 moo: 'cow',
482 baa: 'sheep',
483 oink: 'pig'
484 }
485 }
486 }
487 }
488 ```
489
490 Finally, multiselects are supported if the select element contains the [multiple="true"] attribute. By default stickit will expect that the model attribute is an array of values, but if your model has a formatted value, you can use `onGet` and `onSet` to format attribute values (this applies to any select bindings).
491
492 ```javascript
493 //
494 // model.get('books') returns a dash-delimited list of book ids: "1-2-4"
495
496 bindings: {
497 '#books': {
498 observe: 'books',
499 onGet: function(val) {
500 // Return an array of the ids so that stickit can match them to select options.
501 return _.map(val.split('-'), Number);
502 },
503 onSet: function(vals) {
504 // Format the array of ids into a dash-delimited String before setting.
505 return vals.join('-');
506 },
507 selectOptions: {
508 collection: 'app.books',
509 labelPath: 'name',
510 valuePath: 'id'
511 }
512 }
513 }
514 ```
515
516 ### setOptions
517
518 An object which is used as the set options when setting values in the model. This is only used when binding to form elements, as their changes would update the model.
519
520 ```javascript
521 bindings: {
522 'input#name': {
523 observe: 'name',
524 setOptions: {silent:true}
525 }
526 }
527 ```
528
529 ### stickitChange
530
531 A property that is passed into the set options when stickit changes a model attribute. The value of this property is assigned to the binding configuration.
532
533 ```javascript
534 model.on('change:observed', function(m, v, options) {
535 if (options.stickitChange) {
536 ...
537 } else {
538 ...
539 }
540 });
541
542 ```
543
544 ## Attribute and Property Bindings
545
546 ### attributes
547
548 Binds element attributes and properties with observed model attributes, using the following options:
549
550 - `name`: attribute or property name.
551 - `observe`: observes the given model attribute. If left undefined, then the main configuration `observe` is observed.
552 - `onGet`: formats the observed model attribute value before it is set in the matched element.
553
554 ```javascript
555 bindings: {
556 '#header': {
557 attributes: [{
558 name: 'class',
559 observe: 'hasWings',
560 onGet: 'formatWings'
561 }, {
562 name: 'readonly',
563 observe: 'isLocked'
564 }]
565 }
566 },
567 formatWings: function(val) {
568 return val ? 'has-wings' : 'no-wings';
569 }
570 ```
571
572 ## Custom Handlers
573
574 ### addHandler
575 `Backbone.Stickit.addHandler(handler_s)`
576
577 Adds the given handler or array of handlers to Stickit. A handler is a binding configuration, with an additional `selector` key, that is used to customize or override any of Stickit's default binding handling. To derive a binding configuration, the `selector`s are used to match against a bound element, and any matching handlers are mixed/extended in the order that they were added.
578
579 Internally, Stickit uses `addHandler` to add configuration for its default handling. For example, the following is the internal handler that matches against `textarea` elements:
580
581 ```javascript
582 Backbone.Stickit.addHandler({
583 selector: 'textarea',
584 events: ['keyup', 'change', 'paste', 'cut'],
585 update: function($el, val) { $el.val(val); },
586 getVal: function($el) { return $el.val(); }
587 })
588
589 ```
590 Except for the `selector`, those keys should look familiar since they belong to the binding configuration api. If unspecified, the following keys are defaulted for handlers: `updateModel:true`, `updateView:true`, `updateMethod:'text'`.
591
592 By adding your own `selector:'textarea'` handler, you can override any or all of Stickit's default `textarea` handling. Since binding configurations are derived from handlers with matching selectors, another customization trick would be to add a handler that matches textareas with a specific class name. For example:
593
594 ```javascript
595 Backbone.Stickit.addHandler({
596 selector: 'textarea.trim',
597 getVal: function($el) { return $.trim($el.val()); }
598 })
599
600 ```
601 With this handler in place, anytime you bind to a `textarea`, if the `textarea` contains a `trim` class then this handler will be mixed into the default `textarea` handler and `getVal` will be overridden.
602
603 Another good use for handlers is setup code for third-party plugins. At the end of `View.render`, it is common to include boilerplate third-party initialization code. For example the following sets up a [Chosen](http://harvesthq.github.com/chosen/) multiselect,
604
605 ```javascript
606 render: function() {
607 this.$el.html(this.template());
608 this.setupChosenSelect(this.$('.friends'), 'friends');
609 this.setupChosenSelect(this.$('.albums'), 'albums');
610 }
611
612 setupChosenSelect: function($el, modelAttr) { /* initialize Chosen for the el and map to model */ }
613 ```
614
615 Instead, a handler could be setup to match bound elements that have a `chosen` class and initialize a [Chosen](http://harvesthq.github.com/chosen/) multiselect for the element:
616
617 ```javascript
618 // Setup a generic, global handler for the Chosen plugin.
619 Backbone.Stickit.addHandler({
620 selector: 'select.chosen',
621 initialize: function($el, model, options) {
622 $el.chosen();
623 var up = function(m, v, opt) {
624 if (!opt.bindKey) $el.trigger('liszt:updated');
625 };
626 this.listenTo(model, 'change:' + options.observe, up)
627 }
628 });
629 ```
630
631 ```html
632 <!-- A template for the View, marked with the chosen class -->
633 <select class="friends chosen" multiple="multiple"></select>
634 ```
635
636 ```javascript
637 // In a View ...
638 bindings: {
639 '.friends': {
640 observe: 'friends',
641 selectOptions: {
642 collection: 'this.friendsCollection'
643 }
644 }
645 },
646 render: function() {
647 this.$el.html(this.template());
648 this.stickit(); // Chosen is initialized.
649 }
650 ```
651
652 ## Binding Callbacks Flowchart
653
654 The following image demonstrates the order in which bindings callbacks are called after stickit is initialized, a bound model attribute changes, and a bound view element changes.
655
656 ![alt tag](https://raw.github.com/nytimes/backbone.stickit/gh-pages/flow.png)
657
658 ## F.A.Q.
659
660 ### Why Stickit?
661
662 JavaScript frameworks seem to be headed in the wrong direction - controller callbacks/directives, configuration, and special tags are being forced into the template/presentation layer. Who wants to program and debug templates?
663
664 If you are writing a custom frontend, then you're going to need to write custom JavaScript. Backbone helps you organize with a strong focus on the model, but stays the hell out of your presentation. Configuration and callbacks should only be in one place - the View/JavaScript.
665
666 ### Dependencies
667
668 Backbone 1.0, underscore.js, and jQuery or Zepto (with data module; see `selectOptions`)
669
670 ### License
671
672 MIT
673
674 ## Change Log
675
676 #### Master
677
678 #### 0.9.2
679 Bumped allowed underscore and Backbone versions.
680
681 #### 0.9.0
682 - **Breaking Change**: Classes are now treated separately from other attribute bindings. Use the new `classes` hash to bind element classes to your attributes.
683 - `defaultOption` can be defined as a function.
684 - Passing a Backbone Collection to `selectOptions` will keep the select dropdown in sync with add, remove, and sort events on the collection.
685 - `view#stickit` returns `this` for easier chaining.
686 - Non-string values can be bound to a pre-rendered `<select>` dropdown by setting `data-stickit-bind-val` on `<option>` elements.
687
688 #### 0.8.0
689
690 - **Breaking Change**: Calling `view#stickit` a second time with the same model, will no longer unbind all previously bound bindings associated with that model; instead, it will unbind any duplicate bindings (selectors) found in the given bindings hash (or whatever's in `view.bindings`) before initializing.
691 - Added an `view#addBinding` which will initiate a single, or hash, of bindings.
692 - `view#unstickit` now takes a second, optional, parameter which gives you the control to granularly remove a single, or hash, of bindings.
693
694 #### 0.7.0
695
696 - **Breaking Change**: the `bindKey` that was passed into the Backbone `change:attr` (undocumented) options was changed to `stickitChange` which is assigned the binding options which have a unique `bindId`.
697 - **Breaking Change**: the default events for input, textarea, and contenteditable form elements changed from [`keyup`, `cut`, `paste`, `change`] to [`propertychange`, `input`, `change`].
698 - **Breaking Change**: removed support for `input[type="number"]`. Instead, use `onSet` to format Number values, if needed.
699 - **Breaking Change**: The `updateModel` method parameters changed so the `event` is now passed as the second parameter. `updateModel(val, options)` -> `updateModel(val, event, options)`
700 - Stickit will now load using the UMD pattern so it is compatible with AMD, Node.js, and CommonJS.
701 - A view's `bindings` configuration can be defined as a function.
702 - When observing an array, if `onSet` or `getVal` return an array of values, Stickit will match the values to their respective attributes defined in `observe` and set them in the model. If you don't desire this change, then you can override this behavior with the following change:
703 - Added a `set` callback which by default calls `model#set`
704 - Added the `destroy` binding callback to compliment `initialize`.
705 - Trigger `stickit:unstick` for each model that is unbound in `unstickit` (or `view.remove`).
706 - Added handling for `observe` in function form.
707 - When binding with `visible` the `{updateView:false}` property is defaulted.
708 - Stickit will no longer sanitize (convert a `null`/`undefined` model attribute value to empty string) values if `onGet` is defined.
709 - Added support for the use of dot-notation in binding callbacks that are defined with a string that names a method on the view. For example - `onGet: "myObj.myCallback"`.
710 - Added Backbone.Stickit.getConfiguration which exposes the method of deriving configurations from handlers.
711 - Fixed a bug where "null" would show in Chrome when binding `attribute:null` to an element value.
712 - Fixed a bug where optgroup `<select>` handlers were rendering multiple `collection.defaultOptions`.
713
714 #### 0.6.3
715
716 - Added `Backbone.Stickit.addHandler()`, useful for defining a custom configuration for any bindings that match the `handler.selector`.
717 - **Breaking Change**: `eventsOverride` was changed to `events`.
718 - **Breaking Change**: removed the third param (original value) from the `afterUpdate` parameters.
719 - **Breaking Change**: replaced `unstickModel` with `unstickit`.
720 - **Breaking Change**: removed deprecated `modelAttr` from bindings api.
721 - **Breaking Change**: removed deprecated `format` from bindings api.
722 - **Breaking Change**: removed support for null value default/empty options in selectOptions.collection.
723 - Added `defaultOption` to the `selectOptions`.
724 - Added `initialize` to the bindings api which is called for each binding after it is initialized.
725 - Fixed a bug introduced in 0.6.2 where re-rendering/re-sticking wasn't unbinding view events [#66](https://github.com/NYTimes/backbone.stickit/issues/66).
726 - Added `update` to the bindings api which is an override for handling how the View element gets updated with Model changes.
727 - Added `getVal` to the bindings api which is an override for retrieving the value of the View element.
728 - Added support for passing in Backbone.Collection's into `selectOptions.collection`.
729 - Added support for referencing the view's scope with a String `selectOptions.collection` reference. For example: `collection:'this.viewCollection'`.
730
731 #### 0.6.2
732
733 - **Breaking Change**: Changed the last parameter from the model attribute name to the bindings hash in most of the binding callbacks. Note the model attribute name can still be gleaned from the bindings hash - `options.observe`. The following are the callbacks that were affected and their parameters (`options` are the bindings hash):
734 `onGet(value, options)`
735 `onSet(value, options)`
736 `updateModel(value, options)`
737 `updateView(value, options)`
738 `afterUpdate($el, value, originalVal, options)`
739 `visible(value, options)`
740 `visibleFn($el, isVisible, options)`
741 - Added support for handling multiple checkboxes with one binding/selector and using the `value` attribute, if present, for checkboxes.
742 - Added default values for `labelPath` and `valuePath` in selectOptions: `label` and `value` respectively.
743 - Refactored event registration to use `$.on` and `$.off` instead of delegating through Backbone which fixed the following bugs:
744 - `view.events` selectors and binding selectors that are equal were overriding [#49](https://github.com/NYTimes/backbone.stickit/issues/49)
745 - `view.events` declared as a function was not supported [#51](https://github.com/NYTimes/backbone.stickit/pull/51)
746 - Fixed some bugs and added support requirements for zepto.js; [#58](https://github.com/NYTimes/backbone.stickit/pull/58).
747 - Bug Fixes: [#38](https://github.com/NYTimes/backbone.stickit/pull/38), [#42](https://github.com/NYTimes/backbone.stickit/pull/42),
748
749 #### 0.6.1
750
751 - Added `observe` in place of `modelAttr` (**deprecated** `modelAttr` but maintained for backward-compatibility).
752 - Added `onGet` in place of `format` (**deprecated** `format` but maintained for backward-compatibility).
753 - Added `onSet` binding for formatting values before setting into the model.
754 - Added `updateModel`, a boolean to control changes being reflected from view to model.
755 - Added `updateView`, a boolean to control changes being reflected from model to view.
756 - Added `eventsOverride` which can be used to specify events for form elements that update the model.
757 - **Breaking Change**: Removed manual event configuration/handling (no `keyup`, `submit`, etc, in binding configurations).
758 - Added support for multiselect select elements.
759 - Added support for optgroups within a select element.
760 - Bug Fixes: [#29](https://github.com/NYTimes/backbone.stickit/pull/29), [#31](https://github.com/NYTimes/backbone.stickit/pull/31)
761
762 #### 0.6.0
763
764 - **Breaking Change**: Removed `readonly` configurtion option.
765 - Element properties (like `readonly`, `disabled`, etc.) can be configured in `attributes`.
766 - Added custom event handling to the api - see events section in docs.
767 - Added support for binding multiple model attributes in `modelAttr` configuration.
768 - Added the `visible` and `visibleFn` binding configurations.
769 - Added support for `:el` selector for selecting the view delegate.
770 - Bug Fixes: [#10](https://github.com/NYTimes/backbone.stickit/issues/1), [#11](https://github.com/NYTimes/backbone.stickit/issues/1), [#16](https://github.com/NYTimes/backbone.stickit/issues/16)
771
772 #### 0.5.2
773
774 - Fix IE7/8 select options bug ([issue #9](https://github.com/NYTimes/backbone.stickit/pull/9))
775
776 #### 0.5.1
777
778 - Shorthand binding for model attributes: `'#selector':attrName`.
779 - Added support for input[type=number] where values will be bound to model attributes as the Number type.
780 - Attribute name is passed in as the second parameter of `format` callbacks.
781 - Bug fixes: issue [#1](https://github.com/NYTimes/backbone.stickit/issues/1), [#2](https://github.com/NYTimes/backbone.stickit/issues/2), [#4](https://github.com/NYTimes/backbone.stickit/issues/4), [#6](https://github.com/NYTimes/backbone.stickit/issues/6), [#8](https://github.com/NYTimes/backbone.stickit/issues/8)
782
783 #### 0.5.0
784
785 - Initial release (extracted and cleaned up from the backend of cn.nytimes.com).