1, add missing polyfill for IE9,10

2, IE9, 10, function alias causes error and all audio can't work properly
This commit is contained in:
J.C 2021-12-21 17:09:55 +08:00
parent 38fa339196
commit 57dee7c461
2 changed files with 16 additions and 10 deletions

View file

@ -44,4 +44,6 @@ if (typeof window.Uint32Array !== 'function' && typeof window.Uint32Array !== 'o
CheapArray('Uint16Array'); // jshint ignore:line
CheapArray('Int16Array'); // jshint ignore:line
CheapArray('ArrayBuffer'); // jshint ignore:line
CheapArray('Int8Array'); // jshint ignore:line
CheapArray('Uint8Array'); // jshint ignore:line
}

View file

@ -194,9 +194,13 @@ var BaseSoundManager = new Class({
var _this = this;
var body = document.body;
var bodyAdd = body.addEventListener;
var bodyRemove = body.removeEventListener;
// function alias throws error in IE9, 10
// https://stackoverflow.com/questions/1007340/javascript-function-aliasing-doesnt-seem-to-work
// var bodyAdd = body.addEventListener;
// var bodyRemove = body.removeEventListener;
var unlockHandler = function unlockHandler ()
{
if (!_this.pendingUnlock)
@ -206,18 +210,18 @@ var BaseSoundManager = new Class({
_this.unlockHandler();
bodyRemove('touchstart', unlockHandler);
bodyRemove('touchend', unlockHandler);
bodyRemove('click', unlockHandler);
bodyRemove('keydown', unlockHandler);
document.body.removeEventListener('touchstart', unlockHandler);
document.body.removeEventListener('touchend', unlockHandler);
document.body.removeEventListener('click', unlockHandler);
document.body.removeEventListener('keydown', unlockHandler);
};
if (body)
{
bodyAdd('touchstart', unlockHandler, false);
bodyAdd('touchend', unlockHandler, false);
bodyAdd('click', unlockHandler, false);
bodyAdd('keydown', unlockHandler, false);
document.body.addEventListener('touchstart', unlockHandler, false);
document.body.addEventListener('touchend', unlockHandler, false);
document.body.addEventListener('click', unlockHandler, false);
document.body.addEventListener('keydown', unlockHandler, false);
this.pendingUnlock = true;
}