Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
Add support for jQuery 3
Browse files Browse the repository at this point in the history
$(document).on("ready", handler) was deprecated in jQuery 1.8 and
removed in 3
  • Loading branch information
taylor-steve committed Aug 15, 2024
1 parent 0716b2a commit 61c291e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/assets/javascripts/openseadragon/rails.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
$('picture[data-openseadragon]').openseadragon();
}

var handler = 'ready';
const jquery3 = parseInt($.fn.jquery.split('.')[0]) >= 3;
let handler = 'ready';
if (typeof Turbolinks !== 'undefined' && Turbolinks.supported) {
// Turbolinks 5
if (Turbolinks.BrowserAdapter) {
Expand All @@ -15,5 +16,14 @@
handler = 'page:load ready';
}
}
$(document).on(handler, initOpenSeadragon);

// Support for $(document).on( "ready", handler ) was removed in jQuery 3
if (jquery3 && handler.includes('ready')) {
handler = handler.replace('ready', '').trim();
$(initOpenSeadragon);
}

if (handler) {
$(document).on(handler, initOpenSeadragon);
}
})(jQuery);

0 comments on commit 61c291e

Please sign in to comment.