WordPress.org

Make WordPress Core

Changeset 43517


Ignore:
Timestamp:
07/19/2018 09:59:23 PM (14 months ago)
Author:
obenland
Message:

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

Avoids a type error when obj is not set.

Fixes #44526.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/lib/admin-bar.js

    r43347 r43517  
    304304         */
    305305        var addEvent = function( obj, type, fn ) {
    306             if ( obj.addEventListener )
    307                 obj.addEventListener(type, fn, false);
    308             else if ( obj.attachEvent )
    309                 obj.attachEvent('on' + type, function() { return fn.call(obj, window.event);});
     306            if ( typeof obj.addEventListener === 'function' ) {
     307                obj.addEventListener( type, fn, false );
     308            } else if ( typeof obj.attachEvent === 'function' ) {
     309                obj.attachEvent( 'on' + type, function() {
     310                    return fn.call( obj, window.event );
     311                } );
     312            }
    310313        },
    311314
Note: See TracChangeset for help on using the changeset viewer.