1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-14 15:03:42 +01:00
Radarr/NzbDrone.Web/Scripts/Notification.js

96 lines
2.8 KiB
JavaScript
Raw Normal View History

2011-07-03 00:19:23 +02:00
$(document).ready(function () {
var speed = 700;
2011-04-24 07:48:12 +02:00
var isShown = false;
var currentMessage = "";
2011-07-03 00:19:23 +02:00
$.doTimeout(500, refreshNotifications);
2010-10-12 04:49:27 +02:00
2010-10-18 08:06:16 +02:00
function refreshNotifications() {
$.get('/notification/Comet', { message: currentMessage }, notificationCallback);
2010-10-18 08:06:16 +02:00
}
2010-10-12 04:49:27 +02:00
2010-10-18 08:06:16 +02:00
function notificationCallback(data) {
currentMessage = data;
2010-10-12 04:49:27 +02:00
2010-10-18 08:06:16 +02:00
if (data === "") {
closeMsg();
2010-10-12 04:49:27 +02:00
}
2010-10-18 08:06:16 +02:00
else {
displayMsg(data);
2010-10-12 04:49:27 +02:00
}
refreshNotifications();
2010-10-18 08:06:16 +02:00
}
2010-10-12 04:49:27 +02:00
2010-10-18 08:06:16 +02:00
//SetupNotifications();
//DisplayMsg("Scanning Series Folder.");
2010-10-12 04:49:27 +02:00
2011-04-24 07:48:12 +02:00
function displayMsg(sMsg) {
2010-10-18 08:06:16 +02:00
//set the message text
$("#msgText").showHtml(sMsg, 150);
2011-04-24 07:48:12 +02:00
if (!isShown) {
$('#msgBox').show("slide", { direction: "right" }, speed / 2);
2011-04-24 07:48:12 +02:00
}
isShown = true;
2010-10-18 08:06:16 +02:00
}
2010-10-12 04:49:27 +02:00
function closeMsg() {
2011-07-02 19:41:10 +02:00
//hide the message
if (isShown) {
$('#msgBox').hide("slide", { direction: "right" }, speed);
isShown = false;
}
2010-10-18 08:06:16 +02:00
}
});
2010-10-12 04:49:27 +02:00
2011-04-24 07:48:12 +02:00
// Animates the dimensional changes resulting from altering element contents
// Usage examples:
// $("#myElement").showHtml("new HTML contents");
// $("div").showHtml("new HTML contents", 400);
// $(".className").showHtml("new HTML contents", 400,
// function() {/* on completion */});
(function ($) {
$.fn.showHtml = function (html, speed, callback) {
return this.each(function () {
// The element to be modified
var el = $(this);
// Preserve the original values of width and height - they'll need
// to be modified during the animation, but can be restored once
// the animation has completed.
2011-07-02 21:22:17 +02:00
var finish = { width: 'auto', height: 'auto' };
2011-04-24 07:48:12 +02:00
// The original width and height represented as pixel values.
// These will only be the same as `finish` if this element had its
// dimensions specified explicitly and in pixels. Of course, if that
// was done then this entire routine is pointless, as the dimensions
// won't change when the content is changed.
var cur = { width: el.width() + 'px', height: el.height() + 'px' };
// Modify the element's contents. Element will resize.
el.html(html);
// Capture the final dimensions of the element
// (with initial style settings still in effect)
var next = { width: el.width() + 'px', height: el.height() + 'px' };
el.css(cur) // restore initial dimensions
.animate(next, speed, function () // animate to final dimensions
{
el.css(finish); // restore initial style settings
if ($.isFunction(callback)) callback();
});
});
};
})(jQuery);