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

ng-resize

v2.0.0

Published

Manage resize events in Angular applications

Downloads

2,747

Readme

ngResize

Angular module for managing resize events in your applications. Some of goals of this project worth noting include:

  • Lightweight, flexible and easy to use
  • Bind resize event handler one time for entire app
  • Throttle window resize events

Usage

ngResize is composed of a provider, a service, and a directive. The service can be injected into other modules and used to programatically bind resize events in angular applications. The provider can be injected into your app's configuration phase to set things like throttle time.

Set ngResize as a dependency in your module:

var app = angular.module('YourApp', ['ngResize']);

Provider

app.config(function(resizeProvider) {

    // set throttle time
    resizeProvider.throttle = 100;

    // don't bind resize events on service initialization
    resizeProvider.initBind = false;

});

Properties

name | description ---- | ---- throttle | Throttle time for resize events, default is 32 (30 fps) initBind | Boolean to determine if we should bind resize event when service object is created, default is true

Service

app.directive('someDirective', function(resize) {
    return {
        controller: function($scope) {

        },
        link: function($scope, $elem, $attr, ctrl) {

            // on resize event, set dimensions
            // $event, and data arguments are available
            $scope.$on('resize', function($event, data) {
                $scope.width = data.width;
                $scope.height = data.height;
            });

        }
    };
});

The event listener callback accepts two arguments: $event, and data

Methods

name | description ---- | ---- getThrottle() | Returns current throttle time setThrottle(integer) | Sets current throttle time, applies to entire app trigger([$scope]) | $broadcast a resize event from specified $scope or $rootScope bind() | Bind resize event to $window, only useful if initBind = false or if event has been previously unbound unbind() | Unbinds resize even from $window

Directive

Something worth noting is that when the resize event is triggered, $timeout is used to debounce the expression to the end of the current $digest. This is to try and ensure that any costly calculations you might be doing won't interfere with the current $digest cycle. This approach was taken because resize events are often not critical functionality points, but necessary to maintain ui/ux stability. The goal is to provide efficient, useful access to resize events without crippling the ui.

<div ng-resize="setDimensions($event, data)"></div>

Two arguments are available to directive expressions: $event, and data

Roadmap

A few things I'm interested in pursuing with this project in the future are:

  • option to disable $rootScope $broadcast
  • ability to subscribe and unsubscribe $scopes from resize $broadcast
  • ability to bind resize events to $elements
  • manage detaching of $scopes and $elements when $destroyed
  • set unique throttle time for each $scope or $element