diff options
-rw-r--r-- | app/assets/javascripts/application.js | 32 | ||||
-rw-r--r-- | app/assets/javascripts/commons/bootstrap.js | 18 | ||||
-rw-r--r-- | app/assets/javascripts/commons/index.js | 4 | ||||
-rw-r--r-- | app/assets/javascripts/commons/jquery.js | 21 | ||||
-rw-r--r-- | config/webpack.config.js | 6 |
5 files changed, 49 insertions, 32 deletions
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 8441a335ac0..798553c16ac 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -6,14 +6,29 @@ /* global AwardsHandler */ /* global Aside */ -// common libraries -window.Cookies = require('js-cookie'); -window.Pikaday = require('pikaday'); -window._ = require('underscore'); -window.Dropzone = require('dropzone'); -window.Sortable = require('vendor/Sortable'); +import jQuery from 'jquery'; +import _ from 'underscore'; +import Cookies from 'js-cookie'; +import Pikaday from 'pikaday'; +import Dropzone from 'dropzone'; +import Sortable from 'vendor/Sortable'; + +// libraries with import side-effects require('mousetrap'); require('mousetrap/plugins/pause/mousetrap-pause'); +require('vendor/fuzzaldrin-plus'); +require('es6-promise').polyfill(); + +// expose common libraries as globals (TODO: remove these) +window.jQuery = jQuery; +window.$ = jQuery; +window._ = _; +window.Cookies = Cookies; +window.Pikaday = Pikaday; +window.Dropzone = Dropzone; +window.Sortable = Sortable; + +// shortcuts require('./shortcuts'); require('./shortcuts_navigation'); require('./shortcuts_dashboard_navigation'); @@ -189,9 +204,6 @@ require('./visibility_select'); require('./wikis'); require('./zen_mode'); -require('vendor/fuzzaldrin-plus'); -require('es6-promise').polyfill(); - (function () { document.addEventListener('beforeunload', function () { // Unbind scroll events @@ -269,7 +281,7 @@ require('es6-promise').polyfill(); $.fn.tooltip.Constructor.DEFAULTS.trigger = 'hover'; $body.tooltip({ selector: '.has-tooltip, [data-toggle="tooltip"]', - placement: function (_, el) { + placement: function (tip, el) { return $(el).data('placement') || 'bottom'; } }); diff --git a/app/assets/javascripts/commons/bootstrap.js b/app/assets/javascripts/commons/bootstrap.js index 72e43d34a74..db0cbfd87c3 100644 --- a/app/assets/javascripts/commons/bootstrap.js +++ b/app/assets/javascripts/commons/bootstrap.js @@ -1,10 +1,10 @@ -require('./jquery'); +import 'jquery'; -// twitter bootstrap plugins -require('bootstrap-sass/assets/javascripts/bootstrap/affix'); -require('bootstrap-sass/assets/javascripts/bootstrap/alert'); -require('bootstrap-sass/assets/javascripts/bootstrap/dropdown'); -require('bootstrap-sass/assets/javascripts/bootstrap/modal'); -require('bootstrap-sass/assets/javascripts/bootstrap/tab'); -require('bootstrap-sass/assets/javascripts/bootstrap/transition'); -require('bootstrap-sass/assets/javascripts/bootstrap/tooltip'); +// bootstrap jQuery plugins +import 'bootstrap-sass/assets/javascripts/bootstrap/affix'; +import 'bootstrap-sass/assets/javascripts/bootstrap/alert'; +import 'bootstrap-sass/assets/javascripts/bootstrap/dropdown'; +import 'bootstrap-sass/assets/javascripts/bootstrap/modal'; +import 'bootstrap-sass/assets/javascripts/bootstrap/tab'; +import 'bootstrap-sass/assets/javascripts/bootstrap/transition'; +import 'bootstrap-sass/assets/javascripts/bootstrap/tooltip'; diff --git a/app/assets/javascripts/commons/index.js b/app/assets/javascripts/commons/index.js index a9226bc1325..72ede1d621a 100644 --- a/app/assets/javascripts/commons/index.js +++ b/app/assets/javascripts/commons/index.js @@ -1,2 +1,2 @@ -require('./jquery'); -require('./bootstrap'); +import './jquery'; +import './bootstrap'; diff --git a/app/assets/javascripts/commons/jquery.js b/app/assets/javascripts/commons/jquery.js index 9ef415d6a95..b53f6284afc 100644 --- a/app/assets/javascripts/commons/jquery.js +++ b/app/assets/javascripts/commons/jquery.js @@ -1,12 +1,11 @@ -// jQuery library -window.$ = window.jQuery = require('jquery'); +import 'jquery'; -// jQuery plugins -require('jquery-ujs'); -require('vendor/jquery.endless-scroll'); -require('vendor/jquery.caret'); -require('vendor/jquery.atwho'); -require('vendor/jquery.scrollTo'); -require('vendor/jquery.nicescroll'); -require('vendor/jquery.waitforimages'); -require('select2/select2.js'); +// common jQuery plugins +import 'jquery-ujs'; +import 'vendor/jquery.endless-scroll'; +import 'vendor/jquery.caret'; +import 'vendor/jquery.atwho'; +import 'vendor/jquery.scrollTo'; +import 'vendor/jquery.nicescroll'; +import 'vendor/jquery.waitforimages'; +import 'select2/select2'; diff --git a/config/webpack.config.js b/config/webpack.config.js index c2e0e86fb78..a76daa2ba95 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -87,6 +87,12 @@ var config = { // prevent pikaday from including moment.js new webpack.IgnorePlugin(/moment/, /pikaday/), + // fix legacy jQuery plugins which depend on globals + new webpack.ProvidePlugin({ + $: 'jquery', + jQuery: 'jquery', + }), + // use deterministic module ids in all environments IS_PRODUCTION ? new webpack.HashedModuleIdsPlugin() : |