123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- /***********************************************************************************
- * Add Array.indexOf *
- ***********************************************************************************/
- (function ()
- {
- if (typeof Array.prototype.indexOf !== 'function')
- {
- Array.prototype.indexOf = function(searchElement, fromIndex)
- {
- for (var i = (fromIndex || 0), j = this.length; i < j; i += 1)
- {
- if ((searchElement === undefined) || (searchElement === null))
- {
- if (this[i] === searchElement)
- {
- return i;
- }
- }
- else if (this[i] === searchElement)
- {
- return i;
- }
- }
- return -1;
- };
- }
- })();
- /**********************************************************************************/
- (function ($,undefined)
- {
- var toasting =
- {
- gettoaster : function ()
- {
- var toaster = $('#' + settings.toaster.id);
- if(toaster.length < 1)
- {
- toaster = $(settings.toaster.template).attr('id', settings.toaster.id).css(settings.toaster.css).addClass(settings.toaster['class']);
- if ((settings.stylesheet) && (!$("link[href=" + settings.stylesheet + "]").length))
- {
- $('head').appendTo('<link rel="stylesheet" href="' + settings.stylesheet + '">');
- }
- $(settings.toaster.container).append(toaster);
- }
- return toaster;
- },
- notify : function (title, message, priority)
- {
- var $toaster = this.gettoaster();
- var $toast = $(settings.toast.template.replace('%priority%', priority)).hide().css(settings.toast.css).addClass(settings.toast['class']);
- $('.title', $toast).css(settings.toast.csst).html(title);
- $('.message', $toast).css(settings.toast.cssm).html(message);
- if ((settings.debug) && (window.console))
- {
- console.log(toast);
- }
- $toaster.append(settings.toast.display($toast));
- if (settings.donotdismiss.indexOf(priority) === -1)
- {
- var timeout = (typeof settings.timeout === 'number') ? settings.timeout : ((typeof settings.timeout === 'object') && (priority in settings.timeout)) ? settings.timeout[priority] : 1500;
- setTimeout(function()
- {
- settings.toast.remove($toast, function()
- {
- $toast.remove();
- });
- }, timeout);
- }
- }
- };
- var defaults =
- {
- 'toaster' :
- {
- 'id' : 'toaster',
- 'container' : 'body',
- 'template' : '<div></div>',
- 'class' : 'toaster',
- 'css' :
- {
- 'position' : 'fixed',
- 'top' : '10px',
- 'right' : '10px',
- 'width' : '400px',
- 'zIndex' : 50000
- }
- },
- 'toast' :
- {
- 'template' :
- '<div class="alert alert-%priority% alert-dismissible" role="alert">' +
- '<button type="button" class="close" data-dismiss="alert">' +
- '<span aria-hidden="true">×</span>' +
- '<span class="sr-only">Close</span>' +
- '</button>' +
- '<span class="title"></span>: <span class="message"></span>' +
- '</div>',
- 'defaults' :
- {
- 'title' : 'Notice',
- 'priority' : 'success'
- },
- 'css' : {},
- 'cssm' : {},
- 'csst' : { 'fontWeight' : 'bold' },
- 'fade' : 'slow',
- 'display' : function ($toast)
- {
- return $toast.fadeIn(settings.toast.fade);
- },
- 'remove' : function ($toast, callback)
- {
- return $toast.animate(
- {
- opacity : '0',
- padding : '0px',
- margin : '0px',
- height : '0px'
- },
- {
- duration : settings.toast.fade,
- complete : callback
- }
- );
- }
- },
- 'debug' : false,
- 'timeout' : 1500,
- 'stylesheet' : null,
- 'donotdismiss' : []
- };
- var settings = {};
- $.extend(settings, defaults);
- $.toaster = function (options)
- {
- if (typeof options === 'object')
- {
- if ('settings' in options)
- {
- settings = $.extend(true, settings, options.settings);
- }
- }
- else
- {
- var values = Array.prototype.slice.call(arguments, 0);
- var labels = ['message', 'title', 'priority'];
- options = {};
- for (var i = 0, l = values.length; i < l; i += 1)
- {
- options[labels[i]] = values[i];
- }
- }
- var title = (('title' in options) && (typeof options.title === 'string')) ? options.title : settings.toast.defaults.title;
- var message = ('message' in options) ? options.message : null;
- var priority = (('priority' in options) && (typeof options.priority === 'string')) ? options.priority : settings.toast.defaults.priority;
- if (message !== null)
- {
- toasting.notify(title, message, priority);
- }
- };
- $.toaster.reset = function ()
- {
- settings = {};
- $.extend(settings, defaults);
- };
- })(jQuery);
|