From 11aa571751015b31332e2c113c238a050928b191 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Sat, 21 Jul 2012 14:24:26 +0200 Subject: [PATCH] Added option to notify method. --- apps/contacts/js/contacts.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/apps/contacts/js/contacts.js b/apps/contacts/js/contacts.js index 8d88149876..130d6b6431 100644 --- a/apps/contacts/js/contacts.js +++ b/apps/contacts/js/contacts.js @@ -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'));