ember-hiding-menu
Advanced tools
Comparing version 0.1.3 to 0.2.0
import Ember from 'ember'; | ||
import layout from '../templates/components/hiding-menu'; | ||
const {run, inject, $} = Ember; | ||
const { run, inject } = Ember; | ||
@@ -9,9 +9,11 @@ export default Ember.Component.extend({ | ||
hidingScroll: inject.service(), | ||
tagName: 'nav', | ||
classNames: ['hiding-menu'], | ||
throttleTime: 150, | ||
throttleTime: 30, | ||
tolerance: 0, | ||
topTolerance: 50, | ||
bottomTolerance: 20, | ||
bottomTolerance: 50, | ||
class: null, | ||
@@ -23,6 +25,9 @@ style: null, | ||
hidingScroll: inject.service(), | ||
didInsertElement() { | ||
this.setupScrollMenuToggle(); | ||
this.setMenuHeight(); | ||
this.setupScrollEventHandling(); | ||
this.bodyElement = this.get('hidingScroll.bodyElement'); | ||
this.configScrollContainerElement = this.get('hidingScroll.configScrollContainerElement'); | ||
}, | ||
@@ -34,58 +39,49 @@ | ||
hidingScroll.off('scrollingDown', this, this.onScrollDown); | ||
}, | ||
}, | ||
onScrollUp() { | ||
this.raf(() => this.showMenu()); | ||
if (!this.get('isDestroyed')) { | ||
this.raf(() => this.showMenu()); | ||
} | ||
}, | ||
onScrollDown(newScrollTop) { | ||
this.raf(() => this.hideMenu(newScrollTop)); | ||
if (!this.get('isDestroyed')) { | ||
this.raf(() => this.hideMenu(newScrollTop)); | ||
} | ||
}, | ||
setupScrollMenuToggle(){ | ||
let $el = $(this.element); | ||
let $menu = $el; | ||
let hidingScroll = this.get('hidingScroll'); | ||
this.set('_menuHeight', this.get('menuHeight') || $menu.outerHeight()); | ||
if(parseInt(this.get('throttleTime')) === 150){ | ||
hidingScroll.on('scrollingUp', this, this.onScrollUp); | ||
hidingScroll.on('scrollingDown', this, this.onScrollDown); | ||
} else { | ||
hidingScroll.on('scroll', () => { | ||
this.raf(() => { | ||
run.throttle(this, this.onScroll, this.get('throttleTime')); | ||
}); | ||
}); | ||
setMenuHeight() { | ||
if (!this.get('menuHeight')) { | ||
// if menuHeight is not passed from the outside | ||
this.set('menuHeight', this.element.offsetHeight || this.element.clientHeight); | ||
} | ||
}, | ||
setupScrollEventHandling(){ | ||
const hidingScroll = this.get('hidingScroll'); | ||
hidingScroll.on('scrollingUp', this, () => run.throttle(this, this.onScrollUp, this.get('throttleTime'))); | ||
hidingScroll.on('scrollingDown', this, newScrollTop => run.throttle(this, this.onScrollDown, newScrollTop, this.get('throttleTime'))); | ||
}, | ||
raf(cb){ | ||
let fn = window.requestAnimationFrame || window.setTimeout; | ||
fn(cb); | ||
}, | ||
onScroll(){ | ||
if(!this.get('isDestroyed')){ | ||
let newScrollTop = $('html').scrollTop() || $('body').scrollTop(); | ||
if(newScrollTop > this.get('bodyScrollTop')){ | ||
this.onScrollDown(newScrollTop); | ||
} else { | ||
this.onScrollUp(); | ||
} | ||
this.set('bodyScrollTop', newScrollTop); | ||
if ('requestAnimationFrame' in window) { | ||
window.requestAnimationFrame(run.bind(this, cb)); | ||
} else { | ||
run.next(this, cb); | ||
} | ||
}, | ||
getFixedScrollHeight() { | ||
const containerElement = this.configScrollContainerElement || this.bodyElement; | ||
return containerElement.scrollHeight - window.innerHeight; | ||
}, | ||
hideMenu(newScrollTop){ | ||
// check for Top Tollerance | ||
if(newScrollTop > (document.body.scrollHeight - window.innerHeight - this.get('bottomTolerance') - this.get('_menuHeight'))){ | ||
this.set('isHidden', false); | ||
} else if(!this.get('isHidden') && newScrollTop > this.get('_menuHeight') + this.get('topTolerance')){ | ||
this.set('isHidden', true); | ||
if (newScrollTop > (this.getFixedScrollHeight() - this.get('bottomTolerance') - this.get('menuHeight'))) { | ||
this.set('isHidden', false); | ||
} else if (!this.get('isHidden') && newScrollTop > this.get('menuHeight') + this.get('topTolerance')) { | ||
this.set('isHidden', true); | ||
} | ||
}, | ||
@@ -92,0 +88,0 @@ |
import Ember from 'ember'; | ||
const {$, run} = Ember; | ||
const { run } = Ember; | ||
export default Ember.Service.extend(Ember.Evented, { | ||
init(){ | ||
init() { | ||
this._super(...arguments); | ||
$(window).on('scroll.hiding-menu', () => { | ||
if (typeof FastBoot === 'undefined') { | ||
this.saveScrollingElements(); | ||
this._setScrollListener(); | ||
} | ||
}, | ||
_setScrollListener() { | ||
const scrollEventElement = this.configScrollContainerElement || window; | ||
//TODO passive true? | ||
this._scrollListener = this._scrollListener.bind(this); | ||
scrollEventElement.addEventListener('scroll', this._scrollListener, { passive: true }); | ||
}, | ||
_scrollListener() { | ||
run(() => { | ||
this.trigger('scroll'); | ||
// run.throttle(this, this._onScroll, 20); | ||
this._onScroll(); | ||
@@ -16,17 +29,36 @@ }); | ||
_onScroll(){ | ||
let newScrollTop = $('html').scrollTop() || $('body').scrollTop(); | ||
if(newScrollTop > this.get('bodyScrollTop')){ | ||
this.trigger('scrollingDown', newScrollTop); | ||
} else { | ||
this.trigger('scrollingUp', newScrollTop); | ||
saveScrollingElements() { | ||
const config = Ember.getOwner(this).resolveRegistration('config:environment'); | ||
this.configScrollContainerElement = document.querySelector(config.APP.scrollContainerElement); | ||
this.bodyElement = document.querySelector('body'); | ||
this.htmlElement = document.querySelector('html'); | ||
}, | ||
getScrollTop() { | ||
if (this.configScrollContainerElement) { | ||
return this.configScrollContainerElement.scrollTop; | ||
} | ||
this.set('bodyScrollTop', newScrollTop); | ||
return this.bodyElement.scrollTop || this.htmlElement.scrollTop; | ||
}, | ||
_onScroll() { | ||
if (!this.get('isDestroyed')) { | ||
let newScrollTop = this.getScrollTop(); | ||
if (newScrollTop > this.get('previousScrollTop')) { | ||
this.trigger('scrollingDown', newScrollTop); | ||
} else { | ||
this.trigger('scrollingUp', newScrollTop); | ||
} | ||
this.set('previousScrollTop', newScrollTop); | ||
} | ||
}, | ||
destroy() { | ||
this._super(...arguments); | ||
$(window).off('scroll.hiding-menu'); | ||
if (typeof FastBoot === 'undefined') { | ||
window.removeEventListener('scroll', this._scrollListener); | ||
} | ||
}, | ||
}); |
{ | ||
"name": "ember-hiding-menu", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"description": "Ember addon which adds functionality to toggle class on scroll down", | ||
@@ -21,24 +21,23 @@ "directories": { | ||
"devDependencies": { | ||
"broccoli-asset-rev": "^2.4.2", | ||
"ember-ajax": "^2.0.1", | ||
"ember-cli": "2.11.0", | ||
"ember-cli-app-version": "^1.0.0", | ||
"ember-cli-dependency-checker": "^1.2.0", | ||
"broccoli-asset-rev": "^2.5.0", | ||
"ember-cli": "2.14.0", | ||
"ember-cli-app-version": "^3.0.0", | ||
"ember-cli-dependency-checker": "^2.0.1", | ||
"ember-cli-eslint": "^4.1.0", | ||
"ember-cli-github-pages": "0.1.2", | ||
"ember-cli-inject-live-reload": "^1.4.0", | ||
"ember-cli-jshint": "^1.0.0", | ||
"ember-cli-qunit": "^2.0.0", | ||
"ember-cli-htmlbars-inline-precompile": "^0.4.0", | ||
"ember-cli-inject-live-reload": "^1.6.0", | ||
"ember-cli-qunit": "^4.0.0", | ||
"ember-cli-release": "^0.2.9", | ||
"ember-cli-sass": "5.5.0", | ||
"ember-cli-sri": "^2.1.0", | ||
"ember-cli-test-loader": "^1.1.0", | ||
"ember-cli-test-loader": "^2.1.0", | ||
"ember-cli-uglify": "^1.2.0", | ||
"ember-data": "^2.7.0", | ||
"ember-disable-prototype-extensions": "^1.1.0", | ||
"ember-composable-helpers": "2.0.3", | ||
"ember-disable-prototype-extensions": "^1.1.2", | ||
"ember-export-application-global": "^1.0.5", | ||
"ember-load-initializers": "^0.5.1", | ||
"ember-native-dom-event-dispatcher": "0.5.4", | ||
"ember-cli-htmlbars-inline-precompile": "^0.3.1", | ||
"ember-resolver": "^2.0.3", | ||
"loader.js": "^4.0.1" | ||
"ember-load-initializers": "^1.0.0", | ||
"ember-native-dom-event-dispatcher": "0.6.3", | ||
"ember-resolver": "^4.2.1", | ||
"loader.js": "^4.5.1" | ||
}, | ||
@@ -49,4 +48,4 @@ "keywords": [ | ||
"dependencies": { | ||
"ember-cli-htmlbars": "^1.0.3", | ||
"ember-cli-babel": "^5.1.6" | ||
"ember-cli-htmlbars": "^2.0.2", | ||
"ember-cli-babel": "^6.5.0" | ||
}, | ||
@@ -53,0 +52,0 @@ "ember-addon": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8457
21
14
147
+ Added@ampproject/remapping@2.3.0(transitive)
+ Added@babel/code-frame@7.26.2(transitive)
+ Added@babel/compat-data@7.26.2(transitive)
+ Added@babel/core@7.26.0(transitive)
+ Added@babel/generator@7.26.2(transitive)
+ Added@babel/helper-compilation-targets@7.25.9(transitive)
+ Added@babel/helper-module-imports@7.25.9(transitive)
+ Added@babel/helper-module-transforms@7.26.0(transitive)
+ Added@babel/helper-string-parser@7.25.9(transitive)
+ Added@babel/helper-validator-identifier@7.25.9(transitive)
+ Added@babel/helper-validator-option@7.25.9(transitive)
+ Added@babel/helpers@7.26.0(transitive)
+ Added@babel/parser@7.26.2(transitive)
+ Added@babel/template@7.25.9(transitive)
+ Added@babel/traverse@7.25.9(transitive)
+ Added@babel/types@7.26.0(transitive)
+ Added@jridgewell/gen-mapping@0.3.5(transitive)
+ Added@jridgewell/resolve-uri@3.1.2(transitive)
+ Added@jridgewell/set-array@1.2.1(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@jridgewell/trace-mapping@0.3.25(transitive)
+ Addedamd-name-resolver@1.2.0(transitive)
+ Addedbabel-code-frame@6.26.0(transitive)
+ Addedbabel-core@6.26.3(transitive)
+ Addedbabel-generator@6.26.1(transitive)
+ Addedbabel-helper-builder-binary-assignment-operator-visitor@6.24.1(transitive)
+ Addedbabel-helper-call-delegate@6.24.1(transitive)
+ Addedbabel-helper-define-map@6.26.0(transitive)
+ Addedbabel-helper-explode-assignable-expression@6.24.1(transitive)
+ Addedbabel-helper-function-name@6.24.1(transitive)
+ Addedbabel-helper-get-function-arity@6.24.1(transitive)
+ Addedbabel-helper-hoist-variables@6.24.1(transitive)
+ Addedbabel-helper-optimise-call-expression@6.24.1(transitive)
+ Addedbabel-helper-regex@6.26.0(transitive)
+ Addedbabel-helper-remap-async-to-generator@6.24.1(transitive)
+ Addedbabel-helper-replace-supers@6.24.1(transitive)
+ Addedbabel-helpers@6.24.1(transitive)
+ Addedbabel-messages@6.23.0(transitive)
+ Addedbabel-plugin-check-es2015-constants@6.22.0(transitive)
+ Addedbabel-plugin-debug-macros@0.2.0(transitive)
+ Addedbabel-plugin-ember-modules-api-polyfill@2.13.4(transitive)
+ Addedbabel-plugin-syntax-async-functions@6.13.0(transitive)
+ Addedbabel-plugin-syntax-exponentiation-operator@6.13.0(transitive)
+ Addedbabel-plugin-syntax-trailing-function-commas@6.22.0(transitive)
+ Addedbabel-plugin-transform-async-to-generator@6.24.1(transitive)
+ Addedbabel-plugin-transform-es2015-arrow-functions@6.22.0(transitive)
+ Addedbabel-plugin-transform-es2015-block-scoped-functions@6.22.0(transitive)
+ Addedbabel-plugin-transform-es2015-block-scoping@6.26.0(transitive)
+ Addedbabel-plugin-transform-es2015-classes@6.24.1(transitive)
+ Addedbabel-plugin-transform-es2015-computed-properties@6.24.1(transitive)
+ Addedbabel-plugin-transform-es2015-destructuring@6.23.0(transitive)
+ Addedbabel-plugin-transform-es2015-duplicate-keys@6.24.1(transitive)
+ Addedbabel-plugin-transform-es2015-for-of@6.23.0(transitive)
+ Addedbabel-plugin-transform-es2015-function-name@6.24.1(transitive)
+ Addedbabel-plugin-transform-es2015-literals@6.22.0(transitive)
+ Addedbabel-plugin-transform-es2015-modules-amd@6.24.1(transitive)
+ Addedbabel-plugin-transform-es2015-modules-commonjs@6.26.2(transitive)
+ Addedbabel-plugin-transform-es2015-modules-systemjs@6.24.1(transitive)
+ Addedbabel-plugin-transform-es2015-modules-umd@6.24.1(transitive)
+ Addedbabel-plugin-transform-es2015-object-super@6.24.1(transitive)
+ Addedbabel-plugin-transform-es2015-parameters@6.24.1(transitive)
+ Addedbabel-plugin-transform-es2015-shorthand-properties@6.24.1(transitive)
+ Addedbabel-plugin-transform-es2015-spread@6.22.0(transitive)
+ Addedbabel-plugin-transform-es2015-sticky-regex@6.24.1(transitive)
+ Addedbabel-plugin-transform-es2015-template-literals@6.22.0(transitive)
+ Addedbabel-plugin-transform-es2015-typeof-symbol@6.23.0(transitive)
+ Addedbabel-plugin-transform-es2015-unicode-regex@6.24.1(transitive)
+ Addedbabel-plugin-transform-exponentiation-operator@6.24.1(transitive)
+ Addedbabel-plugin-transform-regenerator@6.26.0(transitive)
+ Addedbabel-plugin-transform-strict-mode@6.24.1(transitive)
+ Addedbabel-polyfill@6.26.0(transitive)
+ Addedbabel-preset-env@1.7.0(transitive)
+ Addedbabel-register@6.26.0(transitive)
+ Addedbabel-runtime@6.26.0(transitive)
+ Addedbabel-template@6.26.0(transitive)
+ Addedbabel-traverse@6.26.0(transitive)
+ Addedbabel-types@6.26.0(transitive)
+ Addedbabylon@6.18.0(transitive)
+ Addedbroccoli-babel-transpiler@6.5.1(transitive)
+ Addedbroccoli-debug@0.6.5(transitive)
+ Addedbroccoli-funnel@2.0.2(transitive)
+ Addedbroccoli-merge-trees@2.0.1(transitive)
+ Addedbroccoli-source@1.1.0(transitive)
+ Addedbrowserslist@3.2.84.24.2(transitive)
+ Addedcaniuse-lite@1.0.30001683(transitive)
+ Addedconvert-source-map@2.0.0(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addeddetect-indent@4.0.0(transitive)
+ Addedelectron-to-chromium@1.5.64(transitive)
+ Addedember-cli-babel@6.18.0(transitive)
+ Addedember-cli-htmlbars@2.0.5(transitive)
+ Addedember-cli-version-checker@2.2.0(transitive)
+ Addedember-rfc176-data@0.3.18(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedgensync@1.0.0-beta.2(transitive)
+ Addedglobals@11.12.09.18.0(transitive)
+ Addedhome-or-tmp@2.0.0(transitive)
+ Addedinvariant@2.2.4(transitive)
+ Addedjs-tokens@3.0.24.0.0(transitive)
+ Addedjsesc@1.3.03.0.2(transitive)
+ Addedjson5@0.5.12.2.3(transitive)
+ Addedloose-envify@1.4.0(transitive)
+ Addedlru-cache@5.1.1(transitive)
+ Addedmerge-trees@1.0.1(transitive)
+ Addedms@2.1.3(transitive)
+ Addednode-releases@2.0.18(transitive)
+ Addedos-homedir@1.0.2(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedregenerator-runtime@0.10.50.11.1(transitive)
+ Addedregenerator-transform@0.10.1(transitive)
+ Addedregexpu-core@2.0.0(transitive)
+ Addedrepeating@2.0.1(transitive)
+ Addedrsvp@4.8.5(transitive)
+ Addedsemver@6.3.1(transitive)
+ Addedsource-map-support@0.4.18(transitive)
+ Addedstrip-bom@3.0.0(transitive)
+ Addedtree-sync@1.4.0(transitive)
+ Addedupdate-browserslist-db@1.1.1(transitive)
+ Addedyallist@3.1.1(transitive)
- Removedacorn@5.7.4(transitive)
- Removedalign-text@0.1.4(transitive)
- Removedalter@0.2.0(transitive)
- Removedamdefine@1.0.1(transitive)
- Removedast-traverse@0.1.1(transitive)
- Removedast-types@0.8.120.9.6(transitive)
- Removedbabel-core@5.8.38(transitive)
- Removedbabel-plugin-constant-folding@1.0.1(transitive)
- Removedbabel-plugin-dead-code-elimination@1.0.2(transitive)
- Removedbabel-plugin-eval@1.0.1(transitive)
- Removedbabel-plugin-inline-environment-variables@1.0.1(transitive)
- Removedbabel-plugin-jscript@1.0.4(transitive)
- Removedbabel-plugin-member-expression-literals@1.0.1(transitive)
- Removedbabel-plugin-property-literals@1.0.1(transitive)
- Removedbabel-plugin-proto-to-assign@1.0.4(transitive)
- Removedbabel-plugin-react-constant-elements@1.0.3(transitive)
- Removedbabel-plugin-react-display-name@1.0.3(transitive)
- Removedbabel-plugin-remove-console@1.0.1(transitive)
- Removedbabel-plugin-remove-debugger@1.0.1(transitive)
- Removedbabel-plugin-runtime@1.0.7(transitive)
- Removedbabel-plugin-undeclared-variables-check@1.0.2(transitive)
- Removedbabel-plugin-undefined-to-void@1.1.6(transitive)
- Removedbabylon@5.8.38(transitive)
- Removedbluebird@2.11.0(transitive)
- Removedbreakable@1.0.0(transitive)
- Removedbroccoli-babel-transpiler@5.7.4(transitive)
- Removedbroccoli-funnel@1.2.0(transitive)
- Removedbroccoli-merge-trees@1.2.4(transitive)
- Removedcamelcase@1.2.1(transitive)
- Removedcenter-align@0.1.3(transitive)
- Removedcliui@2.1.0(transitive)
- Removedclone@0.2.0(transitive)
- Removedcommander@2.20.3(transitive)
- Removedcommoner@0.10.8(transitive)
- Removedcore-js@1.2.7(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removeddefined@1.0.1(transitive)
- Removeddefs@1.1.1(transitive)
- Removeddetect-indent@3.0.1(transitive)
- Removeddetective@4.7.1(transitive)
- Removedember-cli-babel@5.2.8(transitive)
- Removedember-cli-htmlbars@1.3.5(transitive)
- Removedember-cli-version-checker@1.3.1(transitive)
- Removedesprima@2.7.33.1.3(transitive)
- Removedesprima-fb@15001.1001.0-dev-harmony-fb(transitive)
- Removedexists-sync@0.0.4(transitive)
- Removedfs-readdir-recursive@0.1.2(transitive)
- Removedget-stdin@4.0.1(transitive)
- Removedglobals@6.4.1(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhome-or-tmp@1.0.0(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedinvert-kv@1.0.0(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedis-integer@1.0.7(transitive)
- Removedis-utf8@0.2.1(transitive)
- Removedjs-tokens@1.0.1(transitive)
- Removedjson5@0.4.0(transitive)
- Removedkind-of@3.2.2(transitive)
- Removedlazy-cache@1.0.4(transitive)
- Removedlcid@1.0.0(transitive)
- Removedleven@1.0.2(transitive)
- Removedlodash@3.10.1(transitive)
- Removedlongest@1.0.1(transitive)
- Removedminimatch@2.0.10(transitive)
- Removedos-locale@1.4.0(transitive)
- Removedoutput-file-sync@1.1.2(transitive)
- Removedpath-exists@1.0.0(transitive)
- Removedq@1.5.1(transitive)
- Removedrecast@0.10.330.11.23(transitive)
- Removedregenerator@0.8.40(transitive)
- Removedregexpu@1.3.0(transitive)
- Removedrepeat-string@1.6.1(transitive)
- Removedrepeating@1.1.3(transitive)
- Removedright-align@0.1.3(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedshebang-regex@1.0.0(transitive)
- Removedsimple-fmt@0.1.0(transitive)
- Removedsimple-is@0.2.0(transitive)
- Removedsource-map@0.1.32(transitive)
- Removedsource-map-support@0.2.10(transitive)
- Removedstable@0.1.8(transitive)
- Removedstringmap@0.2.2(transitive)
- Removedstringset@0.2.1(transitive)
- Removedstrip-bom@2.0.0(transitive)
- Removedthrough@2.3.8(transitive)
- Removedtry-resolve@1.0.1(transitive)
- Removedtryor@0.1.2(transitive)
- Removeduser-home@1.1.1(transitive)
- Removedwindow-size@0.1.4(transitive)
- Removedwordwrap@0.0.2(transitive)
- Removedy18n@3.2.2(transitive)
- Removedyargs@3.27.0(transitive)
Updatedember-cli-babel@^6.5.0
Updatedember-cli-htmlbars@^2.0.2