Debian Codegraph @

test/addHandler.js

raw symbols SCIP
1 $(document).ready(function() {
2
3 module("Backbone.Stickit");
4
5 test('addHandler', function() {
6
7 Backbone.Stickit.addHandler({
8 selector: 'input.trim',
9 update: function($el, val) { $el.val($.trim(val)); }
10 });
11
12 equal(_.last(Backbone.Stickit._handlers).selector, 'input.trim');
13
14 Backbone.Stickit.addHandler([{
15 selector: 'textarea',
16 update: function($el, val) { $el.val('blood ' + val); }
17 }, {
18 selector: 'div',
19 updateMethod: 'html'
20 }]);
21
22 equal(_.last(Backbone.Stickit._handlers).selector, 'div');
23 equal(_.last(Backbone.Stickit._handlers, 2)[0].selector, 'textarea');
24
25 model.set({'input':' clot ', 'textarea':'clot', 'div':'<em>clot</em>'});
26 view.model = model;
27 view.templateId = 'jst20';
28 view.bindings = {
29 '.input': 'input',
30 'input.trim': 'input',
31 '#textarea': 'textarea',
32 '#div': 'div'
33 };
34 $('#qunit-fixture').html(view.render().el);
35
36 equal(view.$('.input').val(), ' clot ');
37 equal(view.$('input.trim').val(), 'clot');
38 equal(view.$('#textarea').val(), 'blood clot');
39 equal(view.$('#div').text(), 'clot');
40
41 Backbone.Stickit._handlers = _.first(Backbone.Stickit._handlers, Backbone.Stickit._handlers.length - 3);
42 });
43
44 test('public getConfiguration', function(){
45 $('#qunit-fixture').html($('#jst25').html());
46 var $el = $('#qunit-fixture').find('.test25');
47 equal(Backbone.Stickit.getConfiguration($el).getVal($el), 'two');
48 });
49 });