gritter: Improve animations

fix recently introduced bug by myself where all gritter were removed when first removed.
Display container at the top
This commit is contained in:
Sebastian Castro 2020-04-06 18:21:39 +02:00 committed by muxator
parent 559a48221e
commit 9b60bb4d55
4 changed files with 41 additions and 51 deletions

View file

@ -1,19 +1,20 @@
#gritter-container { #gritter-container {
position: absolute; position: absolute;
bottom: 0; bottom: 0;
right: 0; right: 50%;
left: 0; transform: translateX(50%);
text-align: center; text-align: center;
z-index: 9999; z-index: 9999;
} }
.gritter-item.popup { .gritter-item.popup {
position: relative; position: relative;
max-width: 400px; max-width: 450px;
min-width: 0;
margin: 0 auto;
visibility: visible; visibility: visible;
right: auto;
left: auto;
top: auto; top: auto;
bottom: auto;
} }
.gritter-item .popup-content { .gritter-item .popup-content {
display: flex; display: flex;
@ -24,14 +25,9 @@
} }
.gritter-item .gritter-close { .gritter-item .gritter-close {
display: none;
align-self: center; align-self: center;
} }
.gritter-item.sticky .gritter-close {
display: block;
}
.gritter-item.error .popup-content { .gritter-item.error .popup-content {
color: #a84341; color: #a84341;
background-color: #eed3d4; background-color: #eed3d4;

View file

@ -23,7 +23,7 @@
$.gritter.options = { $.gritter.options = {
position: '', position: '',
class_name: '', // could be set to 'gritter-light' to use white notifications class_name: '', // could be set to 'gritter-light' to use white notifications
time: 6000 // hang on the screen for... time: 3000 // hang on the screen for...
} }
/** /**
@ -68,8 +68,6 @@
var Gritter = { var Gritter = {
// Public - options to over-ride with $.gritter.options in "add" // Public - options to over-ride with $.gritter.options in "add"
fade_in_speed: '300',
fade_out_speed: '200',
time: '', time: '',
// Private - no touchy the private parts // Private - no touchy the private parts
@ -86,7 +84,7 @@
'[[title]]', '[[title]]',
'<p>[[text]]</p>', '<p>[[text]]</p>',
'</div>', '</div>',
'<div class="gritter-close"><i class="buttonicon buttonicon-cancel"></i></div>', '<div class="gritter-close"><i class="buttonicon buttonicon-times"></i></div>',
'</div>', '</div>',
'</div>'].join(''), '</div>'].join(''),
@ -164,27 +162,19 @@
var item = $('#gritter-item-' + this._item_count); var item = $('#gritter-item-' + this._item_count);
item.addClass('popup-show').fadeIn(this.fade_in_speed, function(){ setTimeout(function() { item.addClass('popup-show'); }, 0);
Gritter['_after_open_' + number]($(this)); Gritter['_after_open_' + number](item);
});
if(!sticky){ if(!sticky){
this._setFadeTimer(item, number); this._setFadeTimer(item, number);
}
// Bind the hover/unhover states // Bind the hover/unhover states
$(item).bind('mouseenter mouseleave', function(event){ $(item).on('mouseenter', function(event) {
if(event.type == 'mouseenter'){
if(!sticky){
Gritter._restoreItemIfFading($(this), number); Gritter._restoreItemIfFading($(this), number);
}
}
else {
if(!sticky){
Gritter._setFadeTimer($(this), number);
}
}
}); });
$(item).on('mouseleave', function(event) {
Gritter._setFadeTimer($(this), number);
});
}
// Clicking (X) makes the perdy thing close // Clicking (X) makes the perdy thing close
$(item).find('.gritter-close').click(function(){ $(item).find('.gritter-close').click(function(){
@ -208,11 +198,10 @@
e.remove(); e.remove();
this['_after_close_' + unique_id](e, manual_close); this['_after_close_' + unique_id](e, manual_close);
// Check if the wrapper is empty, if it is.. remove the wrapper // Remove container if empty
if($('.gritter-item-wrapper').length == 0){ if ($('#gritter-container .gritter-item').length == 0) {
$('#gritter-container').remove(); $('#gritter-container').remove();
} }
}, },
/** /**
@ -220,14 +209,13 @@
* @private * @private
* @param {Object} e The jQuery element to get rid of * @param {Object} e The jQuery element to get rid of
* @param {Integer} unique_id The id of the element to remove * @param {Integer} unique_id The id of the element to remove
* @param {Object} params An optional list of params to set fade speeds etc. * @param {Object} params An optional list of params.
* @param {Boolean} unbind_events Unbind the mouseenter/mouseleave events if they click (X) * @param {Boolean} unbind_events Unbind the mouseenter/mouseleave events if they click (X)
*/ */
_fade: function(e, unique_id, params, unbind_events){ _fade: function(e, unique_id, params, unbind_events){
var params = params || {}, var params = params || {},
fade = (typeof(params.fade) != 'undefined') ? params.fade : true, fade = (typeof(params.fade) != 'undefined') ? params.fade : true,
fade_out_speed = params.speed || this.fade_out_speed,
manual_close = unbind_events; manual_close = unbind_events;
this['_before_close_' + unique_id](e, manual_close); this['_before_close_' + unique_id](e, manual_close);
@ -239,15 +227,10 @@
// Fade it out or remove it // Fade it out or remove it
if(fade){ if(fade){
e.removeClass('popup-show');
e.animate({ setTimeout(function() {
opacity: 0
}, fade_out_speed, function(){
e.animate({ height: 0 }, 300, function(){
Gritter._countRemoveWrapper(unique_id, e, manual_close); Gritter._countRemoveWrapper(unique_id, e, manual_close);
}) }, 300)
}).removeClass('popup-show')
} }
else { else {
@ -308,11 +291,11 @@
* @param {Object} item The HTML element we're dealing with * @param {Object} item The HTML element we're dealing with
* @param {Integer} unique_id The ID of the element * @param {Integer} unique_id The ID of the element
*/ */
_setFadeTimer: function(e, unique_id){ _setFadeTimer: function(item, unique_id){
var timer_str = (this._custom_timer) ? this._custom_timer : this.time; var timer_str = (this._custom_timer) ? this._custom_timer : this.time;
this['_int_id_' + unique_id] = setTimeout(function(){ this['_int_id_' + unique_id] = setTimeout(function(){
Gritter._fade(e, unique_id); Gritter._fade(item, unique_id);
}, timer_str); }, timer_str);
}, },

View file

@ -24,9 +24,7 @@ exports.saveNow = function(){
// (string | mandatory) the text inside the notification // (string | mandatory) the text inside the notification
text: _("pad.savedrevs.timeslider") || "You can view saved revisions in the timeslider", text: _("pad.savedrevs.timeslider") || "You can view saved revisions in the timeslider",
// (bool | optional) if you want it to fade out on its own or just sit there // (bool | optional) if you want it to fade out on its own or just sit there
sticky: false, sticky: false
// (int | optional) the time you want it to be alive for before fading out
time: '2000'
}); });
} }

View file

@ -1,3 +1,7 @@
#gritter-container {
top: 20px;
bottom: auto;
}
.gritter-item .popup-content { .gritter-item .popup-content {
color: white; color: white;
margin-bottom: 10px; margin-bottom: 10px;
@ -7,7 +11,7 @@
margin: 0; margin: 0;
} }
.gritter-item .gritter-title { .gritter-item .gritter-title {
margin-bottom: 20px; margin-bottom: 10px;
} }
.gritter-item .gritter-close { .gritter-item .gritter-close {
margin-left: 10px; margin-left: 10px;
@ -22,3 +26,12 @@
margin-bottom: 0; margin-bottom: 0;
} }
} }
.gritter-item.popup > .popup-content {
transform: scale(0.8) translateY(-100px);
}
.gritter-item.popup.popup-show > .popup-content {
transform: scale(1) translateY(0);
transition: all 0.4s cubic-bezier(0.74, -0.05, 0.27, 1.75)
}