Permalink
Browse files

Merge pull request #322 from noobiek/master

fix - loss of context
  • Loading branch information...
akre54 committed May 7, 2018
2 parents f1bb0e1 + 73f6aeb commit faad0f28bcbe2ae4193de67ebae881be563523fd
Showing with 44 additions and 1 deletion.
  1. +1 −1 backbone.stickit.js
  2. +39 −0 test/bindData.js
  3. +4 −0 test/setup/dom-setup.js
View
@@ -358,10 +358,10 @@
var initializeClasses = function($el, config, model, modelAttr) {
_.each(config.classes || [], function(classConfig, name) {
if (_.isString(classConfig)) classConfig = {observe: classConfig};
classConfig.view = config.view;
var observed = classConfig.observe;
var updateClass = function() {
classConfig.view = config.view;
var val = getAttr(model, observed, classConfig);
$el.toggleClass(name, !!val);
};
View
@@ -2105,4 +2105,43 @@ $(document).ready(function() {
assert.equal(view._modelBindings.length, 0);
});
QUnit.test('context loss in getAttr', function(assert) {
var model1 = new Backbone.Model();
var model2 = new Backbone.Model();
var View = Backbone.View.extend({
templateId: 'jst29',
bindings: {
'#test29': {
classes: {
'hasCid': {
observe: 'cid',
onGet: function(cid) {
console.log(cid)
if (cid) assert.equal(cid, this.cid);
return true;
}
}
}
}
},
render: function() {
var html = document.getElementById(this.templateId).innerHTML;
this.$el.html(_.template(html)());
this.stickit();
return this;
}
});
var view1 = new View({ model: model1 });
var view2 = new View({ model: model2 });
$('#qunit-fixture').html(view1.render().el);
$('#qunit-fixture').append(view2.render().el);
model1.set({'cid':view1.cid});
model2.set({'cid':view2.cid});
});
});
View
@@ -167,5 +167,9 @@ $('body').append(
'<script id="jst28" type="text/jst">' +
' <input type="checkbox" class="box" value="1">' +
'</script>' +
'<script id="jst29" type="text/jst">' +
' <div id="test29"></div>' +
'</script>'
);

0 comments on commit faad0f2

Please sign in to comment.