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

angular-images-loaded-jtt

v1.0.0

Published

Image load detector

Downloads

5

Readme

angular-images-loaded

####Image load detector with progress events

  • Directive can be nested now (NEW)
  • Detects images load for all images inside an element and broadcasts angular progress events
  • Works with ng-repeat.
  • Can be used on different elements
  • Need not worry about asynchronous image elements insertion into DOM

#####REQUIREMENTS

  • Angularjs 1.2+ only

#####INSTALLATION

  • Download angular-images-loaded-directive.min.js and include it with your JS files.
  • Include module jtt_imagesLoaded in your main app module.

#####USAGE

  • Put directive data-images-loaded on an element containing images.

    Eg.

    <div data-images-loaded>
    <div data-ng-repeat="image in images">
    		<img ng-src="http://lorempixel.com/{{image.src}}">
    	  <div>Foo Bar</div>
    </div>
    </div>
  • You can nest the directive

    Eg.

    <div data-images-loaded>
    ..................
    	
    <div data-images-loaded>
    	<div data-ng-repeat="image in images1">
    			<img ng-src="http://lorempixel.com/{{image.src}}">
    		  <div>Foo Bar</div>
    	</div>
    </div>
      
    <div data-images-loaded>
    	<div data-ng-repeat="image in images2">
    			<img ng-src="http://lorempixel.com/{{image.src}}">
    		  <div>Foo Bar</div>
    	</div>
    </div>
    </div>

    That's it!

#####EVENTS(Always available)

  • imagesLoaded.SUCCESS - All images have been successfully loaded

  • imagesLoaded.FAIL - All images have been loaded with atleast 1 failed image

  • imagesLoaded.ALWAYS - All images are done, whether successfully loaded or failed to load. This event is always broadcasted

    Subscribe to these events in your controller as shown below

    $scope.$on('imagesLoaded.SUCCESS', function() {
      console.log('ALL LOADED');
    });
    
    $scope.$on('imagesLoaded.FAIL', function() {
      console.log('ALL LOADED WITH ATLEAST ONE FAILED');
    });
    
     $scope.$on('imagesLoaded.ALWAYS', function() {
      console.log('ALL DONE ALWAYS');        
    });

#####PROGRESS EVENTS

  • imagesLoaded.QUARTER - One fourth of total images have been loaded/failed

  • imagesLoaded.HALF - Half of total images have been loaded/failed

  • imagesLoaded.THREEQUARTERS - Three fourth of total images have been loaded/failed

  • imagesLoaded.FULL - All images have been loaded/failed

    Main event is imagesLoaded.PROGRESS, other events are received in the callback via progress.status

    Subscribe to these progress events in your controller as shown below

    $scope.$on('imagesLoaded.PROGRESS', function($event, progress) {
      console.log(progress);
      switch(progress.status) {
          case 'imagesLoaded.QUARTER':
              $scope.progress = 25;
              break;
          case 'imagesLoaded.HALF':
              $scope.progress = 50;
              break;
          case 'imagesLoaded.THREEQUARTERS':
              $scope.progress = 75;
              break;
          case 'imagesLoaded.FULL':
              $scope.progress = 100;
              break;
      }
    });

#####Note :-

  1. To listen to progress events, use attribute data-use-progress-events as shown below -
<div data-images-loaded data-use-progress-events="yes">
	<div data-ng-repeat="image in images">
			<img ng-src="http://lorempixel.com/{{image.src}}"/>
		  <div>Foo Bar</div>
	</div>
</div>
  • data-use-progress-events="yes" to listen to progress events

  • data-use-progress-events="no" to skip progress events and just listen to main events

    This approach is taken to minimise $digest cycles in case you wish to skip progress events, since all angular-specific changes take place in the $digest cycle. That's why, I have kept progress events to a minimum, otherwise N images load will cause N $digest cycles to notify the subscriber, which can hamper performance.

  1. Use $event.stopPropagation() in your controller when using progress events and nesting the directive, otherwise you'll receive same notification multiple times.
 $scope.$on('imagesLoaded.PROGRESS', function($event, progress) {
   console.log(progress);
   $event.stopPropagation();
   
   switch(progress.status) {
       case 'imagesLoaded.QUARTER':
           $scope.progress = 25;
           break;
       case 'imagesLoaded.HALF':
           $scope.progress = 50;
           break;
       case 'imagesLoaded.THREEQUARTERS':
           $scope.progress = 75;
           break;
       case 'imagesLoaded.FULL':
           $scope.progress = 100;
           break;
   }
 });