Add documentation and change function names for deprecated functions

namespaces
Svein-Tore Griff With 2015-02-04 18:43:06 +01:00
parent fc4f791e6e
commit c8a2465827
1 changed files with 49 additions and 22 deletions

View File

@ -118,7 +118,7 @@ H5P.init = function () {
};
var resizeDelay;
H5P.deprecatedOn(instance, 'resize', function () {
H5P.on(instance, 'resize', function () {
// Use a delay to make sure iframe is resized to the correct size.
clearTimeout(resizeDelay);
resizeDelay = setTimeout(function () {
@ -128,22 +128,22 @@ H5P.init = function () {
H5P.instances.push(instance);
}
H5P.deprecatedOn(instance, 'xAPI', H5P.xAPIListener);
H5P.deprecatedOn(instance, 'xAPI', H5P.xAPIEmitter);
H5P.on(instance, 'xAPI', H5P.xAPIListener);
H5P.on(instance, 'xAPI', H5P.xAPIEmitter);
// Resize everything when window is resized.
$window.resize(function () {
if (window.parent.H5P.isFullscreen) {
// Use timeout to avoid bug in certain browsers when exiting fullscreen. Some browser will trigger resize before the fullscreenchange event.
H5P.deprecatedTrigger(instance, 'resize');
H5P.trigger(instance, 'resize');
}
else {
H5P.deprecatedTrigger(instance, 'resize');
H5P.trigger(instance, 'resize');
}
});
// Resize content.
H5P.deprecatedTrigger(instance, 'resize');
H5P.trigger(instance, 'resize');
});
// Insert H5Ps that should be in iframes.
@ -229,8 +229,8 @@ H5P.fullScreen = function ($element, instance, exitCallback, body) {
*/
var entered = function () {
// Do not rely on window resize events.
H5P.deprecatedTrigger(instance, 'resize');
H5P.deprecatedTrigger(instance, 'focus');
H5P.trigger(instance, 'resize');
H5P.trigger(instance, 'focus');
};
/**
@ -244,8 +244,8 @@ H5P.fullScreen = function ($element, instance, exitCallback, body) {
$classes.removeClass(classes);
// Do not rely on window resize events.
H5P.deprecatedTrigger(instance, 'resize');
H5P.deprecatedTrigger(instance, 'focus');
H5P.trigger(instance, 'resize');
H5P.trigger(instance, 'focus');
if (exitCallback !== undefined) {
exitCallback();
@ -421,7 +421,7 @@ H5P.newRunnable = function (library, contentId, $attachTo, skipResize) {
// Automatically call resize on resize event if defined
if (typeof instance.resize === 'function') {
H5P.deprecatedOn(instance, 'resize', instance.resize);
H5P.on(instance, 'resize', instance.resize);
}
if ($attachTo !== undefined) {
@ -429,7 +429,7 @@ H5P.newRunnable = function (library, contentId, $attachTo, skipResize) {
if (skipResize === undefined || !skipResize) {
// Resize content.
H5P.deprecatedTrigger(instance, 'resize');
H5P.trigger(instance, 'resize');
}
}
return instance;
@ -1132,20 +1132,47 @@ if (H5P.jQuery) {
});
}
H5P.deprecatedTrigger = function(instance, event) {
/**
* Trigger an event on an instance
*
* Helper function that triggers an event if the instance supports event handling
*
* @param {function} instance
* An H5P instance
* @param {string} eventType
* The event type
*/
H5P.trigger = function(instance, eventType) {
// Try new event system first
if (instance.trigger !== undefined) {
instance.trigger(event);
}
else if (instance.$ !== undefined) {
instance.$.trigger(event)
instance.trigger(eventType);
}
// Try deprecated event system
else if (instance.$ !== undefined && instance.$.trigger !== undefined) {
instance.$.trigger(eventType)
}
};
H5P.deprecatedOn = function(instance, event, handler) {
/**
* Register an event handler
*
* Helper function that registers an event handler for an event type if
* the instance supports event handling
*
* @param {function} instance
* An h5p instance
* @param {string} eventType
* The event type
* @param {function} handler
* Callback that gets triggered for events of the specified type
*/
H5P.on = function(instance, eventType, handler) {
// Try new event system first
if (instance.on !== undefined) {
instance.on(event, handler);
}
else if (instance.$ !== undefined) {
instance.$.on(event, handler)
instance.on(eventType, handler);
}
// Try deprecated event system
else if (instance.$ !== undefined && instance.$.on !== undefined) {
instance.$.on(eventType, handler)
}
};