1/** 2 * noty - jQuery Notification Plugin v2.2.2 3 * Contributors: https://github.com/needim/noty/graphs/contributors 4 * 5 * Examples and Documentation - http://needim.github.com/noty/ 6 * 7 * Licensed under the MIT licenses: 8 * http://www.opensource.org/licenses/mit-license.php 9 * 10 **/ 11 12if (typeof Object.create !== 'function') { 13 Object.create = function (o) { 14 function F() { 15 } 16 17 F.prototype = o; 18 return new F(); 19 }; 20} 21 22(function ($) { 23 24 var NotyObject = { 25 26 init:function (options) { 27 28 // Mix in the passed in options with the default options 29 this.options = $.extend({}, $.noty.defaults, options); 30 31 this.options.layout = (this.options.custom) ? $.noty.layouts['inline'] : $.noty.layouts[this.options.layout]; 32 33 if ($.noty.themes[this.options.theme]) 34 this.options.theme = $.noty.themes[this.options.theme]; 35 else 36 options.themeClassName = this.options.theme; 37 38 delete options.layout; 39 delete options.theme; 40 41 this.options = $.extend({}, this.options, this.options.layout.options); 42 this.options.id = 'noty_' + (new Date().getTime() * Math.floor(Math.random() * 1000000)); 43 44 this.options = $.extend({}, this.options, options); 45 46 // Build the noty dom initial structure 47 this._build(); 48 49 // return this so we can chain/use the bridge with less code. 50 return this; 51 }, // end init 52 53 _build:function () { 54 55 // Generating noty bar 56 var $bar = $('<div class="noty_bar noty_type_' + this.options.type + '"></div>').attr('id', this.options.id); 57 $bar.append(this.options.template).find('.noty_text').html(this.options.text); 58 59 this.$bar = (this.options.layout.parent.object !== null) ? $(this.options.layout.parent.object).css(this.options.layout.parent.css).append($bar) : $bar; 60 61 if (this.options.themeClassName) 62 this.$bar.addClass(this.options.themeClassName).addClass('noty_container_type_' + this.options.type); 63 64 // Set buttons if available 65 if (this.options.buttons) { 66 67 // If we have button disable closeWith & timeout options 68 this.options.closeWith = []; 69 this.options.timeout = false; 70 71 var $buttons = $('<div/>').addClass('noty_buttons'); 72 73 (this.options.layout.parent.object !== null) ? this.$bar.find('.noty_bar').append($buttons) : this.$bar.append($buttons); 74 75 var self = this; 76 77 $.each(this.options.buttons, function (i, button) { 78 var $button = $('<button/>').addClass((button.addClass) ? button.addClass : 'gray').html(button.text).attr('id', button.id ? button.id : 'button-' + i) 79 .appendTo(self.$bar.find('.noty_buttons')) 80 .bind('click', function () { 81 if ($.isFunction(button.onClick)) { 82 button.onClick.call($button, self); 83 } 84 }); 85 }); 86 } 87 88 // For easy access 89 this.$message = this.$bar.find('.noty_message'); 90 this.$closeButton = this.$bar.find('.noty_close'); 91 this.$buttons = this.$bar.find('.noty_buttons'); 92 93 $.noty.store[this.options.id] = this; // store noty for api 94 95 }, // end _build 96 97 show:function () { 98 99 var self = this; 100 101 (self.options.custom) ? self.options.custom.find(self.options.layout.container.selector).append(self.$bar) : $(self.options.layout.container.selector).append(self.$bar); 102 103 if (self.options.theme && self.options.theme.style) 104 self.options.theme.style.apply(self); 105 106 ($.type(self.options.layout.css) === 'function') ? this.options.layout.css.apply(self.$bar) : self.$bar.css(this.options.layout.css || {}); 107 108 self.$bar.addClass(self.options.layout.addClass); 109 110 self.options.layout.container.style.apply($(self.options.layout.container.selector)); 111 112 self.showing = true; 113 114 if (self.options.theme && self.options.theme.style) 115 self.options.theme.callback.onShow.apply(this); 116 117 if ($.inArray('click', self.options.closeWith) > -1) 118 self.$bar.css('cursor', 'pointer').one('click', function (evt) { 119 self.stopPropagation(evt); 120 if (self.options.callback.onCloseClick) { 121 self.options.callback.onCloseClick.apply(self); 122 } 123 self.close(); 124 }); 125 126 if ($.inArray('hover', self.options.closeWith) > -1) 127 self.$bar.one('mouseenter', function () { 128 self.close(); 129 }); 130 131 if ($.inArray('button', self.options.closeWith) > -1) 132 self.$closeButton.one('click', function (evt) { 133 self.stopPropagation(evt); 134 self.close(); 135 }); 136 137 if ($.inArray('button', self.options.closeWith) == -1) 138 self.$closeButton.remove(); 139 140 if (self.options.callback.onShow) 141 self.options.callback.onShow.apply(self); 142 143 self.$bar.animate( 144 self.options.animation.open, 145 self.options.animation.speed, 146 self.options.animation.easing, 147 function () { 148 if (self.options.callback.afterShow) self.options.callback.afterShow.apply(self); 149 self.showing = false;
150 self.shown = true; 151 }); 152 153 // If noty is have a timeout option 154 if (self.options.timeout) 155 self.$bar.delay(self.options.timeout).promise().done(function () { 156 self.close(); 157 }); 158 159 return this; 160 161 }, // end show 162 163 close:function () { 164 165 if (this.closed) return; 166 if (this.$bar && this.$bar.hasClass('i-am-closing-now')) return; 167 168 var self = this; 169 170 if (this.showing) { 171 self.$bar.queue( 172 function () { 173 self.close.apply(self); 174 } 175 ) 176 return; 177 } 178 179 if (!this.shown && !this.showing) { // If we are still waiting in the queue just delete from queue 180 var queue = []; 181 $.each($.noty.queue, function (i, n) { 182 if (n.options.id != self.options.id) { 183 queue.push(n); 184 } 185 }); 186 $.noty.queue = queue; 187 return; 188 } 189 190 self.$bar.addClass('i-am-closing-now'); 191 192 if (self.options.callback.onClose) { 193 self.options.callback.onClose.apply(self); 194 } 195 196 self.$bar.clearQueue().stop().animate( 197 self.options.animation.close, 198 self.options.animation.speed, 199 self.options.animation.easing, 200 function () { 201 if (self.options.callback.afterClose) self.options.callback.afterClose.apply(self); 202 }) 203 .promise().done(function () { 204 205 // Modal Cleaning 206 if (self.options.modal) { 207 $.notyRenderer.setModalCount(-1); 208 if ($.notyRenderer.getModalCount() == 0) $('.noty_modal').fadeOut('fast', function () { 209 $(this).remove(); 210 }); 211 } 212 213 // Layout Cleaning 214 $.notyRenderer.setLayoutCountFor(self, -1); 215 if ($.notyRenderer.getLayoutCountFor(self) == 0) $(self.options.layout.container.selector).remove(); 216 217 // Make sure self.$bar has not been removed before attempting to remove it 218 if (typeof self.$bar !== 'undefined' && self.$bar !== null ) { 219 self.$bar.remove(); 220 self.$bar = null; 221 self.closed = true; 222 } 223 224 delete $.noty.store[self.options.id]; // deleting noty from store 225 226 if(self.options.theme.callback && self.options.theme.callback.onClose) { 227 self.options.theme.callback.onClose.apply(self); 228 } 229 230 if (!self.options.dismissQueue) { 231 // Queue render 232 $.noty.ontap = true; 233 234 $.notyRenderer.render(); 235 } 236 237 if (self.options.maxVisible > 0 && self.options.dismissQueue) { 238 $.notyRenderer.render(); 239 } 240 }) 241 242 }, // end close 243 244 setText:function (text) { 245 if (!this.closed) { 246 this.options.text = text; 247 this.$bar.find('.noty_text').html(text); 248 } 249 return this; 250 }, 251 252 setType:function (type) { 253 if (!this.closed) { 254 this.options.type = type; 255 this.options.theme.style.apply(this); 256 this.options.theme.callback.onShow.apply(this); 257 } 258 return this; 259 }, 260 261 setTimeout:function (time) { 262 if (!this.closed) { 263 var self = this; 264 this.options.timeout = time; 265 self.$bar.delay(self.options.timeout).promise().done(function () { 266 self.close(); 267 }); 268 } 269 return this; 270 }, 271 272 stopPropagation:function (evt) { 273 evt = evt || window.event; 274 if (typeof evt.stopPropagation !== "undefined") { 275 evt.stopPropagation(); 276 } else { 277 evt.cancelBubble = true; 278 } 279 }, 280 281 closed:false, 282 showing:false, 283 shown:false 284 285 }; // end NotyObject 286 287 $.notyRenderer = {}; 288 289 $.notyRenderer.init = function (options) { 290 291 // Renderer creates a new noty 292 var notification = Object.create(NotyObject).init(options); 293 294 if (notification.options.killer) 295 $.noty.closeAll(); 296 297 (notification.options.force) ? $.noty.queue.unshift(notification) : $.noty.queue.push(notification); 298 299 $.notyRenderer.render(); 300 301 return ($.noty.returns == 'object') ? notification : notification.options.id; 302 }; 303 304 $.notyRenderer.render = function () { 305 306 var instance = $.noty.queue[0]; 307 308 if ($.type(instance) === 'object') { 309 if (instance.options.dismissQueue) { 310 if (instance.options.maxVisible > 0) { 311 if ($(instance.options.layout.container.selector + ' li').length < instance.options.maxVisible) { 312 $.notyRenderer.show($.noty.queue.shift()); 313 } else { 314 315 } 316 } else { 317 $.notyRenderer.show($.noty.queue.shift()); 318 } 319 } else { 320 if ($.noty.ontap) { 321 $.notyRenderer.show($.noty.queue.shift()); 322 $.noty.ontap = false;
323 } 324 } 325 } else { 326 $.noty.ontap = true; // Queue is over 327 } 328 329 }; 330 331 $.notyRenderer.show = function (notification) { 332 333 if (notification.options.modal) { 334 $.notyRenderer.createModalFor(notification); 335 $.notyRenderer.setModalCount(+1); 336 } 337 338 // Where is the container? 339 if (notification.options.custom) { 340 if (notification.options.custom.find(notification.options.layout.container.selector).length == 0) { 341 notification.options.custom.append($(notification.options.layout.container.object).addClass('i-am-new')); 342 } else { 343 notification.options.custom.find(notification.options.layout.container.selector).removeClass('i-am-new'); 344 } 345 } else { 346 if ($(notification.options.layout.container.selector).length == 0) { 347 $('body').append($(notification.options.layout.container.object).addClass('i-am-new')); 348 } else { 349 $(notification.options.layout.container.selector).removeClass('i-am-new'); 350 } 351 } 352 353 $.notyRenderer.setLayoutCountFor(notification, +1); 354 355 notification.show(); 356 }; 357 358 $.notyRenderer.createModalFor = function (notification) { 359 if ($('.noty_modal').length == 0) { 360 var modal = $('<div/>').addClass('noty_modal').addClass(notification.options.theme).data('noty_modal_count', 0); 361 362 if (notification.options.theme.modal && notification.options.theme.modal.css) 363 modal.css(notification.options.theme.modal.css); 364 365 modal.prependTo($('body')).fadeIn('fast'); 366 } 367 }; 368 369 $.notyRenderer.getLayoutCountFor = function (notification) { 370 return $(notification.options.layout.container.selector).data('noty_layout_count') || 0; 371 }; 372 373 $.notyRenderer.setLayoutCountFor = function (notification, arg) { 374 return $(notification.options.layout.container.selector).data('noty_layout_count', $.notyRenderer.getLayoutCountFor(notification) + arg); 375 }; 376 377 $.notyRenderer.getModalCount = function () { 378 return $('.noty_modal').data('noty_modal_count') || 0; 379 }; 380 381 $.notyRenderer.setModalCount = function (arg) { 382 return $('.noty_modal').data('noty_modal_count', $.notyRenderer.getModalCount() + arg); 383 }; 384 385 // This is for custom container 386 $.fn.noty = function (options) { 387 options.custom = $(this); 388 return $.notyRenderer.init(options); 389 }; 390 391 $.noty = {}; 392 $.noty.queue = []; 393 $.noty.ontap = true; 394 $.noty.layouts = {}; 395 $.noty.themes = {}; 396 $.noty.returns = 'object'; 397 $.noty.store = {}; 398 399 $.noty.get = function (id) { 400 return $.noty.store.hasOwnProperty(id) ? $.noty.store[id] : false; 401 }; 402 403 $.noty.close = function (id) { 404 return $.noty.get(id) ? $.noty.get(id).close() : false; 405 }; 406 407 $.noty.setText = function (id, text) { 408 return $.noty.get(id) ? $.noty.get(id).setText(text) : false; 409 }; 410 411 $.noty.setType = function (id, type) { 412 return $.noty.get(id) ? $.noty.get(id).setType(type) : false; 413 }; 414 415 $.noty.clearQueue = function () { 416 $.noty.queue = []; 417 }; 418 419 $.noty.closeAll = function () { 420 $.noty.clearQueue(); 421 $.each($.noty.store, function (id, noty) { 422 noty.close(); 423 }); 424 }; 425 426 var windowAlert = window.alert; 427 428 $.noty.consumeAlert = function (options) { 429 window.alert = function (text) { 430 if (options) 431 options.text = text; 432 else 433 options = {text:text}; 434 435 $.notyRenderer.init(options); 436 }; 437 }; 438 439 $.noty.stopConsumeAlert = function () { 440 window.alert = windowAlert; 441 }; 442 443 $.noty.defaults = { 444 layout:'top', 445 theme:'defaultTheme', 446 type:'alert', 447 text:'', 448 dismissQueue:true, 449 template:'<div class="noty_message"><span class="noty_text"></span><div class="noty_close"></div></div>', 450 animation:{ 451 open:{height:'toggle'}, 452 close:{height:'toggle'}, 453 easing:'swing', 454 speed:500 455 }, 456 timeout:false, 457 force:false, 458 modal:false, 459 maxVisible:5, 460 killer: false, 461 closeWith:['click'], 462 callback:{ 463 onShow:function () { 464 }, 465 afterShow:function () { 466 }, 467 onClose:function () { 468 }, 469 afterClose:function () { 470 }, 471 onCloseClick:function () { 472 } 473 }, 474 buttons:false 475 }; 476 477 $(window).resize(function () { 478 $.each($.noty.layouts, function (index, layout) { 479 layout.container.style.apply($(layout.container.selector)); 480 }); 481 }); 482 483})(jQuery); 484 485// Helpers 486window.noty = function noty(options) { 487 return jQuery.notyRenderer.init(options); 488};
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.