2011-08-09 00:50:48 +03:00
|
|
|
|
|
|
|
(function ($) {
|
|
|
|
|
|
|
|
$.extend($.gritter.options, {
|
|
|
|
fade_in_speed: 'medium', // how fast notifications fade in (string or int)
|
|
|
|
fade_out_speed: 'medium', // how fast the notices fade out
|
2011-12-04 03:01:00 +03:00
|
|
|
time: 4000, // hang on the screen for...
|
2011-08-09 00:50:48 +03:00
|
|
|
sticky: false
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$.ajaxPrefilter(function (options, originalOptions, jqXHR) {
|
|
|
|
|
|
|
|
jqXHR.success(function (data) {
|
2012-01-19 06:58:32 +03:00
|
|
|
if (data.NotificationType === 0) {
|
|
|
|
$.gritter.add({
|
|
|
|
title: data.Title,
|
|
|
|
text: data.Text,
|
|
|
|
image: '../../content/images/success.png',
|
|
|
|
class_name: 'gritter-success'
|
|
|
|
});
|
2011-08-09 00:50:48 +03:00
|
|
|
}
|
2012-01-19 06:58:32 +03:00
|
|
|
else if (data.NotificationType === 1) {
|
|
|
|
$.gritter.add({
|
|
|
|
title: data.Title,
|
|
|
|
text: data.Text,
|
|
|
|
image: '../../content/images/error.png',
|
|
|
|
class_name: 'gritter-fail',
|
|
|
|
time: 10000
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-08-09 00:50:48 +03:00
|
|
|
});
|
|
|
|
|
2012-01-30 04:38:44 +03:00
|
|
|
jqXHR.error(function (xhr, textStatus, thrownError) {
|
2011-08-09 00:50:48 +03:00
|
|
|
//ignore notification errors.
|
2012-04-23 10:38:42 +03:00
|
|
|
if (this.url.indexOf("/notification/Comet") === 0 || this.url.indexOf("/Health/Index") === 0 || this.url.indexOf("/signalr") === 0)
|
2012-02-29 03:59:48 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
$.gritter.add({
|
|
|
|
title: 'Request failed',
|
2012-10-01 03:05:16 +03:00
|
|
|
text: 'Url: ' + this.url + '<br/>Error: ' + thrownError,
|
2012-02-29 03:59:48 +03:00
|
|
|
image: '../../content/images/error.png',
|
|
|
|
class_name: 'gritter-fail',
|
|
|
|
time: 10000
|
|
|
|
});
|
2011-08-09 00:50:48 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
} (jQuery));
|
|
|
|
|
|
|
|
|
|
|
|
$(window).load(function () {
|
2011-07-02 11:56:58 +03:00
|
|
|
var speed = 700;
|
2011-04-24 08:48:12 +03:00
|
|
|
var isShown = false;
|
2011-07-02 11:56:58 +03:00
|
|
|
var currentMessage = "";
|
|
|
|
|
2011-07-11 09:51:13 +03:00
|
|
|
//workaround for the infinite browser load in chrome
|
|
|
|
if ($.browser.webkit) {
|
|
|
|
$.doTimeout(1000, refreshNotifications);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
refreshNotifications();
|
|
|
|
}
|
2011-08-09 00:50:48 +03:00
|
|
|
|
2010-10-18 09:06:16 +03:00
|
|
|
function refreshNotifications() {
|
2011-12-19 03:07:41 +03:00
|
|
|
$.ajax({
|
|
|
|
url: '/notification/Comet',
|
|
|
|
data: { message: currentMessage },
|
|
|
|
success: function (data) {
|
|
|
|
notificationCallback(data);
|
2012-02-29 03:59:48 +03:00
|
|
|
},
|
|
|
|
error: function () {
|
|
|
|
$.doTimeout(5000, refreshNotifications);
|
2011-12-19 03:07:41 +03:00
|
|
|
}
|
|
|
|
});
|
2010-10-18 09:06:16 +03:00
|
|
|
}
|
2010-10-12 05:49:27 +03:00
|
|
|
|
2010-10-18 09:06:16 +03:00
|
|
|
function notificationCallback(data) {
|
2011-07-02 11:56:58 +03:00
|
|
|
currentMessage = data;
|
2010-10-12 05:49:27 +03:00
|
|
|
|
2010-10-18 09:06:16 +03:00
|
|
|
if (data === "") {
|
2011-07-02 11:56:58 +03:00
|
|
|
closeMsg();
|
2010-10-12 05:49:27 +03:00
|
|
|
}
|
2010-10-18 09:06:16 +03:00
|
|
|
else {
|
2011-07-02 11:56:58 +03:00
|
|
|
displayMsg(data);
|
2010-10-12 05:49:27 +03:00
|
|
|
}
|
2011-07-02 11:56:58 +03:00
|
|
|
|
|
|
|
refreshNotifications();
|
2010-10-18 09:06:16 +03:00
|
|
|
}
|
2010-10-12 05:49:27 +03:00
|
|
|
|
2010-10-18 09:06:16 +03:00
|
|
|
//SetupNotifications();
|
2011-07-02 11:56:58 +03:00
|
|
|
function displayMsg(sMsg) {
|
2010-10-18 09:06:16 +03:00
|
|
|
//set the message text
|
2011-07-02 11:56:58 +03:00
|
|
|
$("#msgText").showHtml(sMsg, 150);
|
2011-04-24 08:48:12 +03:00
|
|
|
|
|
|
|
if (!isShown) {
|
2011-07-02 11:56:58 +03:00
|
|
|
$('#msgBox').show("slide", { direction: "right" }, speed / 2);
|
2011-04-24 08:48:12 +03:00
|
|
|
}
|
2011-07-02 11:56:58 +03:00
|
|
|
|
|
|
|
isShown = true;
|
2010-10-18 09:06:16 +03:00
|
|
|
}
|
2010-10-12 05:49:27 +03:00
|
|
|
|
2011-07-02 11:56:58 +03:00
|
|
|
function closeMsg() {
|
2011-07-02 20:41:10 +03:00
|
|
|
//hide the message
|
|
|
|
if (isShown) {
|
|
|
|
$('#msgBox').hide("slide", { direction: "right" }, speed);
|
|
|
|
isShown = false;
|
|
|
|
}
|
2010-10-18 09:06:16 +03:00
|
|
|
}
|
|
|
|
});
|
2010-10-12 05:49:27 +03:00
|
|
|
|
|
|
|
|
2011-04-24 08:48:12 +03: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 22:22:17 +03:00
|
|
|
var finish = { width: 'auto', height: 'auto' };
|
2011-04-24 08:48:12 +03: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);
|