mirror of https://github.com/zulip/zulip.git
feedback widget: Avoid duplicate handlers.
We only need these once, not during every show() call. We actually were only setting up the click handlers one time, but we had redundant mouse handlers. More importantly, we stop a runaway timer that tries to fade out our feedback widget every 100ms or ten times per second!
This commit is contained in:
parent
39cdc926a5
commit
4468311620
|
@ -30,39 +30,73 @@ exports.build_feedback_widget = function () {
|
|||
hide_me_time: null,
|
||||
alert_hover_state: false,
|
||||
$container: null,
|
||||
opened: false,
|
||||
};
|
||||
|
||||
var animate = {
|
||||
fadeOut: function () {
|
||||
if (meta.$container) {
|
||||
meta.$container.fadeOut(500).removeClass("show");
|
||||
}
|
||||
},
|
||||
fadeIn: function () {
|
||||
if (meta.$container) {
|
||||
meta.$container.fadeIn(500).addClass("show");
|
||||
}
|
||||
},
|
||||
};
|
||||
setInterval(function () {
|
||||
if (meta.hide_me_time < new Date().getTime() && !meta.alert_hover_state) {
|
||||
animate.fadeOut();
|
||||
}
|
||||
}, 100);
|
||||
|
||||
self.dismiss = function () {
|
||||
animate.fadeOut();
|
||||
};
|
||||
|
||||
self.show = function (opts) {
|
||||
if (!opts.populate) {
|
||||
blueslip.error('programmer needs to supply populate callback.');
|
||||
maybe_close: function () {
|
||||
if (!meta.opened) {
|
||||
return;
|
||||
}
|
||||
|
||||
meta.undo = opts.on_undo;
|
||||
if (meta.hide_me_time < new Date().getTime() && !meta.alert_hover_state) {
|
||||
animate.fadeOut();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!meta.$container) {
|
||||
meta.$container = $("#feedback_container");
|
||||
setTimeout(animate.maybe_close, 100);
|
||||
},
|
||||
fadeOut: function () {
|
||||
if (!meta.opened) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (meta.$container) {
|
||||
meta.$container.fadeOut(500).removeClass("show");
|
||||
meta.opened = false;
|
||||
meta.alert_hover_state = false;
|
||||
}
|
||||
},
|
||||
fadeIn: function () {
|
||||
if (meta.opened) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (meta.$container) {
|
||||
meta.$container.fadeIn(500).addClass("show");
|
||||
meta.opened = true;
|
||||
setTimeout(animate.maybe_close, 100);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function set_up_handlers() {
|
||||
if (meta.handlers_set) {
|
||||
return;
|
||||
}
|
||||
|
||||
meta.handlers_set = true;
|
||||
|
||||
// if the user mouses over the notification, don't hide it.
|
||||
meta.$container.mouseenter(function () {
|
||||
if (!meta.opened) {
|
||||
return;
|
||||
}
|
||||
|
||||
meta.alert_hover_state = true;
|
||||
});
|
||||
|
||||
// once the user's mouse leaves the notification, restart the countdown.
|
||||
meta.$container.mouseleave(function () {
|
||||
if (!meta.opened) {
|
||||
return;
|
||||
}
|
||||
|
||||
meta.alert_hover_state = false;
|
||||
// add at least 2000ms but if more than that exists just keep the
|
||||
// current amount.
|
||||
meta.hide_me_time = Math.max(meta.hide_me_time, new Date().getTime() + 2000);
|
||||
});
|
||||
|
||||
meta.$container.find('.exit-me').click(function () {
|
||||
animate.fadeOut();
|
||||
|
@ -76,6 +110,22 @@ exports.build_feedback_widget = function () {
|
|||
});
|
||||
}
|
||||
|
||||
self.dismiss = function () {
|
||||
animate.fadeOut();
|
||||
};
|
||||
|
||||
self.show = function (opts) {
|
||||
if (!opts.populate) {
|
||||
blueslip.error('programmer needs to supply populate callback.');
|
||||
return;
|
||||
}
|
||||
|
||||
meta.$container = $('#feedback_container');
|
||||
|
||||
set_up_handlers();
|
||||
|
||||
meta.undo = opts.on_undo;
|
||||
|
||||
// add a four second delay before closing up.
|
||||
meta.hide_me_time = new Date().getTime() + 4000;
|
||||
|
||||
|
@ -85,18 +135,6 @@ exports.build_feedback_widget = function () {
|
|||
|
||||
animate.fadeIn();
|
||||
|
||||
// if the user mouses over the notification, don't hide it.
|
||||
meta.$container.mouseenter(function () {
|
||||
meta.alert_hover_state = true;
|
||||
});
|
||||
|
||||
// once the user's mouse leaves the notification, restart the countdown.
|
||||
meta.$container.mouseleave(function () {
|
||||
meta.alert_hover_state = false;
|
||||
// add at least 2000ms but if more than that exists just keep the
|
||||
// current amount.
|
||||
meta.hide_me_time = Math.max(meta.hide_me_time, new Date().getTime() + 2000);
|
||||
});
|
||||
};
|
||||
|
||||
return self;
|
||||
|
|
Loading…
Reference in New Issue