PageSourceSearch

https://town-web.co.jp/box-list/share/js/jquery.jgrowl.js

js town-web.co.jp collected 2026-10-04 14:59:45 UTC 9,126 bytes, 219 lines download raw bytes

1/**
2 * jGrowl 1.1.2
3 *
4 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
5 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
6 *
7 * Written by Stan Lemon <[email protected]>
8 * Last updated: 2008.08.17
9 *
10 * jGrowl is a jQuery plugin implementing unobtrusive userland notifications.  These 
11 * notifications function similarly to the Growl Framework available for
12 * Mac OS X (http://growl.info).
13 *
14 * To Do:
15 * - Move library settings to containers and allow them to be changed per container
16 *
17 * Changes in 1.1.2
18 * - Added iPhone styled example
19 * - Fixed possible IE7 bug when determining if the ie6 class shoudl be applied.
20 * - Added template for the close button, so that it's content could be customized.
21 *
22 * Changes in 1.1.1
23 * - Fixed CSS styling bug for ie6 caused by a mispelling
24 * - Changes height restriction on default notifications to min-height
25 * - Added skinned examples using a variety of images
26 * - Added the ability to customize the content of the [close all] box
27 * - Added jTweet, an example of using jGrowl + Twitter
28 *
29 * Changes in 1.1.0
30 * - Multiple container and instances.
31 * - Standard $.jGrowl() now wraps $.fn.jGrowl() by first establishing a generic jGrowl container.
32 * - Instance methods of a jGrowl container can be called by $.fn.jGrowl(methodName)
33 * - Added glue preferenced, which allows notifications to be inserted before or after nodes in the container
34 * - Added new log callback which is called before anything is done for the notification
35 * - Corner's attribute are now applied on an individual notification basis.
36 *
37 * Changes in 1.0.4
38 * - Various CSS fixes so that jGrowl renders correctly in IE6.
39 *
40 * Changes in 1.0.3
41 * - Fixed bug with options persisting across notifications
42 * - Fixed theme application bug
43 * - Simplified some selectors and manipulations.
44 * - Added beforeOpen and beforeClose callbacks
45 * - Reorganized some lines of code to be more readable
46 * - Removed unnecessary this.defaults context
47 * - If corners plugin is present, it's now customizable.
48 * - Customizable open animation.
49 * - Customizable close animation.
50 * - Customizable animation easing.
51 * - Added customizable positioning (top-left, top-right, bottom-left, bottom-right, center)
52 *
53 * Changes in 1.0.2
54 * - All CSS styling is now external.
55 * - Added a theme parameter which specifies a secondary class for styling, such
56 *   that notifications can be customized in appearance on a per message basis.
57 * - Notification life span is now customizable on a per message basis.
58 * - Added the ability to disable the global closer, enabled by default.
59 * - Added callbacks for when a notification is opened or closed.
60 * - Added callback for the global closer.
61 * - Customizable animation speed.
62 * - jGrowl now set itself up and tears itself down.
63 *
64 * Changes in 1.0.1:
65 * - Removed dependency on metadata plugin in favor of .data()
66 * - Namespaced all events
67 */
68(function($) {
69
70	/** jGrowl Wrapper - Establish a base jGrowl Container for compatibility with older releases. **/
71	$.jGrowl = function( m , o ) {
72		// To maintain compatibility with older version that only supported one instance we'll create the base container.
73		if ( $('#jGrowl').size() == 0 ) $('<div id="jGrowl"></div>').addClass($.jGrowl.defaults.position).appendTo('body');
74		// Create a notification on the container.
75		$('#jGrowl').jGrowl(m,o);
76	};
77
78
79	/** Raise jGrowl Notification on a jGrowl Container **/
80	$.fn.jGrowl = function( m , o ) {
81		if ( $.isFunction(this.each) ) {
82			var args = arguments;
83
84			return this.each(function() {
85				var self = this;
86
87				/** Create a jGrowl Instance on the Container if it does not exist **/
88				if ( $(this).data('jGrowl.instance') == undefined ) {
89					$(this).data('jGrowl.instance', new $.fn.jGrowl());
90					$(this).data('jGrowl.instance').startup( this );
91				}
92
93				/** Optionally call jGrowl instance methods, or just raise a normal notification **/
94				if ( $.isFunction($(this).data('jGrowl.instance')[m]) ) {
95					$(this).data('jGrowl.instance')[m].apply( $(this).data('jGrowl.instance') , $.makeArray(args).slice(1) );
96				} else {
97					$(this).data('jGrowl.instance').notification( m , o );
98				}
99			});
100		};
101	};
102
103	$.extend( $.fn.jGrowl.prototype , {
104
105		/** Default JGrowl Settings **/
106		defaults: {
107			header: 		'',
108			sticky: 		false,
109			position: 		'top-right', // Is this still needed?
110			glue: 			'after',
111			theme: 			'default',
112			corners: 		'10px',
113			check: 			500,
114			life: 			3000,
115			speed: 			'normal',
116			easing: 		'swing',
117			closer: 		true,
118			closeTemplate: '&times;',
119			closerTemplate: '<div>[ close all ]</div>',
120			log: 			function(e,m,o) {},
121			beforeOpen: 	function(e,m,o) {},
122			open: 			function(e,m,o) {},
123			beforeClose: 	function(e,m,o) {},
124			close: 			function(e,m,o) {},
125			animateOpen: 	{
126				opacity: 	'show'
127			},
128			animateClose: 	{
129				opacity: 	'hide'
130			}
131		},
132		
133		/** jGrowl Container Node **/
134		element: 	null,
135	
136		/** Interval Function **/
137		interval:   null,
138		
139		/** Create a Notification **/
140		notification: 	function( message , o ) {
141			var self = this;
142			var o = $.extend({}, this.defaults, o);
143
144			o.log.apply( this.element , [this.element,message,o] );
145
146			var notification = $('<div class="jGrowl-notification"><div class="close">' + o.closeTemplate + '</div><div class="header">' + o.header + '</div><div class="message">' + message + '</div></div>')
147				.data("jGrowl", o).addClass(o.theme).children('div.close').bind("click.jGrowl", function() {
148					$(this).unbind('click.jGrowl').parent().trigger('jGrowl.beforeClose').animate(o.animateClose, o.speed, o.easing, function() {
149						$(this).trigger('jGrowl.close').remove();
150					});
151				}).parent();
152				
153			( o.glue == 'after' ) ? $('div.jGrowl-notification:last', this.element).after(notification) : $('div.jGrowl-notification:first', this.element).before(notification);
154
155			/** Notification Actions **/
156			$(notification).bind("mouseover.jGrowl", function() {
157				$(this).data("jGrowl").pause = true;
158			}).bind("mouseout.jGrowl", function() {
159				$(this).data("jGrowl").pause = false;
160			}).bind('jGrowl.beforeOpen', function() {
161				o.beforeOpen.apply( self.element , [self.element,message,o] );
162			}).bind('jGrowl.open', function() {
163				o.open.apply( self.element , [self.element,message,o] );
164			}).bind('jGrowl.beforeClose', function() {
165				o.beforeClose.apply( self.element , [self.element,message,o] );
166			}).bind('jGrowl.close', function() {
167				o.close.apply( self.element , [self.element,message,o] );
168			}).trigger('jGrowl.beforeOpen').animate(o.animateOpen, o.speed, o.easing, function() {
169				$(this).data("jGrowl").created = new Date();
170			}).trigger('jGrowl.open');
171		
172			/** Optional Corners Plugin **/
173			if ( $.fn.corner != undefined ) $(notification).corner( o.corners );
174
175			/** Add a Global Closer if more than one notification exists **/
176			if ( $('div.jGrowl-notification:parent', this.element).size() > 1 && $('div.jGrowl-closer', this.element).size() == 0 && this.defaults.closer != false ) {
177				$(this.defaults.closerTemplate).addClass('jGrowl-closer').addClass(this.defaults.theme).appendTo(this.element).animate(this.defaults.animateOpen, this.defaults.speed, this.defaults.easing).bind("click.jGrowl", function() {
178					$(this).siblings().children('div.close').trigger("click.jGrowl");
179
180					if ( $.isFunction( self.defaults.closer ) ) self.defaults.closer.apply( $(this).parent()[0] , [$(this).parent()[0]] );
181				});
182			};
183		},
184
185		/** Update the jGrowl Container, removing old jGrowl notifications **/
186		update:	 function() {
187			$(this.element).find('div.jGrowl-notification:parent').each( function() {
188				if ( $(this).data("jGrowl") != undefined && $(this).data("jGrowl").created != undefined && ($(this).data("jGrowl").created.getTime() + $(this).data("jGrowl").life)  < (new Date()).getTime() && $(this).data("jGrowl").sticky != true && 
189					 ($(this).data("jGrowl").pause == undefined || $(this).data("jGrowl").pause != true) ) {
190					$(this).children('div.close').trigger('click.jGrowl');
191				}
192			});
193
194			if ( $(this.element).find('div.jGrowl-notification:parent').size() < 2 ) {
195				$(this.element).find('div.jGrowl-closer').animate(this.defaults.animateClose, this.defaults.speed, this.defaults.easing, function() {
196					$(this).remove();
197				});
198			};
199		},
200
201		/** Setup the jGrowl Notification Container **/
202		startup:	function(e) {
203			this.element = $(e).addClass('jGrowl').append('<div class="jGrowl-notification"></div>');
204			this.interval = setInterval( function() { jQuery(e).data('jGrowl.instance').update(); }, this.defaults.check);
205			
206			if ($.browser.msie && parseInt($.browser.version) < 7 && !window["XMLHttpRequest"]) $(this.element).addClass('ie6');
207		},
208
209		/** Shutdown jGrowl, removing it and clearing the interval **/
210		shutdown:   function() {
211			$(this.element).removeClass('jGrowl').find('div.jGrowl-notification').remove();
212			clearInterval( this.interval );
213		}
214	});
215	
216	/** Reference the Defaults Object for compatibility with older versions of jGrowl **/
217	$.jGrowl.defaults = $.fn.jGrowl.prototype.defaults;
218
219})(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.