├── .editorconfig ├── .ember-cli ├── .eslintrc.js ├── .gitignore ├── .npmignore ├── .travis.yml ├── .watchmanconfig ├── LICENSE.md ├── README.md ├── addon ├── .gitkeep └── mixins │ └── resize-aware.js ├── app └── .gitkeep ├── config ├── ember-try.js └── environment.js ├── ember-cli-build.js ├── index.js ├── package.json ├── testem.js ├── tests ├── dummy │ ├── app │ │ ├── app.js │ │ ├── components │ │ │ ├── .gitkeep │ │ │ └── test-resize │ │ │ │ ├── component.js │ │ │ │ └── template.hbs │ │ ├── controllers │ │ │ └── .gitkeep │ │ ├── helpers │ │ │ └── .gitkeep │ │ ├── index.html │ │ ├── models │ │ │ └── .gitkeep │ │ ├── resolver.js │ │ ├── router.js │ │ ├── routes │ │ │ └── .gitkeep │ │ ├── styles │ │ │ └── app.css │ │ └── templates │ │ │ ├── application.hbs │ │ │ └── components │ │ │ └── .gitkeep │ ├── config │ │ ├── environment.js │ │ └── targets.js │ └── public │ │ └── robots.txt ├── helpers │ └── .gitkeep ├── index.html ├── integration │ └── .gitkeep ├── test-helper.js └── unit │ ├── .gitkeep │ └── mixins │ └── resize-aware-test.js ├── vendor └── .gitkeep └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | [*] 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | indent_style = space 11 | indent_size = 2 12 | 13 | [*.hbs] 14 | insert_final_newline = false 15 | 16 | [*.{diff,md}] 17 | trim_trailing_whitespace = false 18 | -------------------------------------------------------------------------------- /.ember-cli: -------------------------------------------------------------------------------- 1 | { 2 | /** 3 | Ember CLI sends analytics information by default. The data is completely 4 | anonymous, but there are times when you might want to disable this behavior. 5 | 6 | Setting `disableAnalytics` to true will prevent any data from being sent. 7 | */ 8 | "disableAnalytics": false 9 | } 10 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | parserOptions: { 4 | ecmaVersion: 2017, 5 | sourceType: 'module' 6 | }, 7 | plugins: [ 8 | 'ember' 9 | ], 10 | extends: [ 11 | 'eslint:recommended', 12 | 'plugin:ember/recommended' 13 | ], 14 | env: { 15 | browser: true 16 | }, 17 | rules: { 18 | }, 19 | overrides: [ 20 | // node files 21 | { 22 | files: [ 23 | 'index.js', 24 | 'testem.js', 25 | 'ember-cli-build.js', 26 | 'config/**/*.js', 27 | 'tests/dummy/config/**/*.js' 28 | ], 29 | excludedFiles: [ 30 | 'app/**', 31 | 'addon/**', 32 | 'tests/dummy/app/**' 33 | ], 34 | parserOptions: { 35 | sourceType: 'script', 36 | ecmaVersion: 2015 37 | }, 38 | env: { 39 | browser: false, 40 | node: true 41 | }, 42 | plugins: ['node'], 43 | rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, { 44 | // add your custom rules and overrides for node files here 45 | }) 46 | } 47 | ] 48 | }; 49 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | 7 | # dependencies 8 | /node_modules 9 | /bower_components 10 | 11 | # misc 12 | /.sass-cache 13 | /connect.lock 14 | /coverage/* 15 | /libpeerconnection.log 16 | npm-debug.log* 17 | yarn-error.log 18 | testem.log 19 | 20 | # ember-try 21 | .node_modules.ember-try/ 22 | bower.json.ember-try 23 | package.json.ember-try 24 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /bower_components 2 | /config/ember-try.js 3 | /dist 4 | /tests 5 | /tmp 6 | **/.gitkeep 7 | .bowerrc 8 | .editorconfig 9 | .ember-cli 10 | .eslintrc.js 11 | .gitignore 12 | .watchmanconfig 13 | .travis.yml 14 | bower.json 15 | ember-cli-build.js 16 | testem.js 17 | 18 | # ember-try 19 | .node_modules.ember-try/ 20 | bower.json.ember-try 21 | package.json.ember-try 22 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: node_js 3 | node_js: 4 | - "8" 5 | 6 | sudo: required 7 | dist: trusty 8 | 9 | addons: 10 | chrome: stable 11 | 12 | cache: 13 | yarn: true 14 | 15 | env: 16 | global: 17 | # See https://git.io/vdao3 for details. 18 | - JOBS=1 19 | matrix: 20 | - SCRIPT=lint:js 21 | - SCRIPT=test 22 | # - SCRIPT=test:fastboot 23 | # - SCRIPT=test:node 24 | 25 | matrix: 26 | fast_finish: true 27 | allow_failures: 28 | - env: EMBER_TRY_SCENARIO=ember-canary 29 | 30 | before_install: 31 | - sudo chown root /opt/google/chrome/chrome-sandbox 32 | - sudo chmod 4755 /opt/google/chrome/chrome-sandbox 33 | - curl -o- -L https://yarnpkg.com/install.sh | bash 34 | - export PATH=$HOME/.yarn/bin:$PATH 35 | - yarn global add greenkeeper-lockfile@1 36 | 37 | install: 38 | - yarn install --no-lockfile --non-interactive 39 | 40 | before_script: 41 | - greenkeeper-lockfile-update 42 | 43 | script: 44 | - yarn run $SCRIPT 45 | 46 | after_script: 47 | - greenkeeper-lockfile-upload 48 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | { 2 | "ignore_dirs": ["tmp", "dist"] 3 | } 4 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ember-resize-aware 2 | ============================================================================== 3 | 4 | [![Greenkeeper badge](https://badges.greenkeeper.io/Duder-onomy/ember-resize-aware.svg)](https://greenkeeper.io/) 5 | 6 | [![Build Status](https://travis-ci.org/Duder-onomy/ember-resize-aware.svg?branch=master)](https://travis-ci.org/Duder-onomy/ember-resize-aware) 7 | 8 | [![npm version](https://badge.fury.io/js/ember-resize-aware.svg)](https://badge.fury.io/js/ember-resize-aware) 9 | 10 | Checkout the [DEMO](https://duder-onomy.github.io/ember-resize-aware/) 11 | 12 | Simplified and updated version of `ember-resize`. 13 | Provides a mixin that you can use on your components, your components will have a `didResize` event called on them when appropriate. 14 | 15 | Uses [ember-singularity](https://github.com/trentmwillis/ember-singularity) under the hood for efficient and massively gangster event handling. 16 | 17 | Installation 18 | ------------------------------------------------------------------------------ 19 | 20 | ``` 21 | ember install ember-resize-aware 22 | ``` 23 | 24 | 25 | Usage 26 | ------------------------------------------------------------------------------ 27 | 28 | Just mix this sucker into a component or any ember object with the `didInsertElement` lifecycle hooks. 29 | 30 | ```javascript 31 | import Component from '@ember/component'; 32 | import ResizeAware from 'ember-resize-aware/mixins/resize-aware'; 33 | 34 | export default Component.extend(ResizeAware, { 35 | debounceRate: 400, // You can optionally set the debounce rate, the default is 200, 0 during testing. 36 | 37 | didResize(width, height) { 38 | // YOU GET THE WIDTH! AND THE HEIGHT! BOOM! 39 | }, 40 | }); 41 | ``` 42 | 43 | 44 | Contributing 45 | ------------------------------------------------------------------------------ 46 | 47 | ### Installation 48 | 49 | * `git clone ` 50 | * `cd ember-resize-aware` 51 | * `yarn install` 52 | 53 | ### Linting 54 | 55 | * `yarn lint:js` 56 | * `yarn lint:js --fix` 57 | 58 | ### Running tests 59 | 60 | * `ember test` – Runs the test suite on the current Ember version 61 | * `ember test --server` – Runs the test suite in "watch mode" 62 | * `yarn test` – Runs `ember try:each` to test your addon against multiple Ember versions 63 | 64 | ### Running the dummy application 65 | 66 | * `ember serve` 67 | * Visit the dummy application at [http://localhost:4200](http://localhost:4200). 68 | 69 | For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/). 70 | 71 | License 72 | ------------------------------------------------------------------------------ 73 | 74 | This project is licensed under the [MIT License](LICENSE.md). 75 | -------------------------------------------------------------------------------- /addon/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Duder-onomy/ember-resize-aware/5228409acb42e43301dfc9264896900ae1e0433e/addon/.gitkeep -------------------------------------------------------------------------------- /addon/mixins/resize-aware.js: -------------------------------------------------------------------------------- 1 | import Mixin from '@ember/object/mixin'; 2 | import { inject as service } from '@ember/service'; 3 | import { get, setProperties } from '@ember/object'; 4 | import { debounce, next, scheduleOnce } from '@ember/runloop'; 5 | import { tryInvoke } from '@ember/utils'; 6 | import Ember from 'ember'; 7 | 8 | export default Mixin.create({ 9 | unifiedEventHandler: service(), 10 | 11 | didResize(/*width, height*/) {}, // Overridden in subclass 12 | debounceRate: 200, // Overridden in subclass 13 | 14 | _previousWidth: null, 15 | _previousHeight: null, 16 | 17 | didInsertElement(...args) { 18 | this._super(...args); 19 | this._handleResizeEvent = this._handleResizeEvent.bind(this); 20 | scheduleOnce('afterRender', this, () => get(this, 'unifiedEventHandler').register('window', 'resize', this._handleResizeEvent)); 21 | }, 22 | 23 | willDestroyElement(...args) { 24 | this._super(...args); 25 | get(this, 'unifiedEventHandler').unregister('window', 'resize', this._handleResizeEvent); 26 | }, 27 | 28 | _handleResizeEvent() { 29 | debounce(this, this._debouncedResizeEvent, Ember.testing ? 0 : get(this, 'debounceRate')); 30 | }, 31 | 32 | _debouncedResizeEvent() { 33 | if (this.element) { 34 | const boundingRect = this.element.getBoundingClientRect(); 35 | 36 | const newWidth = Math.floor(boundingRect.width); 37 | const newHeight = Math.floor(boundingRect.height); 38 | 39 | if ((get(this, '_previousWidth') !== newWidth) || (get(this, '_previousHeight') !== newHeight)) { 40 | next(this, () => !get(this, 'isDestroyed') && tryInvoke(this, 'didResize', [newWidth, newHeight])); 41 | setProperties(this, { 42 | _previousWidth: newWidth, 43 | _previousHeight: newHeight 44 | }); 45 | } 46 | } 47 | } 48 | }); 49 | -------------------------------------------------------------------------------- /app/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Duder-onomy/ember-resize-aware/5228409acb42e43301dfc9264896900ae1e0433e/app/.gitkeep -------------------------------------------------------------------------------- /config/ember-try.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function() { 4 | return { 5 | useVersionCompatibility: true, 6 | useYarn: true, 7 | }; 8 | }; 9 | -------------------------------------------------------------------------------- /config/environment.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function(/* environment, appConfig */) { 4 | return { }; 5 | }; 6 | -------------------------------------------------------------------------------- /ember-cli-build.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); 4 | 5 | module.exports = function(defaults) { 6 | let app = new EmberAddon(defaults, { 7 | // Add options here 8 | }); 9 | 10 | /* 11 | This build file specifies the options for the dummy test app of this 12 | addon, located in `/tests/dummy` 13 | This build file does *not* influence how the addon or the app using it 14 | behave. You most likely want to be modifying `./index.js` or app's build file 15 | */ 16 | 17 | return app.toTree(); 18 | }; 19 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | name: 'ember-resize-aware' 5 | }; 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ember-resize-aware", 3 | "version": "1.2.0", 4 | "description": "Ember Component mixin to notify of size changes.", 5 | "keywords": [ 6 | "ember-addon" 7 | ], 8 | "homepage": "https://duder-onomy.github.io/ember-resize-aware/", 9 | "license": "MIT", 10 | "author": "", 11 | "directories": { 12 | "doc": "doc", 13 | "test": "tests" 14 | }, 15 | "repository": "https://github.com/Duder-onomy/ember-resize-aware", 16 | "scripts": { 17 | "build": "ember build", 18 | "lint:js": "eslint ./*.js addon config tests", 19 | "start": "ember serve", 20 | "test": "ember try:each" 21 | }, 22 | "dependencies": { 23 | "ember-cli-babel": "7.7.3", 24 | "ember-singularity": "^1.2.1" 25 | }, 26 | "devDependencies": { 27 | "ember-cli": "~3.10.0", 28 | "ember-cli-dependency-checker": "^3.0.0", 29 | "ember-cli-github-pages": "^0.2.0", 30 | "ember-cli-htmlbars": "^3.0.0", 31 | "ember-cli-htmlbars-inline-precompile": "^2.0.0", 32 | "ember-cli-inject-live-reload": "^2.0.1", 33 | "ember-cli-qunit": "^4.1.1", 34 | "ember-cli-shims": "^1.2.0", 35 | "ember-cli-sri": "^2.1.0", 36 | "ember-cli-uglify": "^3.0.0", 37 | "ember-disable-prototype-extensions": "^1.1.2", 38 | "ember-export-application-global": "^2.0.0", 39 | "ember-load-initializers": "^2.0.0", 40 | "ember-maybe-import-regenerator": "^0.1.6", 41 | "ember-resolver": "^5.0.0", 42 | "ember-source": "~3.10.0", 43 | "ember-try": "^1.0.0-beta.3", 44 | "eslint": "^5.9.0", 45 | "eslint-plugin-ember": "^6.4.1", 46 | "eslint-plugin-node": "^9.0.1", 47 | "loader.js": "^4.2.3" 48 | }, 49 | "engines": { 50 | "node": ">= 8.*" 51 | }, 52 | "ember-addon": { 53 | "configPath": "tests/dummy/config", 54 | "demoUrl": "https://duder-onomy.github.io/ember-resize-aware/", 55 | "versionCompatibility": { 56 | "ember": ">2.16" 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /testem.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | test_page: 'tests/index.html?hidepassed', 3 | disable_watching: true, 4 | launch_in_ci: [ 5 | 'Chrome' 6 | ], 7 | launch_in_dev: [ 8 | 'Chrome' 9 | ], 10 | browser_args: { 11 | Chrome: { 12 | mode: 'ci', 13 | args: [ 14 | // --no-sandbox is needed when running Chrome inside a container 15 | process.env.TRAVIS ? '--no-sandbox' : null, 16 | 17 | '--disable-gpu', 18 | '--headless', 19 | '--remote-debugging-port=0', 20 | '--window-size=1440,900' 21 | ].filter(Boolean) 22 | } 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /tests/dummy/app/app.js: -------------------------------------------------------------------------------- 1 | import Application from '@ember/application'; 2 | import Resolver from './resolver'; 3 | import loadInitializers from 'ember-load-initializers'; 4 | import config from './config/environment'; 5 | 6 | const App = Application.extend({ 7 | modulePrefix: config.modulePrefix, 8 | podModulePrefix: config.podModulePrefix, 9 | Resolver 10 | }); 11 | 12 | loadInitializers(App, config.modulePrefix); 13 | 14 | export default App; 15 | -------------------------------------------------------------------------------- /tests/dummy/app/components/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Duder-onomy/ember-resize-aware/5228409acb42e43301dfc9264896900ae1e0433e/tests/dummy/app/components/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/components/test-resize/component.js: -------------------------------------------------------------------------------- 1 | import Component from '@ember/component'; 2 | import { setProperties } from '@ember/object'; 3 | import ResizeAware from 'ember-resize-aware/mixins/resize-aware'; 4 | import layout from './template'; 5 | 6 | export default Component.extend(ResizeAware, { 7 | layout, 8 | 9 | width: null, 10 | height: null, 11 | 12 | didInsertElement(...args) { 13 | const boundingRect = this.element.getBoundingClientRect(); 14 | 15 | setProperties(this, { 16 | width: boundingRect.width, 17 | height: boundingRect.height, 18 | }); 19 | 20 | this._super(...args); 21 | }, 22 | 23 | didResize(width, height) { 24 | setProperties(this, { 25 | width, 26 | height, 27 | }); 28 | }, 29 | }); 30 | -------------------------------------------------------------------------------- /tests/dummy/app/components/test-resize/template.hbs: -------------------------------------------------------------------------------- 1 |
2 | Current width: {{width}} 3 |
4 |
5 | Current height: {{height}} 6 |
7 | -------------------------------------------------------------------------------- /tests/dummy/app/controllers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Duder-onomy/ember-resize-aware/5228409acb42e43301dfc9264896900ae1e0433e/tests/dummy/app/controllers/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/helpers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Duder-onomy/ember-resize-aware/5228409acb42e43301dfc9264896900ae1e0433e/tests/dummy/app/helpers/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Dummy 7 | 8 | 9 | 10 | {{content-for "head"}} 11 | 12 | 13 | 14 | 15 | {{content-for "head-footer"}} 16 | 17 | 18 | {{content-for "body"}} 19 | 20 | 21 | 22 | 23 | {{content-for "body-footer"}} 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/dummy/app/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Duder-onomy/ember-resize-aware/5228409acb42e43301dfc9264896900ae1e0433e/tests/dummy/app/models/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/resolver.js: -------------------------------------------------------------------------------- 1 | import Resolver from 'ember-resolver'; 2 | 3 | export default Resolver; 4 | -------------------------------------------------------------------------------- /tests/dummy/app/router.js: -------------------------------------------------------------------------------- 1 | import EmberRouter from '@ember/routing/router'; 2 | import config from './config/environment'; 3 | 4 | const Router = EmberRouter.extend({ 5 | location: config.locationType, 6 | rootURL: config.rootURL 7 | }); 8 | 9 | Router.map(function() { 10 | }); 11 | 12 | export default Router; 13 | -------------------------------------------------------------------------------- /tests/dummy/app/routes/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Duder-onomy/ember-resize-aware/5228409acb42e43301dfc9264896900ae1e0433e/tests/dummy/app/routes/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/styles/app.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding: 1rem; 3 | } 4 | .test-resize { 5 | display: flex; 6 | flex-direction: column; 7 | 8 | border: 1px solid black; 9 | 10 | height: 100%; 11 | } 12 | -------------------------------------------------------------------------------- /tests/dummy/app/templates/application.hbs: -------------------------------------------------------------------------------- 1 |

Ember Resize Aware

2 | 3 | Resize this window to see these values change! Boom! 4 | {{test-resize 5 | class='test-resize' 6 | }} 7 | 8 | {{outlet}} 9 | -------------------------------------------------------------------------------- /tests/dummy/app/templates/components/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Duder-onomy/ember-resize-aware/5228409acb42e43301dfc9264896900ae1e0433e/tests/dummy/app/templates/components/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/config/environment.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function(environment) { 4 | let ENV = { 5 | modulePrefix: 'dummy', 6 | environment, 7 | rootURL: '/', 8 | locationType: 'auto', 9 | EmberENV: { 10 | FEATURES: { 11 | // Here you can enable experimental features on an ember canary build 12 | // e.g. 'with-controller': true 13 | }, 14 | EXTEND_PROTOTYPES: { 15 | // Prevent Ember Data from overriding Date.parse. 16 | Date: false 17 | } 18 | }, 19 | 20 | APP: { 21 | // Here you can pass flags/options to your application instance 22 | // when it is created 23 | } 24 | }; 25 | 26 | if (environment === 'development') { 27 | // ENV.APP.LOG_RESOLVER = true; 28 | // ENV.APP.LOG_ACTIVE_GENERATION = true; 29 | // ENV.APP.LOG_TRANSITIONS = true; 30 | // ENV.APP.LOG_TRANSITIONS_INTERNAL = true; 31 | // ENV.APP.LOG_VIEW_LOOKUPS = true; 32 | } 33 | 34 | if (environment === 'test') { 35 | // Testem prefers this... 36 | ENV.locationType = 'none'; 37 | 38 | // keep test console output quieter 39 | ENV.APP.LOG_ACTIVE_GENERATION = false; 40 | ENV.APP.LOG_VIEW_LOOKUPS = false; 41 | 42 | ENV.APP.rootElement = '#ember-testing'; 43 | ENV.APP.autoboot = false; 44 | } 45 | 46 | if (environment === 'production') { 47 | ENV.locationType = 'hash'; 48 | ENV.rootURL = '/ember-resize-aware/'; 49 | // here you can enable a production-specific feature 50 | } 51 | 52 | return ENV; 53 | }; 54 | -------------------------------------------------------------------------------- /tests/dummy/config/targets.js: -------------------------------------------------------------------------------- 1 | const browsers = [ 2 | 'last 1 Chrome versions', 3 | 'last 1 Firefox versions', 4 | 'last 1 Safari versions' 5 | ]; 6 | 7 | const isCI = !!process.env.CI; 8 | const isProduction = process.env.EMBER_ENV === 'production'; 9 | 10 | if (isCI || isProduction) { 11 | browsers.push('ie 11'); 12 | } 13 | 14 | module.exports = { 15 | browsers 16 | }; 17 | -------------------------------------------------------------------------------- /tests/dummy/public/robots.txt: -------------------------------------------------------------------------------- 1 | # http://www.robotstxt.org 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /tests/helpers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Duder-onomy/ember-resize-aware/5228409acb42e43301dfc9264896900ae1e0433e/tests/helpers/.gitkeep -------------------------------------------------------------------------------- /tests/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Dummy Tests 7 | 8 | 9 | 10 | {{content-for "head"}} 11 | {{content-for "test-head"}} 12 | 13 | 14 | 15 | 16 | 17 | {{content-for "head-footer"}} 18 | {{content-for "test-head-footer"}} 19 | 20 | 21 | {{content-for "body"}} 22 | {{content-for "test-body"}} 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | {{content-for "body-footer"}} 31 | {{content-for "test-body-footer"}} 32 | 33 | 34 | -------------------------------------------------------------------------------- /tests/integration/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Duder-onomy/ember-resize-aware/5228409acb42e43301dfc9264896900ae1e0433e/tests/integration/.gitkeep -------------------------------------------------------------------------------- /tests/test-helper.js: -------------------------------------------------------------------------------- 1 | import Application from '../app'; 2 | import config from '../config/environment'; 3 | import { setApplication } from '@ember/test-helpers'; 4 | import { start } from 'ember-qunit'; 5 | 6 | setApplication(Application.create(config.APP)); 7 | 8 | start(); 9 | -------------------------------------------------------------------------------- /tests/unit/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Duder-onomy/ember-resize-aware/5228409acb42e43301dfc9264896900ae1e0433e/tests/unit/.gitkeep -------------------------------------------------------------------------------- /tests/unit/mixins/resize-aware-test.js: -------------------------------------------------------------------------------- 1 | import Component from '@ember/component'; 2 | import { set } from '@ember/object'; 3 | import ResizeAwareMixin from 'ember-resize-aware/mixins/resize-aware'; 4 | import hbs from 'htmlbars-inline-precompile'; 5 | import { render, settled } from '@ember/test-helpers'; 6 | import { module, test } from 'qunit'; 7 | import { setupRenderingTest } from 'ember-qunit'; 8 | 9 | module('Integration | Component | pretty color', function(hooks) { 10 | setupRenderingTest(hooks); 11 | 12 | hooks.beforeEach(function() { 13 | const testContext = this; 14 | 15 | this.owner.register('component:resize-aware-component', 16 | Component.extend(ResizeAwareMixin, { 17 | init(...args) { 18 | this._super(...args); 19 | testContext.componentInstance = this; 20 | } 21 | }) 22 | ); 23 | }); 24 | 25 | test('didResize hook is on the object', async function(assert) { 26 | await render(hbs`{{resize-aware-component}}`); 27 | let resizeAwareComponent = this.componentInstance; 28 | 29 | assert.ok(resizeAwareComponent.didResize, 'didResize hook is present on the subject'); 30 | assert.equal(typeof resizeAwareComponent.didResize, 'function', 'didResize hook is a function'); 31 | }); 32 | 33 | test('it fires "didResize" when the window is resized', async function(assert) { 34 | assert.expect(2); 35 | 36 | let didResizeCallCount = 0; 37 | 38 | this.didResize = function() { didResizeCallCount++; }; 39 | this.debounceRate = 0; 40 | 41 | await render(hbs`{{resize-aware-component didResize=didResize debounceRate=debounceRate}}`); 42 | let resizeAwareComponent = this.componentInstance; 43 | 44 | let evt = new window.Event('resize'); 45 | 46 | window.dispatchEvent(evt); 47 | 48 | await settled(); 49 | 50 | assert.equal(didResizeCallCount, 1, 'didResize called 1 time on event firing'); 51 | 52 | set(resizeAwareComponent, '_previousWidth', 0); 53 | 54 | window.dispatchEvent(evt); 55 | 56 | await settled(); 57 | 58 | assert.equal(didResizeCallCount, 2, 'didResize called another time on event firing again'); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /vendor/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Duder-onomy/ember-resize-aware/5228409acb42e43301dfc9264896900ae1e0433e/vendor/.gitkeep --------------------------------------------------------------------------------