Toolbar: Fail gracefully when adding events to non-existent elements

Avoids a type error when `obj` is not set.

Fixes #44526.


git-svn-id: https://develop.svn.wordpress.org/trunk@43517 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
obenland 2018-07-19 21:59:23 +00:00
parent e7d9ee5051
commit 9d4b0ec88f
1 changed files with 7 additions and 4 deletions

View File

@ -303,10 +303,13 @@ if ( typeof(jQuery) != 'undefined' ) {
* @return {void}
*/
var addEvent = function( obj, type, fn ) {
if ( obj.addEventListener )
obj.addEventListener(type, fn, false);
else if ( obj.attachEvent )
obj.attachEvent('on' + type, function() { return fn.call(obj, window.event);});
if ( typeof obj.addEventListener === 'function' ) {
obj.addEventListener( type, fn, false );
} else if ( typeof obj.attachEvent === 'function' ) {
obj.attachEvent( 'on' + type, function() {
return fn.call( obj, window.event );
} );
}
},
aB, hc = new RegExp('\\bhover\\b', 'g'), q = [],