(function ($) { $.jnotify = { defaults: { autohide: true, clickoverlay: false, minwidth: 200, timeshown: 1500, showtimeeffect: 200, hidetimeeffect: 200, longtrip: 15, horizontalposition: 'right', verticalposition: 'bottom', showoverlay: true, coloroverlay: '#000', opacityoverlay: 0.3, onclosed: null, oncompleted: null }, init: function (msg, options, id) { opts = $.extend({}, $.jnotify.defaults, options); if ($("#" + id).length == 0) $div = $.jnotify._construct(id, msg); widthdoc = parseint($(window).width()); heightdoc = parseint($(window).height()); scrolltop = parseint($(window).scrolltop()); scrollleft = parseint($(window).scrollleft()); postop = $.jnotify.vpos(opts.verticalposition); posleft = $.jnotify.hpos(opts.horizontalposition); if (opts.showoverlay && $("#joverlay").length == 0) $.jnotify._showoverlay($div); $.jnotify._show(msg); }, _construct: function (id, msg) { $div = $('
').css({ opacity: 0, minwidth: opts.minwidth }).html(msg).appendto('body'); return $div; }, vpos: function (pos) { switch (pos) { case 'top': var vpos = scrolltop + parseint($div.outerheight(true) / 2); break; case 'center': var vpos = scrolltop + (heightdoc / 2) - (parseint($div.outerheight(true)) / 2); break; case 'bottom': var vpos = scrolltop + heightdoc - parseint($div.outerheight(true)); break; } return vpos; }, hpos: function (pos) { switch (pos) { case 'left': var hpos = scrollleft; break; case 'center': var hpos = scrollleft + (widthdoc / 2) - (parseint($div.outerwidth(true)) / 2); break; case 'right': var hpos = scrollleft + widthdoc - parseint($div.outerwidth(true)); break; } return hpos; }, _show: function (msg) { $div.css({ top: postop, left: posleft }); switch (opts.verticalposition) { case 'top': $div.animate({ top: postop + opts.longtrip, opacity: 1 }, opts.showtimeeffect, function () { if (opts.oncompleted) opts.oncompleted(); }); if (opts.autohide) $.jnotify._close(); else $div.css('cursor', 'pointer').click(function (e) { $.jnotify._close(); }); break; case 'center': $div.animate({ opacity: 1 }, opts.showtimeeffect, function () { if (opts.oncompleted) opts.oncompleted(); }); if (opts.autohide) $.jnotify._close(); else $div.css('cursor', 'pointer').click(function (e) { $.jnotify._close(); }); break; case 'bottom': $div.animate({ top: postop - opts.longtrip, opacity: 1 }, opts.showtimeeffect, function () { if (opts.oncompleted) opts.oncompleted(); }); if (opts.autohide) $.jnotify._close(); else $div.css('cursor', 'pointer').click(function (e) { $.jnotify._close(); }); break; } }, _showoverlay: function (el) { var overlay = $('').css({ backgroundcolor: opts.coloroverlay, opacity: opts.opacityoverlay }).appendto('body').show(); if (opts.clickoverlay) overlay.click(function (e) { e.preventdefault(); $.jnotify._close(); }); }, _close: function () { switch (opts.verticalposition) { case 'top': if (!opts.autohide) opts.timeshown = 0; $div.delay(opts.timeshown).animate({ top: postop - opts.longtrip, opacity: 0 }, opts.hidetimeeffect, function () { $(this).remove(); if (opts.showoverlay && $("#joverlay").length > 0) $("#joverlay").remove(); if (opts.onclosed) opts.onclosed(); }); break; case 'center': if (!opts.autohide) opts.timeshown = 0; $div.delay(opts.timeshown).animate({ opacity: 0 }, opts.hidetimeeffect, function () { $(this).remove(); if (opts.showoverlay && $("#joverlay").length > 0) $("#joverlay").remove(); if (opts.onclosed) opts.onclosed(); }); break; case 'bottom': if (!opts.autohide) opts.timeshown = 0; $div.delay(opts.timeshown).animate({ top: postop + opts.longtrip, opacity: 0 }, opts.hidetimeeffect, function () { $(this).remove(); if (opts.showoverlay && $("#joverlay").length > 0) $("#joverlay").remove(); if (opts.onclosed) opts.onclosed(); }); break; } }, _isreadable: function (id) { if ($('#' + id).length > 0) return false; else return true; } }; jnotify = function (msg, options) { if ($.jnotify._isreadable('jnotify')) $.jnotify.init(msg, options, 'jnotify'); }; jsuccess = function (msg, options) { if ($.jnotify._isreadable('jsuccess')) $.jnotify.init(msg, options, 'jsuccess'); }; jerror = function (msg, options) { if ($.jnotify._isreadable('jerror')) $.jnotify.init(msg, options, 'jerror'); }; })(jquery);