diff options
author | Morris Jobke <hey@morrisjobke.de> | 2015-01-07 14:51:20 +0100 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2015-01-08 13:06:45 +0100 |
commit | 8e1904386fe75c77675c882e2d3eca34d5828cec (patch) | |
tree | 157973fb67ae3cd5b6846f94db7ec685d6366625 /core/js/js.js | |
parent | 14e534e93322d3ce3275f04657de40fcf34d61d9 (diff) | |
download | nextcloud-server-8e1904386fe75c77675c882e2d3eca34d5828cec.tar.gz nextcloud-server-8e1904386fe75c77675c882e2d3eca34d5828cec.zip |
Add timeout for notifications
* options for timeout in seconds and if it contains HTML
* if timeout is 0 it will show the message permanently
* removes the notification after a given (default: 5 seconds) timeframe
* based on work by @brantje
* provide JS unit tests for notifications
Diffstat (limited to 'core/js/js.js')
-rw-r--r-- | core/js/js.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/core/js/js.js b/core/js/js.js index 8bcd546b420..579bf09b2e4 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -669,6 +669,7 @@ OC.msg={ OC.Notification={ queuedNotifications: [], getDefaultNotificationFunction: null, + notificationTimer: 0, /** * @param callback @@ -731,6 +732,42 @@ OC.Notification={ } }, + + /** + * Shows a notification that disappears after x seconds, default is + * 7 seconds + * @param {string} text Message to show + * @param {array} [options] options array + * @param {int} [options.timeout=7] timeout in seconds, if this is 0 it will show the message permanently + * @param {boolean} [options.isHTML=false] an indicator for HTML notifications (true) or text (false) + */ + showTemporary: function(text, options) { + var defaults = { + isHTML: false, + timeout: 7 + }, + options = options || {}; + // merge defaults with passed in options + _.defaults(options, defaults); + + // clear previous notifications + OC.Notification.hide(); + if(OC.Notification.notificationTimer) { + clearTimeout(OC.Notification.notificationTimer); + } + + if(options.isHTML) { + OC.Notification.showHtml(text); + } else { + OC.Notification.show(text); + } + + if(options.timeout > 0) { + // register timeout to vanish notification + OC.Notification.notificationTimer = setTimeout(OC.Notification.hide, (options.timeout * 1000)); + } + }, + /** * Returns whether a notification is hidden. * @return {boolean} |