Skip to content

Commit

Permalink
♻️ Remove Dependency On JQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
nadnoslen committed Mar 30, 2022
1 parent e8b5abc commit 12efba4
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 18 deletions.
31 changes: 15 additions & 16 deletions addon/mixins/viewport.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { computed } from '@ember/object';
import { not } from '@ember/object/computed';
import Mixin from '@ember/object/mixin';
import $ from 'jquery';
import { computed } from "@ember/object";
import { not } from "@ember/object/computed";
import Mixin from "@ember/object/mixin";

/**
* The Viewport mixin can be used to add a number of helpful responsive queries to any component. These
Expand All @@ -16,44 +15,44 @@ export default Mixin.create({
/**
* @return true when viewport is 1200px or wider, false otherwise.
*/
'lg?': computed('_width', function() {
"lg?": computed("_width", function () {
const width = this._width;
return width >= 1200;
}),
/**
* @return true when viewport is 992px to 1199px, false otherwise.
*/
'md?': computed('_width', function() {
"md?": computed("_width", function () {
const width = this._width;
return width >= 992 && width < 1200;
}),
/**
* @return true when the Viewport is less than 1200px, false otherwise.
*/
'notLg?': not('lg?'),
"notLg?": not("lg?"),
/**
* @return true when the Viewport is less than 992px or greater than 1199px, false otherwise.
*/
'notMd?': not('md?'),
"notMd?": not("md?"),
/**
* @return true when the Viewport is less than 768px or greater than 991px, false otherwise.
*/
'notSm?': not('sm?'),
"notSm?": not("sm?"),
/**
* @return true when the Viewport is greater than 767px, false otherwise.
*/
'notXs?': not('xs?'),
"notXs?": not("xs?"),
/**
* @return true when viewport is 768px to 991px, false otherwise.
*/
'sm?': computed('_width', function() {
"sm?": computed("_width", function () {
const width = this._width;
return width >= 768 && width < 992;
}),
/**
* @return true when viewport is smaller than 768px, false otherwise.
*/
'xs?': computed('_width', function() {
"xs?": computed("_width", function () {
const width = this._width;
return width < 768;
}),
Expand All @@ -63,11 +62,11 @@ export default Mixin.create({
init() {
this._super(arguments);
const self = this;
$(window).on('resize', () => {
if (!(self.get('isDestroyed') || self.get('isDestroying'))) {
self.set('_width', $(window).width());
window.addEventListener("resize", () => {
if (!(self.get("isDestroyed") || self.get("isDestroying"))) {
self.set("_width", window.innerWidth);
}
});
},
_width: $(window).width()
_width: window.innerWidth,
});
5 changes: 5 additions & 0 deletions tests/dummy/app/controllers/viewport-demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Viewport from "ember-cli-bootstrap3-grid/mixins/viewport";

import Controller from "@ember/controller";

export default Controller.extend(Viewport, {});
1 change: 1 addition & 0 deletions tests/dummy/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const Router = EmberRouter.extend({

Router.map(function() {
this.route('twbs-clearfix');
this.route('viewport-demo');
});

export default Router;
4 changes: 4 additions & 0 deletions tests/dummy/app/routes/viewport-demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Route from '@ember/routing/route';

export default Route.extend({
});
10 changes: 8 additions & 2 deletions tests/dummy/app/templates/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
<h1>Demo</h1>
<ul>
<li>
{{#link-to "twbs-clearfix"}}<code>twbs-clearfix</code> Component{{/link-to}}
{{#link-to "twbs-clearfix"}}
<code>twbs-clearfix</code>
Component
{{/link-to}}
</li>
<li>
{{#link-to "viewport-demo"}}<code>Viewport</code> Mixin Demo{{/link-to}}
</li>
</ul>
</div>
</div>
9 changes: 9 additions & 0 deletions tests/dummy/app/templates/viewport-demo.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="container">
<h2>Viewport</h2>
<ul>
<li>Is XS {{xs?}}</li>
<li>Is SM {{sm?}}</li>
<li>Is MD {{md?}}</li>
<li>Is LG {{lg?}}</li>
</ul>
</div>

0 comments on commit 12efba4

Please sign in to comment.