Skip to content

Commit

Permalink
Call Behavior#init function before any event binding
Browse files Browse the repository at this point in the history
This allows to define new elements and contents for the behavior element
on initialization
  • Loading branch information
roperzh committed Sep 12, 2014
1 parent 2eb004f commit d68f19d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ Essential.Behavior = Proto.extend({
},

start: function() {
this.delegateEvents();
this.listenChannels();

if(typeof this.init === "function") {
this.init();
}

this.delegateEvents();
this.listenChannels();
},

// Delegate Events
Expand Down
14 changes: 14 additions & 0 deletions test/behavior_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ describe("Essential.Behavior", function() {
expect(behavior).to.be.ok;
});
});

it("executes the init function before any bindings", function() {
var Behavior = customBehavior.extend({
init: function() {
this.el.innerHTML = "<li id='created-on-init'></li>";
}
});

var instanceBehavior = Behavior.new(this.domElement);
var clickTester = document.getElementById("created-on-init");
clickTester.dispatchEvent(Events.click());

expect(Helper.flag).to.not.equal(0);
});
});

it("has a default priority equal to zero", function() {
Expand Down

0 comments on commit d68f19d

Please sign in to comment.