I have been using jQuery for various small things like datepicker and reveal modals and animations in my application, now. I ran ember-modules-codemod and all of my files (800+) are updated.
That also changed jQuery imports. I have been using Ember.$( for Global level and this.$( for component level .
What are my options and how I can keep both of them working.
Right now
import Ember from 'ember';
const {$} = Ember;
// `error Use import $ from 'jquery'; instead of using Ember destructuring ember/new-module-imports`
and
import $ from 'jquery';
// `error Do not use global `$` or `jQuery` ember/no-global-jquery`
I have used it like
Ember.$(body).addClass('blurBG'); // to blur out whole page under the popup
this.$().autocomplete(); // implement jquery autocomplete on a textfield
I am upgrading my “very huge application” which i started in Ember 0.7 version. Updated it to latest Ember 2.16.
Error is due to eslint-plugin-ember package and there is no compiling error just linting. As ember-modules-codemod modified my whole codebase I was not sure what should I do with my jquery stuff.
I have created a blank project and tested what you suggested. seems working fine. Below is my test component
import $ from 'jquery';
import Component from '@ember/component';
export default Component.extend({
didInsertElement() {
this.$().css({'background-color': 'red'});
$('body').css({'background-color': 'blue'});
},
});
We have had the same “issue” but we decided to get rid of jQuery. We don’t need to support super old browser so it’s not that hard for us. There is no general solution for example you could replace the following code with:
And the no jQuery version:
document.body.classList.add('blurBG')
Removing jQuery also reduces the payload of your app which is also a good thing