Add documentation and change function names for deprecated functions
parent
fc4f791e6e
commit
c8a2465827
71
js/h5p.js
71
js/h5p.js
|
@ -118,7 +118,7 @@ H5P.init = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
var resizeDelay;
|
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.
|
// Use a delay to make sure iframe is resized to the correct size.
|
||||||
clearTimeout(resizeDelay);
|
clearTimeout(resizeDelay);
|
||||||
resizeDelay = setTimeout(function () {
|
resizeDelay = setTimeout(function () {
|
||||||
|
@ -128,22 +128,22 @@ H5P.init = function () {
|
||||||
H5P.instances.push(instance);
|
H5P.instances.push(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
H5P.deprecatedOn(instance, 'xAPI', H5P.xAPIListener);
|
H5P.on(instance, 'xAPI', H5P.xAPIListener);
|
||||||
H5P.deprecatedOn(instance, 'xAPI', H5P.xAPIEmitter);
|
H5P.on(instance, 'xAPI', H5P.xAPIEmitter);
|
||||||
|
|
||||||
// Resize everything when window is resized.
|
// Resize everything when window is resized.
|
||||||
$window.resize(function () {
|
$window.resize(function () {
|
||||||
if (window.parent.H5P.isFullscreen) {
|
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.
|
// 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 {
|
else {
|
||||||
H5P.deprecatedTrigger(instance, 'resize');
|
H5P.trigger(instance, 'resize');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Resize content.
|
// Resize content.
|
||||||
H5P.deprecatedTrigger(instance, 'resize');
|
H5P.trigger(instance, 'resize');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Insert H5Ps that should be in iframes.
|
// Insert H5Ps that should be in iframes.
|
||||||
|
@ -229,8 +229,8 @@ H5P.fullScreen = function ($element, instance, exitCallback, body) {
|
||||||
*/
|
*/
|
||||||
var entered = function () {
|
var entered = function () {
|
||||||
// Do not rely on window resize events.
|
// Do not rely on window resize events.
|
||||||
H5P.deprecatedTrigger(instance, 'resize');
|
H5P.trigger(instance, 'resize');
|
||||||
H5P.deprecatedTrigger(instance, 'focus');
|
H5P.trigger(instance, 'focus');
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -244,8 +244,8 @@ H5P.fullScreen = function ($element, instance, exitCallback, body) {
|
||||||
$classes.removeClass(classes);
|
$classes.removeClass(classes);
|
||||||
|
|
||||||
// Do not rely on window resize events.
|
// Do not rely on window resize events.
|
||||||
H5P.deprecatedTrigger(instance, 'resize');
|
H5P.trigger(instance, 'resize');
|
||||||
H5P.deprecatedTrigger(instance, 'focus');
|
H5P.trigger(instance, 'focus');
|
||||||
|
|
||||||
if (exitCallback !== undefined) {
|
if (exitCallback !== undefined) {
|
||||||
exitCallback();
|
exitCallback();
|
||||||
|
@ -421,7 +421,7 @@ H5P.newRunnable = function (library, contentId, $attachTo, skipResize) {
|
||||||
|
|
||||||
// Automatically call resize on resize event if defined
|
// Automatically call resize on resize event if defined
|
||||||
if (typeof instance.resize === 'function') {
|
if (typeof instance.resize === 'function') {
|
||||||
H5P.deprecatedOn(instance, 'resize', instance.resize);
|
H5P.on(instance, 'resize', instance.resize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($attachTo !== undefined) {
|
if ($attachTo !== undefined) {
|
||||||
|
@ -429,7 +429,7 @@ H5P.newRunnable = function (library, contentId, $attachTo, skipResize) {
|
||||||
|
|
||||||
if (skipResize === undefined || !skipResize) {
|
if (skipResize === undefined || !skipResize) {
|
||||||
// Resize content.
|
// Resize content.
|
||||||
H5P.deprecatedTrigger(instance, 'resize');
|
H5P.trigger(instance, 'resize');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return instance;
|
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) {
|
if (instance.trigger !== undefined) {
|
||||||
instance.trigger(event);
|
instance.trigger(eventType);
|
||||||
}
|
|
||||||
else if (instance.$ !== undefined) {
|
|
||||||
instance.$.trigger(event)
|
|
||||||
}
|
}
|
||||||
|
// 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) {
|
if (instance.on !== undefined) {
|
||||||
instance.on(event, handler);
|
instance.on(eventType, handler);
|
||||||
}
|
|
||||||
else if (instance.$ !== undefined) {
|
|
||||||
instance.$.on(event, handler)
|
|
||||||
}
|
}
|
||||||
|
// Try deprecated event system
|
||||||
|
else if (instance.$ !== undefined && instance.$.on !== undefined) {
|
||||||
|
instance.$.on(eventType, handler)
|
||||||
}
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue