DanWebb
5/1/2014 - 5:56 PM

Simple notification object

Simple notification object

var notification = {
	element: $('#notification'),
	timeout: null,
	show: function(type, message) {
		'use strict';

		// reset the current timer
		clearTimeout(this.timeout);

		this.element
		// remove any classes already added
		.removeClass()
		// set background color
		.addClass(type)
		// add message text
		.html(message)
		// animate and display
		.slideDown()
		// hide notification if clicked
		.click(function() {
			notification.hide();
		});

		// hide automatically after 5 seconds
		this.timeout = setTimeout(function(){
			notification.hide();
		},5000);
	},
	hide: function() {
		'use strict';

		// reset the current timer
		clearTimeout(this.timeout);

		// animate and hide the notification
		this.element.slideUp();
	}
};