New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ember-spaniel

Package Overview
Dependencies
Maintainers
6
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-spaniel

Ember addon wrapping spaniel and providing viewport and requestAnimationFrame utilities

  • 0.3.8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12
decreased by-50%
Maintainers
6
Weekly downloads
 
Created
Source

ember-spaniel Build Status npm version

Ember addon wrapping spaniel, a viewport tracking library, IntersectionObserver polyfill, and requestAnimationFrame task utility.

Including this addon will add Spaniel to your application, available for direct use in the app.

import spaniel from 'spaniel';

The rest of the API is contained in a service.

viewport service API

The viewport service will look for a defaultRootMargin object property on the application config. If not found, will default to 0, 0, 0, 0.

// environment.js
module.exports = {
  ...
  defaultRootMargin: {
    top: 100,
    bottom: 200
  }
}
onInViewportOnce(el, callback, { context, rootMargin, ratio }) => Function

Register a callback that will be called when the provided element first enters the viewport. Will get called on the next requestAnimationFrame if the element is already in the viewport. Returns a function that, when called, will cancel and clear the callback.

export default Ember.Component.extend({
  viewport: Ember.inject.service(),
  didInsertElement() {
    let viewport = this.get('viewport');
    let el = this.get('element');
    this.clearViewportCallback = viewport.onInViewportOnce(el, () => {
      console.log('I am in the viewport');
    });
  },
  willDestroyElement() {
    this._super(...arguments);
    this.clearViewportCallback();
  }
});
isInViewport(el, { ratio, rootMargin } = {}) => Promise

Returns a promise that resolves if the element is in the viewport, otherwise rejects.

export default Ember.Component.extend({
  viewport: Ember.inject.service(),
  didInsertElement() {
    let viewport = this.get('viewport');
    let el = this.get('element');
    viewport.isInViewport(el).then(() => {
      console.log('In the viewport');
    }, () => {
      console.log('Not in the viewport');
    });
  }
});
getWatcher()

The service has a Watcher instance available for direct use.

export default Ember.Component.extend({
  viewport: Ember.inject.service(),
  didInsertElement() {
    let watcher = this.get('viewport').getWatcher();
    let el = this.get('element');
    watcher.watch(el, (e) => {
      console.log(`${e} happened`);
    });
  }
});

Requirements

Ember 2.x.x is required. Tests are only run against latest LTS and latest release.

Installation

  • git clone https://github.com/asakusuma/ember-spaniel.git this repository
  • cd ember-spaniel
  • npm install
  • bower install

Linting

  • npm run lint:js
  • npm run lint:js -- --fix

Running

Running Tests

  • npm test (Runs ember try:each to test your addon against multiple Ember versions)
  • ember test – Runs the test suite on the current Ember version
  • ember test --server – Runs the test suite in "watch mode"

Building

  • ember build

For more information on using ember-cli, visit http://ember-cli.com/.

Keywords

FAQs

Package last updated on 04 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc