Skip to content

Commit 533405c

Browse files
committed
added a new event and made the eventbus return the player instance
1 parent f85beb2 commit 533405c

File tree

7 files changed

+39
-4
lines changed

7 files changed

+39
-4
lines changed

dist/afterglow.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/afterglow.zip

28 Bytes
Binary file not shown.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "afterglowplayer",
33
"description": "An easy to integrate HTML5 video player with lightbox support.",
4-
"version": "1.0.4",
4+
"version": "1.1.0",
55
"license": "MIT",
66
"repository": {
77
"type": "git",

src/js/afterglow/components/Eventbus.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Eventbus{
5858
return false;
5959
}
6060
for (var i = 0; i < this.players[playerid].listeners[event].length; i++) {
61-
this.players[playerid].listeners[event][i]({type: event, player: playerid});
61+
this.players[playerid].listeners[event][i]({type: event, playerid: playerid, player: window.afterglow.getPlayer(playerid)});
6262
}
6363
}
6464
}

src/js/afterglow/components/Lightbox.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ class Lightbox extends DOMElement{
239239
* @return void
240240
*/
241241
close(){
242+
window.afterglow.eventbus.dispatch(this.player.id, 'before-lightbox-close');
242243
this.player.destroy(true);
243244
this.node.parentNode.removeChild(this.node);
244245
this.emit('close');

test/test.2.lightbox.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Player from '../src/js/afterglow/components/Player';
22
import Lightbox from '../src/js/afterglow/components/Lightbox';
33
import Emitter from '../vendor/Emitter/Emitter';
4+
import Eventbus from '../src/js/afterglow/components/Eventbus';
45
import DOMElement from '../src/js/afterglow/lib/DOMElement';
56
import Util from '../src/js/afterglow/lib/Util';
67

@@ -246,9 +247,15 @@ describe("Afterglow Lightbox", () => {
246247

247248
describe('close()', () => {
248249
beforeEach(() => {
250+
251+
sinon.stub(Eventbus.prototype, 'dispatch');
249252
sinon.stub(Lightbox.prototype, 'build');
250253
sinon.stub(Lightbox.prototype, 'bindEmitter');
251254
sinon.stub(DOMElement.prototype, 'addClass');
255+
256+
window.afterglow = {};
257+
window.afterglow.eventbus = new Eventbus();
258+
252259
lightbox = new Lightbox();
253260
lightbox.player = {
254261
destroy : () => {}
@@ -269,6 +276,7 @@ describe("Afterglow Lightbox", () => {
269276
Lightbox.prototype.bindEmitter.restore();
270277
DOMElement.prototype.addClass.restore();
271278
Lightbox.prototype.build.restore();
279+
Eventbus.prototype.dispatch.restore();
272280
});
273281

274282
it('should properly trigger the destroy method on the player', () => {
@@ -283,6 +291,7 @@ describe("Afterglow Lightbox", () => {
283291

284292
it('should emit the closing event', () => {
285293
lightbox.close();
294+
assert(Eventbus.prototype.dispatch.calledOnce);
286295
expect(lightbox.emit).to.have.been.calledOnce;
287296
expect(lightbox.emit).to.have.been.calledWith('close');
288297
});

test/test.3.eventbus.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Eventbus from '../src/js/afterglow/components/Eventbus';
33
var chai = require('chai');
44
var sinon = require("sinon");
55
var sinonChai = require("sinon-chai");
6+
var jsdom = require('mocha-jsdom');
67

78
chai.use(sinonChai);
89
chai.should();
@@ -41,7 +42,14 @@ describe("Eventbus", () => {
4142

4243

4344
describe('dispatch()', () => {
45+
// Initiate the DOM
46+
jsdom();
47+
4448
it('should dispatch events',() => {
49+
window.afterglow = {
50+
getPlayer: sinon.spy()
51+
}
52+
4553
eventbus.players = {
4654
playerid : {
4755
listeners : {
@@ -62,6 +70,23 @@ describe("Eventbus", () => {
6270
eventbus.dispatch('playerid','event1');
6371
sinon.assert.calledThrice(testCallback);
6472
});
73+
74+
it('should pass the player instance', () => {
75+
window.afterglow = {
76+
getPlayer: sinon.stub().returns({id:42})
77+
}
78+
79+
eventbus.players = {
80+
playerid : {
81+
listeners : {
82+
'event1': [testCallback]
83+
}
84+
}
85+
};
86+
eventbus.dispatch('playerid','event1');
87+
assert(window.afterglow.getPlayer.called);
88+
assert(testCallback.calledWith({type:'event1', player: {id:42}, playerid: 'playerid'}));
89+
});
6590
});
6691

6792
});

0 commit comments

Comments
 (0)