vendor: 4,096 bytes, lines 1-140
1; 2(function (define) { 3 define(['jquery'], function ($) { 4 return (function () { 5 var $container; 6 var listener; 7 var toastId = 0; 8 var toastType = { 9 error: 'error', 10 info: 'info', 11 success: 'success', 12 warning: 'warning' 13 }; 14 15 var toastr = { 16 clear: clear, 17 remove: remove, 18 error: error, 19 getContainer: getContainer, 20 info: info, 21 options: {}, 22 subscribe: subscribe, 23 success: success, 24 version: '2.1.0', 25 warning: warning 26 }; 27 28 var previousToast; 29 30 return toastr; 31 32 //#region Accessible Methods 33 function error(message, title, optionsOverride) { 34 return notify({ 35 type: toastType.error, 36 iconClass: getOptions().iconClasses.error, 37 message: message, 38 optionsOverride: optionsOverride, 39 title: title 40 }); 41 } 42 43 function getContainer(options, create) { 44 if (!options) { 45 options = getOptions(); 46 } 47 $container = $('#' + options.containerId); 48 if ($container.length) { 49 return $container; 50 } 51 if (create) { 52 $container = createContainer(options); 53 } 54 return $container; 55 } 56 57 function info(message, title, optionsOverride) { 58 return notify({ 59 type: toastType.info, 60 iconClass: getOptions().iconClasses.info, 61 message: message, 62 optionsOverride: optionsOverride, 63 title: title 64 }); 65 } 66 67 function subscribe(callback) { 68 listener = callback; 69 } 70 71 function success(message, title, optionsOverride) { 72 return notify({ 73 type: toastType.success, 74 iconClass: getOptions().iconClasses.success, 75 message: message, 76 optionsOverride: optionsOverride, 77 title: title 78 }); 79 } 80 81 function warning(message, title, optionsOverride) { 82 return notify({ 83 type: toastType.warning, 84 iconClass: getOptions().iconClasses.warning, 85 message: message, 86 optionsOverride: optionsOverride, 87 title: title 88 }); 89 } 90 91 function clear($toastElement) { 92 var options = getOptions(); 93 if (!$container) { 94 getContainer(options); 95 } 96 if (!clearToast($toastElement, options)) { 97 clearContainer(options); 98 } 99 } 100 101 function remove($toastElement) { 102 var options = getOptions(); 103 if (!$container) { 104 getContainer(options); 105 } 106 if ($toastElement && $(':focus', $toastElement).length === 0) { 107 removeToast($toastElement); 108 return; 109 } 110 if ($container.children().length) { 111 $container.remove(); 112 } 113 } 114 //#endregion 115 116 //#region Internal Methods 117 118 function clearContainer(options) { 119 var toastsToClear = $container.children(); 120 for (var i = toastsToClear.length - 1; i >= 0; i--) { 121 clearToast($(toastsToClear[i]), options); 122 } 123 ; 124 } 125 126 function clearToast($toastElement, options) { 127 if ($toastElement && $(':focus', $toastElement).length === 0) { 128 $toastElement[options.hideMethod]({ 129 duration: options.hideDuration, 130 easing: options.hideEasing, 131 complete: function () { 132 removeToast($toastElement); 133 } 134 }); 135 return true; 136 } 137 return false; 138 } 139 140 function createContainer(options) {
141 $container = $('<div/>') 142 .attr('id', options.containerId) 143 .addClass(options.positionClass) 144 .attr('aria-live', 'polite') 145 .attr('role', 'alert'); 146 147 $container.appendTo($(options.target)); 148 return $container; 149 } 150 151 function getDefaults() { 152 return { 153 tapToDismiss: true, 154 toastClass: 'toast', 155 containerId: 'toast-container', 156 debug: false, 157 158 showMethod: 'fadeIn', //fadeIn, slideDown, and show are built into jQuery 159 showDuration: 300, 160 showEasing: 'swing', //swing and linear are built into jQuery 161 onShown: undefined, 162 hideMethod: 'fadeOut', 163 hideDuration: 1000, 164 hideEasing: 'swing', 165 onHidden: undefined, 166 167 extendedTimeOut: 1000, 168 iconClasses: { 169 error: 'toast-custom-error', 170 info: 'toast-info', 171 success: 'toast-custom-success', 172 warning: 'toast-warning' 173 }, 174 iconClass: 'toast-info', 175 positionClass: 'toast-top-right', 176 timeOut: 5000, // Set timeOut and extendedTimeOut to 0 to make it sticky 177 titleClass: 'toast-title', 178 messageClass: 'toast-message', 179 target: 'body', 180 closeHtml: '<button>×</button>', 181 newestOnTop: true, 182 preventDuplicates: false 183 }; 184 } 185 186 function publish(args) { 187 if (!listener) { 188 return; 189 } 190 listener(args); 191 } 192 193 function notify(map) { 194 var options = getOptions(), 195 iconClass = map.iconClass || options.iconClass; 196 197 if (options.preventDuplicates) { 198 if (map.message === previousToast) { 199 return; 200 } else { 201 previousToast = map.message; 202 } 203 } 204 205 if (typeof (map.optionsOverride) !== 'undefined') { 206 options = $.extend(options, map.optionsOverride); 207 iconClass = map.optionsOverride.iconClass || iconClass; 208 } 209 210 toastId++; 211 212 $container = getContainer(options, true); 213 var intervalId = null, 214 $toastElement = $('<div/>'), 215 $titleElement = $('<div/>'), 216 $messageElement = $('<div/>'), 217 $closeElement = $(options.closeHtml), 218 response = { 219 toastId: toastId, 220 state: 'visible', 221 startTime: new Date(), 222 options: options, 223 map: map 224 }; 225 226 if (map.iconClass) { 227 $toastElement.addClass(options.toastClass).addClass(iconClass); 228 } 229 230 if (map.title) { 231 $titleElement.append(map.title).addClass(options.titleClass); 232 $toastElement.append($titleElement); 233 } 234 235 if (map.message) { 236 $messageElement.append(map.message).addClass(options.messageClass); 237 $toastElement.append($messageElement); 238 } 239 240 if (options.closeButton) { 241 $closeElement.addClass('toast-close-button').attr("role", "button"); 242 $toastElement.prepend($closeElement); 243 } 244 245 $toastElement.hide(); 246 if (options.newestOnTop) { 247 $container.prepend($toastElement); 248 } else { 249 $container.append($toastElement); 250 } 251 252 $toastElement[options.showMethod]({ 253 duration: options.showDuration, 254 easing: options.showEasing, 255 complete: options.onShown 256 }); 257 258 if (options.timeOut > 0) { 259 intervalId = setTimeout(hideToast, options.timeOut); 260 } 261 262 $toastElement.hover(stickAround, delayedHideToast); 263 if (!options.onclick && options.tapToDismiss) { 264 $toastElement.click(hideToast); 265 } 266 267 if (options.closeButton && $closeElement) { 268 $closeElement.click(function (event) { 269 if (event.stopPropagation) { 270 event.stopPropagation(); 271 } else if (event.cancelBubble !== undefined && event.cancelBubble !== true) { 272 event.cancelBubble = true; 273 } 274 hideToast(true); 275 }); 276 } 277 278 if (options.onclick) { 279 $toastElement.click(function () { 280 options.onclick(); 281 hideToast(); 282 }); 283 } 284 285 publish(response); 286 287 if (options.debug && console) { 288 console.log(response); 289 } 290 291 return $toastElement; 292 293 function hideToast(override) { 294 if ($(':focus', $toastElement).length && !override) { 295 return; 296 } 297 return $toastElement[options.hideMethod]({ 298 duration: options.hideDuration, 299 easing: options.hideEasing, 300 complete: function () { 301 removeToast($toastElement); 302 if (options.onHidden && response.state !== 'hidden') { 303 options.onHidden(); 304 } 305 response.state = 'hidden'; 306 response.endTime = new Date(); 307 publish(response); 308 } 309 }); 310 } 311 312 function delayedHideToast() { 313 if (options.timeOut > 0 || options.extendedTimeOut > 0) { 314 intervalId = setTimeout(hideToast, options.extendedTimeOut); 315 } 316 } 317 318 function stickAround() { 319 clearTimeout(intervalId); 320 $toastElement.stop(true, true)[options.showMethod]({ 321 duration: options.showDuration, 322 easing: options.showEasing 323 }); 324 } 325 } 326 327 function getOptions() { 328 return $.extend({}, getDefaults(), toastr.options); 329 } 330 331 function removeToast($toastElement) { 332 if (!$container) { 333 $container = getContainer(); 334 } 335 if ($toastElement.is(':visible')) { 336 return; 337 } 338 $toastElement.remove(); 339 $toastElement = null; 340 if ($container.children().length === 0) { 341 $container.remove(); 342 } 343 } 344 //#endregion 345 346 })(); 347 }); 348}(typeof define === 'function' && define.amd ? define : function (deps, factory) { 349 if (typeof module !== 'undefined' && module.exports) { //Node 350 module.exports = factory(require('jquery')); 351 } else { 352 window['toastr'] = factory(window['jQuery']); 353 } 354})); 355jQuery.fn.exists = function () { 356 return this.length > 0; 357}
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.