Skip to content

Commit 5056918

Browse files
committed
Merge branch 'master' of github.com:ampersandjs/ampersand-view into renaming-get
2 parents f54de7f + bd28228 commit 5056918

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

ampersand-view.js

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ function View(attrs) {
1717
this.on('change:el', this._handleElementChange, this);
1818
this._parsedBindings = bindings(this.bindings);
1919
this._initializeBindings();
20+
if (attrs.el && !this.autoRender) {
21+
this._handleElementChange();
22+
}
2023
this._initializeSubviews();
2124
this.initialize.apply(this, arguments);
2225
this.set(_.pick(attrs, viewOptions));

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ampersand-view",
33
"description": "A smart base view for Backbone apps, to make it easy to bind collections and properties to the DOM.",
4-
"version": "6.0.9",
4+
"version": "6.0.11",
55
"author": "Henrik Joreteg <henrik@andyet.net>",
66
"browser": "./ampersand-view.js",
77
"bugs": "https://github.com/ampersandjs/ampersand-view/issues",
@@ -14,7 +14,7 @@
1414
"events-mixin": "^1.1.0",
1515
"get-object-path": "^0.0.2",
1616
"matches-selector": "^1.0.0",
17-
"underscore": "^1.6.0"
17+
"underscore": "1.6.0"
1818
},
1919
"devDependencies": {
2020
"ampersand-model": "~2.10.6",

test/main.js

+20
Original file line numberDiff line numberDiff line change
@@ -622,3 +622,23 @@ test('make sure template can return a dom node', function (t) {
622622

623623
t.end();
624624
});
625+
626+
test('events are bound if there is an el in the constructor', function (t) {
627+
t.plan(1);
628+
var event = document.createEvent("MouseEvent");
629+
var View = AmpersandView.extend({
630+
template: function () {
631+
return document.createElement('div');
632+
},
633+
events: {
634+
'click div': 'divClicked'
635+
},
636+
divClicked: function (e) {
637+
t.ok(true, 'event fired');
638+
t.end();
639+
}
640+
});
641+
var view = new View({el: document.createElement('div')});
642+
event.initMouseEvent('click');
643+
view.el.dispatchEvent(event);
644+
});

0 commit comments

Comments
 (0)