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

backbone.tango

v0.3.0

Published

Notification library for Backbone.js

Downloads

46

Readme

Backbone.Tango

Notification library for Backbone.js

bower install backbone.tango --save
npm install backbone.tango --save

notifier.info('The more you know...');

notifier.warning('Beware!!!');

notifier.error('Ooops!');


<br/>
An options object can be provided as a second argument.

<br/>
```javascript
notifier.success('Success!!!', {
    position: 'bottom-left',
    timeout: 3000
});

notifier.success('Going left');



<br/>
**View options**

 * position: Determines the place where notifications are shown. Values accepted: `top-right`, `top-left`, `bottom-right`, `bottom-left`, `top-center`, `bottom-center`, `top-full-width`, `bottom-full-width` (default: `top-right`).
 * timeout: The amount of time (in milliseconds) a notification remains visible (default: `5000`).
 * newestOnTop: Determines if new notifications are rendered on top of old ones (default: true).
 * type: Notification type. Values: `info`, `success`, `error`, `warning`, `loader` (default: `undefined`). 
 * render: Determines if the notification is renderer automatically after creation (default: `true`).
 * clearAll: When true, all notifications are removed except for the current one (Default: `false`).
 * clearContainer: When true, all notifications rendered in the same container are hided (Default: `false`).
 * viewClass: The default view class (Default: `Backbone.Tango.View`).
 

<br/>
**Style options**

 * cssClass: A CSS class used for all notification views. When a notification defines a `type` it will also be used to generate an additional class ("tango-success", "tango-warning", etc) (default: `tango`).
 * showMethod: The jQuery method used to show the current view (default: `fadeIn`).
 * showDuration: The amount of time (in milliseconds) for the specified show animation (default: 250).
 * showEasing: The easing method used for the specified show animation (default: `swing`).
 * hideMethod: The jQuery method used to hide the current view (default: `fadeOut`).
 * hideDuration: The amount of time (in milliseconds) for the specified hide animation (default: `850`).
 * hideEasing: The easing method used for the specified hide animation (default: `swing`).

<br/>
**Events options**

 * tapToDismiss: Determines if a view is removed after a *click* event (default: *true*).
 * extendedTimeout: The time in milliseconds in which a notification remains visible after a hover event (default: 1000).
 * onShown: A function called when a view is shown (default: *undefined*).
 * onHidden: A function called when a view is hdden (default: *undefined*).

<br/>
**Container options**

Containers are elements that wrap one or more notificacions in order to be displayed in the requested position. When a notification is removed from screen it also checks if the current container has any childs left. Empty containers are removed as well.

 * target: The element where all notification containers are appended to (default: `body`).
 * containerBaseId: All containers are generated using and id that combines this option and the position where is rendered (default: `tango-container`).
 * containerClass: A CSS class used for all containers (default: `tango-container`). Containers also include an additional CSS class associated with the position.

<br/>
**Overlay options**

 * overlay: When true, an overlay is appended to the document before showing the notification (Default: `false`).
 * overlayClass: The CSS class used by the overlay (Default `tango-overlay`).

<br/>
**Template options**

 * template: The function used to generate a notification view (default: `undefined`, when no template is found then a default one is used).
 * templateFn: A function that receives a list of options and returns a template function. It has priority over the `template` option (default: `undefined`).
 * includeDefaultVars: When true, additional values like `nid` (notification id) and `cssClass` are added to the template arguments (Default: `true`).
 * templateVars: Additional vars that are provided to the template (Default: `null`).

<br/>
###Using templates

<br/>
This example illustrates how to use a default notification template using Undercore.js. We start by adding the following snippet to our page.

<br/>
```html
<script type="text/template" id="notifier-tpl">
    <div class="tango">
        <h5><%=title%></h5>
        <p><%=message%></p>
    </div>
</script>

var notifier = new Notifier({ template: _.template($('#notifier-tpl').html()) });


<br/>
This template receives a `title` and a `message` argument. We need to provide them using an object.

<br/>
```javascript
notifier.success({
    title: 'Hello',
    message: 'This is my custom template'
});

notifier.warning('Stop right there criminal scum!', { onShown: function(data, options) { console.log('Message "' + data.message + '" was showed.'); },

onHidden: function(data, options) {
    console.log('Notification was showed for about ' + (options.timeout / 1000) + ' seconds.');
},

timeout: 7000

});


<br/>
We can also bind a callback to a view event just like any regular *Backbone* view. During its lifetime, a `Tango.View` instance triggers a `shown` and a `hidden` event. Any callback triggered by the `shown` event is called before the `onShown` callback. Same goes for the `hidden` event handler and the `onHidden` callback.

<br/>
```javascript
var notifier = new Backbone.Tango.Notifier();
var view = notifier.info("The princess is in another castle");

// Bind a callback to the 'shown' event
view.on('shown', function(view, data, options) {
    console.log('Showing view "' + view.cid + '"');
});

// Bind a callback to the 'hidden' event
view.on('hidden', function(view, data, options) {
    console.log('Removing view "' + view.cid + '"');
});

// CloseableNotification class var CloseableNotification = View.extend({ events: { "click .close-button": "close" },

close: function(e) {
    e.stopPropagation();
    this.hide(true);
}

}, { defaults: { template: _.template($('#closeable-tpl').html()),

    tapToDismiss: false,
    
    timeout: 0,
    
    extendedTimeout: 0
}

});


<br/>
Now we create a new notifier instance using this class as the argument. The notifier instance will then import the configuration from the `defaults` property.

<br/>
```javascript
var Notifier = Backbone.Tango.Notifier;

// Import defaults from CloseableNotification
var notifier = new Notifier(CloseableNotification);

notifier.info({
    title: 'Welcome',
    message: 'How are you today?'
});

var view = notifier.make(CloseableNotification, { title: 'Welcome', message: 'How are you today?' });


<br/>
###Loaders

<br/>
Loaders are a special type of notification that are generated using the `loader` method. By default they include a small css animation just before the text.

<br/>
```javascript
var notifier = new Backbone.Tango.Notifier();
notifier.loader('Loading...');

// Show loader for 4 seconds setTimeout(function () { view.hide(); }, 4000);


<br/>
###License

This library is distributed under the terms of the MIT license.