]> source.dussan.org Git - nextcloud-server.git/commitdiff
Added option to notify method.
authorThomas Tanghus <thomas@tanghus.net>
Sat, 21 Jul 2012 12:24:26 +0000 (14:24 +0200)
committerThomas Tanghus <thomas@tanghus.net>
Sat, 21 Jul 2012 12:24:26 +0000 (14:24 +0200)
apps/contacts/js/contacts.js

index 8d881498768e4ab4369e0fb1c54f472b981a94ec..130d6b64319c86691c6a20e08d3e3101d1fd5dfd 100644 (file)
@@ -12,10 +12,28 @@ String.prototype.strip_tags = function(){
 
 Contacts={
        UI:{
+               /**
+                * Arguments:
+                * message: The text message to show. The only mandatory parameter.
+                * timeout: The timeout in seconds before the notification disappears. Default 10.
+                * timeouthandler: A function to run on timeout.
+                * clickhandler: A function to run on click. If a timeouthandler is given it will be cancelled.
+                */
                notify:function(params) {
-                       $('#notification').text(params.message);
-                       $('#notification').fadeIn();
-                       setTimeout(function() {$('#notification').fadeOut();}, 10000);
+                       var notifier = $('#notification');
+                       notifier.text(params.message);
+                       notifier.fadeIn();
+                       var timer = setTimeout(function() {
+                               notifier.fadeOut();
+                               if(params.timeouthandler && $.isFunction(params.timeouthandler)) { params.timeouthandler();}
+                       }, params.timeout && $.isNumeric(params.timeout) ? parseInt(params.timeout)*1000 : 10000);
+                       if(params.clickhandler && $.isFunction(params.clickhandler)) {
+                               notifier.on('click', function() {
+                                       clearTimeout(timer);
+                                       notifier.off('click');
+                                       params.clickhandler();
+                               });
+                       }
                },
                notImplemented:function() {
                        OC.dialogs.alert(t('contacts', 'Sorry, this functionality has not been implemented yet'), t('contacts', 'Not implemented'));