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