1/*********************************************************************************** 2 github.com/scottoffen/jquery.toaster 3 4 * Add Array.indexOf * 5 ***********************************************************************************/ 6(function () { 7 if (typeof Array.prototype.indexOf !== 'function') { 8 Array.prototype.indexOf = function (searchElement, fromIndex) { 9 for (var i = (fromIndex || 0), j = this.length; i < j; i += 1) { 10 if ((searchElement === undefined) || (searchElement === null)) { 11 if (this[i] === searchElement) { 12 return i; 13 } 14 } else if (this[i] === searchElement) { 15 return i; 16 } 17 } 18 return -1; 19 }; 20 } 21})(); 22/**********************************************************************************/ 23 24(function ($, undefined) { 25 var toasting = { 26 gettoaster: function () { 27 var toaster = $j('#' + settings.toaster.id); 28 29 if (toaster.length < 1) { 30 toaster = $j(settings.toaster.template).attr('id', settings.toaster.id).css(settings.toaster.css).addClass(settings.toaster['class']); 31 32 if ((settings.stylesheet) && (!$j("link[href=" + settings.stylesheet + "]").length)) { 33 $j('head').appendTo('<link rel="stylesheet" href="' + settings.stylesheet + '">'); 34 } 35 36 $j(settings.toaster.container).append(toaster); 37 } 38 39 return toaster; 40 }, 41 42 notify: function (title, message, priority) { 43 var $toaster = this.gettoaster(); 44 var $toast = $j(settings.toast.template.replace('%priority%', priority)).hide().css(settings.toast.css).addClass(settings.toast['class']); 45 46 $j('.toast-heading .area-heading', $toast).css(settings.toast.csst).html(title); 47 $j('.toast-body p', $toast).css(settings.toast.cssm).html(message); 48 49 if ((settings.debug) && (window.console)) { 50 console.log(toast); 51 } 52 53 $toaster.append(settings.toast.display($toast)); 54 55 if (settings.donotdismiss.indexOf(priority) === -1) { 56 var timeout = (typeof settings.timeout === 'number') ? settings.timeout : ((typeof settings.timeout === 'object') && (priority in settings.timeout)) ? settings.timeout[priority] : 1500; 57 setTimeout(function () { 58 settings.toast.remove($toast, function () { 59 $toast.remove(); 60 }); 61 }, timeout); 62 } 63 } 64 }; 65 66 var defaults = { 67 'toaster': { 68 'id': 'toaster', 69 'container': 'body', 70 'template': '<div></div>', 71 'class': 'toaster', 72 'css': { 73 //'position': 'fixed', 74 //'top': '60px', 75 //'right': '20px', 76 //'width': '300px', 77 'zIndex': 11 78 } 79 }, 80 81 'toast': { 82 'template': '<div class="alert alert-%priority% alert-dismissible" role="alert">' + 83 '<button type="button" class="close" data-dismiss="alert">' + 84 '<span aria-hidden="true">×</span>' + 85 '<span class="sr-only">Close</span>' + 86 '</button>' + 87 88 '<div class="toast-heading">' + 89 '<h3 class="area-heading"></h3>' + 90 '</div>' + 91 '<div class="toast-body">' + 92 '<p></p>' + 93 '</div>' + 94 95 '</div>', 96 97 'defaults': { 98 'title': 'Notice', 99 'priority': 'success' 100 }, 101 102 'css': {}, 103 'cssm': {}, 104 'csst': { 105 'fontWeight': 'bold' 106 }, 107 108 'fade': 'slow', 109 110 'display': function ($toast) { 111 return $toast.fadeIn(settings.toast.fade); 112 }, 113 114 'remove': function ($toast, callback) { 115 return $toast.animate({ 116 opacity: '0', 117 padding: '0px', 118 margin: '0px', 119 height: '0px' 120 }, { 121 duration: settings.toast.fade, 122 complete: callback 123 }); 124 } 125 }, 126 127 'debug': false, 128 'timeout': 6000, 129 'stylesheet': null, 130 'donotdismiss': [] // array of priority 131 }; 132 133 var settings = {}; 134 $.extend(settings, defaults); 135 136 $.toaster = function (options) { 137 if (typeof options === 'object') {
138 if ('settings' in options) { 139 settings = $.extend(true, settings, options.settings); 140 } 141 } else { 142 var values = Array.prototype.slice.call(arguments, 0); 143 var labels = ['message', 'title', 'priority']; 144 options = {}; 145 146 for (var i = 0, l = values.length; i < l; i += 1) { 147 options[labels[i]] = values[i]; 148 } 149 } 150 151 var title = (('title' in options) && (typeof options.title === 'string')) ? options.title : settings.toast.defaults.title; 152 var message = ('message' in options) ? options.message : null; 153 var priority = (('priority' in options) && (typeof options.priority === 'string')) ? options.priority : settings.toast.defaults.priority; 154 155 if (message !== null) { 156 toasting.notify(title, message, priority); 157 } 158 }; 159 160 $.toaster.reset = function () { 161 settings = {}; 162 $.extend(settings, defaults); 163 }; 164})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.