fancyapps / fancybox

jQuery lightbox script for displaying images, videos and more. Touch enabled, responsive and fully customizable.
http://fancyapps.com/
7.28k stars 1.78k forks source link

.blur() deprecated #1784

Closed mnbeer closed 6 years ago

mnbeer commented 6 years ago

Should the following:

        // Save last active element and current scroll position
        self.$lastFocus = $(document.activeElement).blur();

be

        // Save last active element and current scroll position
        self.$lastFocus = $(document.activeElement).trigger('blur');

?

The line is kicking up a warning in jQuery Migrate.

jQuery.fn.blur() event shorthand is deprecated

fancyapps commented 6 years ago

Hi,

While I do not think that blur() method would be deprecated - https://api.jquery.com/blur/ - I'll replace with trigger. Thanks.

mnbeer commented 6 years ago

Thanks. See: https://github.com/jquery/jquery-migrate/blob/master/warnings.md

JQMIGRATE: jQuery.fn.click() event shorthand is deprecated Cause: The .on() and .trigger() methods can set an event handler or generate an event for any event type, and should be used instead of the shortcut methods. This message also applies to the other event shorthands, including: blur, focus, focusin, focusout, resize, scroll, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, mouseenter, mouseleave, change, select, submit, keydown, keypress, keyup, and contextmenu.

Solution: Instead of .click(fn) use .on("click", fn). Instead of .click() use .trigger("click").

fancyapps commented 6 years ago

Interestingly, there are still debates whether to deprecate .on() or not - https://github.com/jquery/jquery/issues/3214

mnbeer commented 6 years ago

I think it can be confidently assumed that removal isn't going to happen for a long time, even if deprecated. But it is clear that on() and trigger() are now considered "best practice". So, it makes sense to do that.