szurubooru/public_html/js/Presenters/MessagePresenter.js

55 lines
1.1 KiB
JavaScript
Raw Normal View History

2014-08-31 23:22:56 +02:00
var App = App || {};
App.Presenters = App.Presenters || {};
App.Presenters.MessagePresenter = function(_, jQuery) {
var options = {
instant: false
};
2014-08-31 23:22:56 +02:00
function showInfo($el, message) {
return showMessage($el, 'info', message);
2014-09-08 22:02:28 +02:00
}
2014-08-31 23:22:56 +02:00
function showError($el, message) {
return showMessage($el, 'error', message);
2014-09-08 22:02:28 +02:00
}
2014-08-31 23:22:56 +02:00
function hideMessages($el) {
var $messages = $el.children('.message');
if (options.instant) {
$messages.each(function() {
jQuery(this).slideUp('fast', function() {
jQuery(this).remove();
});
2014-08-31 23:22:56 +02:00
});
} else {
$messages.remove();
}
2014-09-08 22:02:28 +02:00
}
2014-08-31 23:22:56 +02:00
function showMessage($el, className, message) {
2014-09-08 22:02:28 +02:00
var $messageDiv = jQuery('<div>');
2014-08-31 23:22:56 +02:00
$messageDiv.addClass('message');
$messageDiv.addClass(className);
$messageDiv.html(message);
if (!options.instant) {
$messageDiv.hide();
}
2014-08-31 23:22:56 +02:00
$el.append($messageDiv);
if (!options.instant) {
$messageDiv.slideDown('fast');
}
2014-08-31 23:22:56 +02:00
return $messageDiv;
2014-09-08 22:02:28 +02:00
}
2014-08-31 23:22:56 +02:00
return _.extend(options, {
2014-08-31 23:22:56 +02:00
showInfo: showInfo,
showError: showError,
hideMessages: hideMessages,
});
2014-08-31 23:22:56 +02:00
};
App.DI.register('messagePresenter', ['_', 'jQuery'], App.Presenters.MessagePresenter);