Skip to content

Add Bottom position;position can be set more #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 62 additions & 53 deletions src/main/javascript/jquery.toastmessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,37 +62,46 @@
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.
sticky: false, // should the toast item sticky or not?
type: 'notice', // notice, warning, error, success
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
closeText: '', // text which will be shown as close button, set to '' when you want to introduce an image via css
close: null // callback function when the toastmessage is closed
};
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
closeText: '', // text which will be shown as close button, set to '' when you want to introduce an image via css
close: null // callback function when the toastmessage is closed
};

var methods = {
init : function(options)
var methods = {
init : function(options)
{
if (options) {
$.extend( settings, options );
}
$.extend( settings, options );
}
},

showToast : function(options)
showToast : function(options)
{
var localSettings = {};
$.extend(localSettings, settings, options);
$.extend(localSettings, settings, options);

// declare variables
var toastWrapAll, toastItemOuter, toastItemInner, toastItemClose, toastItemImage;

toastWrapAll = (!$('.toast-container').length) ? $('<div></div>').addClass('toast-container').addClass('toast-position-' + localSettings.position).appendTo('body') : $('.toast-container');
var toastWrapAll, toastItemOuter, toastItemInner, toastItemClose, toastItemImage;
if($('.toast-position-' + localSettings.position).length) {
toastWrapAll = $('.toast-position-' + localSettings.position);
}
else {
toastWrapAll = $('<div></div>').addClass('toast-container').addClass('toast-position-' + localSettings.position).appendTo('body');
}
toastItemOuter = $('<div></div>').addClass('toast-item-wrapper');
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);
if(localSettings.position === 'bottom-left' || localSettings.position === 'bottom-center' || localSettings.position === 'bottom-right') {
toastItemInner = $('<div></div>').hide().addClass('toast-item toast-type-' + localSettings.type).prependTo(toastWrapAll).html($('<p>').append (localSettings.text)).animate(localSettings.inEffect, localSettings.inEffectDuration).wrap(toastItemOuter);
}
else {
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);
}
toastItemClose = $('<div></div>').addClass('toast-item-close').prependTo(toastItemInner).html(localSettings.closeText).click(function() { $().toastmessage('removeToast',toastItemInner, localSettings) });
toastItemImage = $('<div></div>').addClass('toast-item-image').addClass('toast-item-image-' + localSettings.type).prependTo(toastItemInner);

if(navigator.userAgent.match(/MSIE 6/i))
if(navigator.userAgent.match(/MSIE 6/i))
{
toastWrapAll.css({top: document.documentElement.scrollTop});
}
toastWrapAll.css({top: document.documentElement.scrollTop});
}

if(!localSettings.sticky)
{
Expand All @@ -102,32 +111,32 @@
},
localSettings.stayTime);
}
return toastItemInner;
return toastItemInner;
},

showNoticeToast : function (message)
{
var options = {text : message, type : 'notice'};
return $().toastmessage('showToast', options);
},
showNoticeToast : function (message)
{
var options = {text : message, type : 'notice'};
return $().toastmessage('showToast', options);
},

showSuccessToast : function (message)
{
var options = {text : message, type : 'success'};
return $().toastmessage('showToast', options);
},
showSuccessToast : function (message)
{
var options = {text : message, type : 'success'};
return $().toastmessage('showToast', options);
},

showErrorToast : function (message)
{
var options = {text : message, type : 'error'};
return $().toastmessage('showToast', options);
},
showErrorToast : function (message)
{
var options = {text : message, type : 'error'};
return $().toastmessage('showToast', options);
},

showWarningToast : function (message)
{
var options = {text : message, type : 'warning'};
return $().toastmessage('showToast', options);
},
showWarningToast : function (message)
{
var options = {text : message, type : 'warning'};
return $().toastmessage('showToast', options);
},

removeToast: function(obj, options)
{
Expand All @@ -138,24 +147,24 @@
obj.parent().remove();
});
});
// callback
if (options && options.close !== null)
{
options.close();
}
// callback
if (options && options.close !== null)
{
options.close();
}
}
};

$.fn.toastmessage = function( method ) {
$.fn.toastmessage = function( method ) {

// Method calling logic
if ( methods[method] ) {
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.toastmessage' );
}
};
// Method calling logic
if ( methods[method] ) {
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.toastmessage' );
}
};

})(jQuery);
19 changes: 19 additions & 0 deletions src/main/resources/css/jquery.toastmessage.css
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,22 @@
margin-top: -40px;
top: 50%;
}

.toast-position-bottom-left {
position: fixed;
left: 20px;
bottom: 20px;
}

.toast-position-bottom-center {
position: fixed;
left: 50%;
margin-left: -140px;
bottom: 20px;
}

.toast-position-bottom-right {
position: fixed;
right: 20px;
bottom: 20px;
}