diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2013-10-27 00:53:53 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2013-10-27 00:53:53 +0400 |
commit | 80bce1089434384e73afe6aea6ce297ef2da2679 (patch) | |
tree | b65f7723217172c756b246f736c6494623cca232 /plugins/CoreHome/javascripts/notification.js | |
parent | fe5cddd90421e3e4d16bb3f10d99fe00ef5c9165 (diff) |
refs #4179 throw errors if invalid params given, handle close event
Diffstat (limited to 'plugins/CoreHome/javascripts/notification.js')
-rw-r--r-- | plugins/CoreHome/javascripts/notification.js | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/plugins/CoreHome/javascripts/notification.js b/plugins/CoreHome/javascripts/notification.js index 92faadfa0e..8a110c5aed 100644 --- a/plugins/CoreHome/javascripts/notification.js +++ b/plugins/CoreHome/javascripts/notification.js @@ -14,10 +14,27 @@ Notification.prototype.show = function (message, options) { if (!message) { - return; + throw new Error('No message given, cannot display notification'); } + if (options && !$.isPlainObject(options)) { + throw new Error('Options has the wrong format, cannot display notification'); + } else if (!options) { + options = {}; + } + + var template = '<div class="notification'; + + if (options.context) { + template += ' notification-' + options.context; + } + + template += '"'; - var template = '<div class="notification notification-' + options.context + ' ">'; + if (options.id) { + template += ' data-id="' + options.id + '"'; + } + + template += '>'; if (!options.noclear) { @@ -29,11 +46,20 @@ } template += message; - template += '</div>'; - $(template).appendTo('#notificationContainer'); + + var notificationNode = $(template).appendTo('#notificationContainer'); + addCloseEvent(notificationNode); }; exports.Notification = Notification; + function addCloseEvent(notificationNode) { + $(notificationNode).on('click', '.close', function (event) { + if (event.delegateTarget) { + $(event.delegateTarget).remove(); + } + }); + }; + })(jQuery, require);
\ No newline at end of file |