PageSourceSearch

https://www.fiepr.org.br/layout/js/plugins/jquery-toastmessage/javascript/jquery.toastmessage.js

js fiepr.org.br collected 2026-09-24 09:49:06 UTC 6,592 bytes, 161 lines download raw bytes

1/*
2 * Copyright 2010 akquinet
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *   http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/**
17 *  This JQuery Plugin will help you in showing some nice Toast-Message like notification messages. The behavior is
18 *  similar to the android Toast class.
19 *  You have 4 different toast types you can show. Each type comes with its own icon and colored border. The types are:
20 *  - notice
21 *  - success
22 *  - warning
23 *  - error
24 *
25 *  The following methods will display a toast message:
26 *
27 *   $().toastmessage('showNoticeToast', 'some message here');
28 *   $().toastmessage('showSuccessToast', "some message here");
29 *   $().toastmessage('showWarningToast', "some message here");
30 *   $().toastmessage('showErrorToast', "some message here");
31 *
32 *   // user configured toastmessage:
33 *   $().toastmessage('showToast', {
34 *      text     : 'Hello World',
35 *      sticky   : true,
36 *      position : 'top-right',
37 *      type     : 'success',
38 *      close    : function () {console.log("toast is closed ...");}
39 *   });
40 *
41 *   To see some more examples please have a look into the Tests in src/test/javascript/ToastmessageTest.js
42 *
43 *   For further style configuration please see corresponding css file: jquery-toastmessage.css
44 *
45 *   This plugin is based on the jquery-notice (http://sandbox.timbenniks.com/projects/jquery-notice/)
46 *   but is enhanced in several ways:
47 *
48 *   configurable positioning
49 *   convenience methods for different message types
50 *   callback functionality when closing the toast
51 *   included some nice free icons
52 *   reimplemented to follow jquery plugin good practices rules
53 *
54 *   Author: Daniel Bremer-Tonn
55**/
56(function($)
57{
58	var settings = {
59				inEffect: 			{opacity: 'show'},	// in effect
60				inEffectDuration: 	600,				// in effect duration in miliseconds
61				stayTime: 			3000,				// time in miliseconds before the item has to disappear
62				text: 				'',					// content of the item. Might be a string or a jQuery object. Be aware that any jQuery object which is acting as a message will be deleted when the toast is fading away.
63				sticky: 			false,				// should the toast item sticky or not?
64				type: 				'notice', 			// notice, warning, error, success
65                position:           'top-right',        // top-left, top-center, top-right, middle-left, middle-center, middle-right ... Position of the toast container holding different toast. Position can be set only once at the very first call, changing the position after the first call does nothing
66                closeText:          '',                 // text which will be shown as close button, set to '' when you want to introduce an image via css
67                close:              null                // callback function when the toastmessage is closed
68            };
69
70    var methods = {
71        init : function(options)
72		{
73			if (options) {
74                $.extend( settings, options );
75            }
76		},
77
78        showToast : function(options)
79		{
80			var localSettings = {};
81            $.extend(localSettings, settings, options);
82
83			// declare variables
84            var toastWrapAll, toastItemOuter, toastItemInner, toastItemClose, toastItemImage;
85
86			toastWrapAll	= (!$('.toast-container').length) ? $('<div></div>').addClass('toast-container').addClass('toast-position-' + localSettings.position).appendTo('body') : $('.toast-container');
87			toastItemOuter	= $('<div></div>').addClass('toast-item-wrapper');
88			toastItemInner	= $('<div></div>').hide().addClass('toast-item toast-type-' + localSettings.type).appendTo(toastWrapAll).html($('<p>').append (localSettings.text)).animate(localSettings.inEffect, localSettings.inEffectDuration).wrap(toastItemOuter);
89			toastItemClose	= $('<div></div>').addClass('toast-item-close').prependTo(toastItemInner).html(localSettings.closeText).click(function() { $().toastmessage('removeToast',toastItemInner, localSettings) });
90			toastItemImage  = $('<div></div>').addClass('toast-item-image').addClass('toast-item-image-' + localSettings.type).prependTo(toastItemInner);
91
92            if(navigator.userAgent.match(/MSIE 6/i))
93			{
94		    	toastWrapAll.css({top: document.documentElement.scrollTop});
95		    }
96
97			if(!localSettings.sticky)
98			{
99				setTimeout(function()
100				{
101					$().toastmessage('removeToast', toastItemInner, localSettings);
102				},
103				localSettings.stayTime);
104			}
105            return toastItemInner;
106		},
107
108        showNoticeToast : function (message)
109        {
110            var options = {text : message, type : 'notice'};
111            return $().toastmessage('showToast', options);
112        },
113
114        showSuccessToast : function (message)
115        {
116            var options = {text : message, type : 'success'};
117            return $().toastmessage('showToast', options);
118        },
119
120        showErrorToast : function (message)
121        {
122            var options = {text : message, type : 'error'};
123            return $().toastmessage('showToast', options);
124        },
125
126        showWarningToast : function (message)
127        {
128            var options = {text : message, type : 'warning'};
129            return $().toastmessage('showToast', options);
130        },
131
132		removeToast: function(obj, options)
133		{
134			obj.animate({opacity: '0'}, 600, function()
135			{
136				obj.parent().animate({height: '0px'}, 300, function()
137				{
138					obj.parent().remove();
139				});
140			});
141            // callback
142            if (options && options.close !== null)
143            {
144                options.close();
145            }
146		}
147	};
148
149    $.fn.toastmessage = function( method ) {
150
151        // Method calling logic
152        if ( methods[method] ) {
153          return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
154        } else if ( typeof method === 'object' || ! method ) {
155          return methods.init.apply( this, arguments );
156        } else {
157          $.error( 'Method ' +  method + ' does not exist on jQuery.toastmessage' );
158        }
159    };
160
161})(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.