Skip to content

Commit

Permalink
Fix JQuery UI 1.14 incompatibility, with updating vendorized one
Browse files Browse the repository at this point in the history
  • Loading branch information
mshibuya committed Aug 18, 2024
1 parent 876be11 commit e66cdc3
Show file tree
Hide file tree
Showing 18 changed files with 574 additions and 1,246 deletions.
10 changes: 10 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,14 @@ namespace :vendorize do
locales = Dir.glob('node_modules/flatpickr/dist/l10n/*.js').map { |f| File.read(f) }
File.write('vendor/assets/javascripts/rails_admin/flatpickr-with-locales.js', ([flatpickr] + locales).join("\n"))
end

task :jquery_ui do
Dir.chdir(__dir__)
Dir.glob('vendor/assets/javascripts/rails_admin/jquery-ui/**/*.js').each do |dest|
src = dest.sub(%r{vendor/assets/javascripts/rails_admin/jquery-ui/}, 'node_modules/jquery-ui/ui/')
FileUtils.cp(src, dest)
rescue Errno::ENOENT
warn "File #{src} doesn't exist, skipping"
end
end
end
4 changes: 2 additions & 2 deletions spec/dummy_app/config/importmap.rails_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
pin 'bootstrap', to: 'https://ga.jspm.io/npm:[email protected]/dist/js/bootstrap.esm.js'
pin 'flatpickr', to: 'https://ga.jspm.io/npm:[email protected]/dist/flatpickr.js'
pin 'flatpickr/', to: 'https://ga.jspm.io/npm:[email protected]/'
pin 'jquery', to: 'https://ga.jspm.io/npm:jquery@3.6.0/dist/jquery.js'
pin 'jquery-ui/', to: 'https://ga.jspm.io/npm:jquery-ui@1.13.1/'
pin 'jquery', to: 'https://ga.jspm.io/npm:jquery@3.7.1/dist/jquery.js'
pin 'jquery-ui/', to: 'https://ga.jspm.io/npm:jquery-ui@1.14.0/'
pin 'trix', to: 'https://ga.jspm.io/npm:[email protected]/dist/trix.js'
2 changes: 1 addition & 1 deletion spec/dummy_app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@rails/actiontext": "^7.0.3-1",
"@rails/activestorage": "^7.0.3-1",
"@rails/webpacker": "5.4.3",
"rails_admin": "file:../../",
"rails_admin": "file:../..",
"trix": "^2.0.0-beta.0",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.12"
Expand Down
10 changes: 8 additions & 2 deletions src/rails_admin/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ import "bootstrap";
import "jquery-ui/ui/version.js";
import "jquery-ui/ui/keycode.js";
import "jquery-ui/ui/position.js";
import "jquery-ui/ui/safe-active-element.js";
import "jquery-ui/ui/data.js";
import "jquery-ui/ui/ie.js";
import "jquery-ui/ui/scroll-parent.js";
import "jquery-ui/ui/unique-id.js";
import "jquery-ui/ui/widget.js";
import "jquery-ui/ui/widgets/menu.js";
import "jquery-ui/ui/widgets/mouse.js";

// For compatibility with jQuery UI < 1.14
console.log(window.$.ui.safeActiveElement);
if (window.$.ui.safeActiveElement === undefined) {
window.$.ui.safeActiveElement = function (document) {
return document.activeElement;
};
}

import "./abstract-select";
import "./filter-box";
import "./filtering-multiselect";
Expand Down
36 changes: 16 additions & 20 deletions vendor/assets/javascripts/rails_admin/jquery-ui/data.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
//= require rails_admin/jquery-ui/version

/*!
* jQuery UI :data 1.12.1
* http://jqueryui.com
* jQuery UI :data 1.14.0
* https://jqueryui.com
*
* Copyright jQuery Foundation and other contributors
* Copyright OpenJS Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
* https://jquery.org/license
*/

//>>label: :data Selector
//>>group: Core
//>>description: Selects elements which have data stored under the specified key.
//>>docs: http://api.jqueryui.com/data-selector/
//>>docs: https://api.jqueryui.com/data-selector/

( function( factory ) {
"use strict";

if ( typeof define === "function" && define.amd ) {

// AMD. Register as an anonymous module.
Expand All @@ -24,18 +24,14 @@
// Browser globals
factory( jQuery );
}
} ( function( $ ) {
return $.extend( $.expr[ ":" ], {
data: $.expr.createPseudo ?
$.expr.createPseudo( function( dataName ) {
return function( elem ) {
return !!$.data( elem, dataName );
};
} ) :
} )( function( $ ) {
"use strict";

// Support: jQuery <1.8
function( elem, i, match ) {
return !!$.data( elem, match[ 3 ] );
}
return $.extend( $.expr.pseudos, {
data: $.expr.createPseudo( function( dataName ) {
return function( elem ) {
return !!$.data( elem, dataName );
};
} )
} );
} );
} ) );
Loading

0 comments on commit e66cdc3

Please sign in to comment.