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-autodisable

v0.2.2

Published

Angular directive that extends ngClick behaviour allowing it to automatically disable target element if the handler returns a promise

Downloads

34

Readme

angular-autodisable Build Status

An extension to angular ng-click directive that automatically sets the element to disabled if the handler would return a promise.

Requirements


  1. angular.js version >1.2+
  2. following es5 functions:
    1. bind
    2. map
    3. forEach
    4. indexOf

Usage


Include ngAutodisable as dependency

  angular.module('MyApp', [ 'ngAutodisable', ... ]);

If that's done then just follow those simple steps:

  1. just attach ng-autodisable directive to the element which happens to have ng-click directive OR a form that has the ng-submit directive.
  2. ???
  3. profit!

On an element

  <button ng-click="doSomething()" ng-autodisable>Do something</button>
  
  <a ng-click="doSomething()" ng-autodisable>Do something</a>

On a form

  <form ng-submit="doSomething()" ng-autodisable> 
    ...
    <button type="submit">Submit</button> 
  </form>

The button with type submit within the form will be disabled.

Loading class

You can optionally add a list of classes which will be added to the element while this is disabled. This is useful to add a spinner or something similar.

  <button ng-click="doSomething()" 
          ng-autodisable-class="class1 class2" 
          ng-autodisable>
    Do something
  </button>
  
  <form ng-submit="doSomething()" 
        ng-autodisable-class="class1 class2"
        ng-autodisable> 
    ...
    <button type="submit">Submit</button> 
  </form>

The button with type submit within the form will get the class.

Demo


A quick demo is available at jsfiddle

How it works


When ngClick and ngAutodisable are on the same element then ngAutodisable overwrites the handler for click event. The default ngClick action is recreated (and passes all the angular specs).

If the click handlers result happens to be a promise ($http or $q) then the element attribute disabled will be set as true. If the promise fulfills then the element disabled attribute will be removed.

This also works with multiple click handlers, given that click handlers are separated by ; as such:

  <button ng-click="doSomething();doSomethingElse()" ng-autodisable>Do something</button>

If there are multiple click handlers then the element disabled style will be removed after the last promise resolves.

Note


Throws an exception ngAutodisable requires ngClick attribute in order to work if ngAutodisable is on an element without ngClick.

Devel


  npm install
  bower install
  grunt test
  grunt build

License


MIT