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

ampersand-auto-closing-view

v1.0.3

Published

A view that closes itself after a certain period of time.

Downloads

4

Readme

ampersand-auto-closing-view Build Status NPM version Dependency Status

A view that closes itself after a certain period of time.

Install via npm:

npm install ampersand-auto-closing-view --save

Example

A simple example might be to show a prompt each time the user moves his/her mouse. It could look like this:

var View   = require('ampersand-view');
var ACView = require('ampersand-auto-closing-view');

// Extend the view so that we can have custom HTML instead
var MyACView = ACView.extend({
    template: '<h1>Hello, world!</h1>'
});

var MyView = View.extend({
    template: '<div class="container"><div class="prompt"></div></div>',
    events: {
        'mousemove': 'reset'
    },
    reset: function() {
        this.acView.trigger('reset');
    },
    render: function() {
        this.renderWithTemplate();
        this.acView = new MyACView();
        this.renderSubview(this.acView, '.prompt');
    }
});

var myView = new MyView({ el: document.body });
myView.render();

We can go a little further with this, and keep the view persisted whilst the user has his/her mouse over our custom view:

var MyACView = ACView.extend({
    template: '<h1>Hello, world!</h1>'
    events: {
        'mousemove': 'onMouseMove',
        'mouseout' : 'onMouseOut'
    },
    onMouseMove: function(e) {
        e.stopPropagation();
        this.trigger('stay');
    },
    onMouseOut: function(e) {
        e.stopPropagation();
        this.trigger('reset');
    }
});

Note that this module leaves the hide/show implementation up to you - at its most simple, you can define these two classes in your CSS file:

.hidden {
    display: none;
}

.active {
    display: block;
}

Or, make it look a little smoother by defining a transition between the two states:

.prompt {
    position: absolute;
    left: 0;
    top: 0;
    width: 200px;
    height: 100%;
    background: #222;
    transition: transform .2s ease;
}

.prompt.hidden {
    transform: translateX(-200px);
}

API

ampersand-auto-closing-view is itself an ampersand-view so you can extend it to add additional functionality. This is recommended as this module provides only a skeleton view which you can then fill with your own content.

new ACView(options)

Construct a new auto closing view with an options object. The following options are supported:

duration

type: Number
default: 4000

The duration, in milliseconds, that the element should be shown for.

activeClass

type: String
default: active

The class name to use whilst the element is active.

hiddenClass

type: String
default: hidden

The class name to use whilst the element is hidden.

ACView.hide()

"Hides" the view. Note that you should supplement this with your own CSS; this is so you can animate the view in and out using CSS transitions. Does not start the timer.

ACView.show()

"Shows" the view. Note that you should supplement this with your own CSS; this is so you can animate the view in and out using CSS transitions. Does not start the timer.

ACView.reset()

Reset the timer for the view, keeping it on screen for the duration that was defined (default is 4 seconds). Note that you can also do ACView.trigger('reset').

ACView.stay()

Convenience for clearing the timer and showing the view with a single method call. Note that you can also do ACView.trigger('stay').

ACView.clear()

Clears the timeout for the view, so that you can (temporarily) override the show/hide behaviour. For example, when you mouse over the view, it could stay in place until you mouse out of it again.

Contributing

Pull requests are welcome. If you add functionality, then please add unit tests to cover it.

License

MIT © Ben Briggs