Use H5P.EventDispatcher to trigger and handle events
parent
4246857bf7
commit
019ee64e17
|
@ -1,6 +1,6 @@
|
||||||
/*jshint -W083 */
|
/*jshint -W083 */
|
||||||
|
|
||||||
(function ($, Version) {
|
(function ($, Version, EventDispatcher) {
|
||||||
var info, $container, librariesCache = {}, scriptsCache = {};
|
var info, $container, librariesCache = {}, scriptsCache = {};
|
||||||
|
|
||||||
// Initialize
|
// Initialize
|
||||||
|
@ -70,6 +70,15 @@
|
||||||
* @returns {_L1.ContentUpgrade}
|
* @returns {_L1.ContentUpgrade}
|
||||||
*/
|
*/
|
||||||
function ContentUpgrade(libraryId, events) {
|
function ContentUpgrade(libraryId, events) {
|
||||||
|
if( typeof EventDispatcher !== 'undefined'){
|
||||||
|
EventDispatcher.call(this);
|
||||||
|
if( typeof events !== 'undefined'){
|
||||||
|
for (var i in events){
|
||||||
|
this.on(i, events[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// Get selected version
|
// Get selected version
|
||||||
|
@ -85,8 +94,6 @@
|
||||||
// Track number of working
|
// Track number of working
|
||||||
self.working = 0;
|
self.working = 0;
|
||||||
|
|
||||||
self.events = events || {};
|
|
||||||
|
|
||||||
var start = function () {
|
var start = function () {
|
||||||
self.trigger('start');
|
self.trigger('start');
|
||||||
|
|
||||||
|
@ -448,15 +455,10 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trigger
|
* Trigger
|
||||||
* @param action
|
* Fallback function in case EventDispatcher is undefined
|
||||||
* @param data
|
|
||||||
*/
|
*/
|
||||||
ContentUpgrade.prototype.trigger = function (action, data) {
|
ContentUpgrade.prototype.trigger = function () {};
|
||||||
if( typeof this.events[action] !== "undefined"){
|
|
||||||
this.events[action].call(this, data);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
H5P.ContentUpgrade = ContentUpgrade;
|
H5P.ContentUpgrade = ContentUpgrade;
|
||||||
|
|
||||||
})(H5P.jQuery, H5P.Version);
|
})(H5P.jQuery, H5P.Version, H5P.EventDispatcher);
|
||||||
|
|
Loading…
Reference in New Issue