npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-img-manager

v0.0.12

Published

An `<img>` manager for Ember with cache, batch load and error handling.

Downloads

23

Readme

ember-img-manager Build Status

This Ember addon lets you control how images are loaded (batch size, delay, ...), setup events for success or error, re-use DOM img nodes by cloning them so that external images with no cache are cached, and use different image sources while an image is loading or becomes error.

The batchSize is particularly helpful when dealing with Google contacts library for example, where Google limits each client to 10 requests per second for contact images.

You can also use this addon to avoid loading any external images on dev environment for example if you are used to work disconnected from internet.

By default images are lazy loaded, which means that if they have not yet been loaded, the load will trigger only when the image will appear in the viewport.

Example configuration

// config/environment.js

// all settings are optionals
ENV.imgManager = {
  // how many times to try to load an image (default: 1)
  maxTries: 3,
  // wait 10 milliseconds before trying to load more images (default: 1)
  delay: 10,
  // how many images to try to load in a raw (if 0 then it'll load all at once) (default: 0)
  batchSize: 0,
  // should we start loading a source image only when it appear in the viewport (default: true)
  lazyLoad: false,
  // the image to use while loading the real image (default: null)
  loadingSrc: 'assets/loading-img.png',
  // the image to use when an image has failed to load (default: null)
  errorSrc: 'assets/error-img.png',
  // in the `rules`, you can define specific settings for each image depending on its `src` (default: null)
  rules: [
    // for use with google contacts photos for example:
    {match: 'www.google.com/m8/feeds/photos', delay: 1000, batchSize: 10},
    // do not try to load any external image (for dev env for example):
    {match: /^https?:\/\//, maxTries: 0}
  ],
  // ------ global only settings (show with their default values) -----
  // css class to use when loading an image
  loadingClass: 'loading',
  // css class to use when the load was successful
  successClass: 'success',
  // css class to use when the load has failed
  errorClass: 'error'
};

Installation

  • npm install --save-dev ember-img-manager
  • or, with the latest ember-cli, ember install:addon ember-img-manager

Usage:

  • Simply replace any <img ...> tag that you want to be handled by the manager with the equivalent {{img-wrap ...}} handlebars tag. All HTML attributes are supported.

    {{!-- old tag was <img {{bind-attr src=photoUrl}} alt="Landscape"> --}}
    {{img-wrap src=photoUrl alt="Landscape"}}

    There are a few properties you can use:

    • loadingClass, successClass, errorClass: the css classes to use for each status (using the default ones from config if they are not set)
    • isLoading, isSuccess, isError: whether the image is in one of those status
    • progress: the value representing the percentage of the image which has been loaded already
    • load-error: name of an Ember action to trigger when the image fails to load
    • load-success: name of an Ember action to trigger when the image loads successfully
    • lazyLoad: whether to directly load the image or wait until it appears in the viewport (will override anything set in the rules)
  • One thing to note is that the <img> is then wrapped inside a <span> which has display: inline-block. It should not break your design in most of the cases.

  • This <span> tag has then a img-wrap class, plus a loading, error or success class depending on the state of the load.

  • Any other class defined in the hash of the handlebars tag is defined on the <span> element instead of the <img> itself.

Author

Huafu Gandon @huafu_g - my website


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