Skip to content

Commit

Permalink
STRF-5732: Get rid of jquery-migrate
Browse files Browse the repository at this point in the history
* We only need a small subset of jquery-migrate (to support Foundation
5.5), so pull that in directly rather than the whole library
  • Loading branch information
mattolson committed Jan 8, 2019
1 parent a2a25ae commit dcc5585
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
1 change: 0 additions & 1 deletion assets/js/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
__webpack_public_path__ = window.__webpack_public_path__; // eslint-disable-line

import 'jquery-migrate';
import Global from './theme/global';

const getAccount = () => import('./theme/account');
Expand Down
1 change: 1 addition & 0 deletions assets/js/theme/global.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './global/jquery-migrate';
import './common/select-option-plugin';
import PageManager from './page-manager';
import quickSearch from './global/quick-search';
Expand Down
34 changes: 34 additions & 0 deletions assets/js/theme/global/jquery-migrate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// From https://github.com/jquery/jquery-migrate/blob/master/src/event.js
// Needed because we use Foundation 5.5, which expects jQuery 2.x. However,
// rather than bringing in all of jquery-migrate, we're cherry picking individual
// fixes needed for Foundation.
//
// See https://stackoverflow.com/questions/37738732/jquery-3-0-url-indexof-error/37915907#37915907
//
jQuery.each( [ "load", "unload", "error" ], function( _, name ) {

jQuery.fn[ name ] = function() {
var args = Array.prototype.slice.call( arguments, 0 );

// If this is an ajax load() the first arg should be the string URL;
// technically this could also be the "Anything" arg of the event .load()
// which just goes to show why this dumb signature has been deprecated!
// jQuery custom builds that exclude the Ajax module justifiably die here.
if ( name === "load" && typeof args[ 0 ] === "string" ) {
return oldLoad.apply( this, args );
}

args.splice( 0, 0, name );
if ( arguments.length ) {
return this.on.apply( this, args );
}

// Use .triggerHandler here because:
// - load and unload events don't need to bubble, only applied to window or image
// - error event should not bubble to window, although it does pre-1.7
// See http://bugs.jquery.com/ticket/11820
this.triggerHandler.apply( this, args );
return this;
};

} );
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"easyzoom": "^2.5.0",
"foundation-sites": "^5.5.3",
"jquery": "^3.3.1",
"jquery-migrate": "^1.4.1",
"jstree": "vakata/jstree",
"lazysizes": "4.1.2",
"lodash": "^4.17.4",
Expand Down
7 changes: 1 addition & 6 deletions webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ module.exports = {
},
},
},
{
test: /jquery-migrate/,
use: 'imports-loader?define=>false',
},
],
},
output: {
Expand All @@ -48,7 +44,7 @@ module.exports = {
performance: {
hints: 'warning',
maxAssetSize: 1024 * 150,
maxEntrypointSize: 1024 * 300,
maxEntrypointSize: 1024 * 150,
},
plugins: [
new CleanPlugin(['assets/dist'], {
Expand All @@ -69,7 +65,6 @@ module.exports = {
resolve: {
alias: {
jquery: path.resolve(__dirname, 'node_modules/jquery/dist/jquery.min.js'),
'jquery-migrate': path.resolve(__dirname, 'node_modules/jquery-migrate/dist/jquery-migrate.min.js'),
jstree: path.resolve(__dirname, 'node_modules/jstree/dist/jstree.min.js'),
lazysizes: path.resolve(__dirname, 'node_modules/lazysizes/lazysizes.min.js'),
pace: path.resolve(__dirname, 'node_modules/pace/pace.min.js'),
Expand Down

0 comments on commit dcc5585

Please sign in to comment.