summaryrefslogtreecommitdiffstats
path: root/js/app/directives/undonotification.coffee
diff options
context:
space:
mode:
Diffstat (limited to 'js/app/directives/undonotification.coffee')
-rw-r--r--js/app/directives/undonotification.coffee32
1 files changed, 20 insertions, 12 deletions
diff --git a/js/app/directives/undonotification.coffee b/js/app/directives/undonotification.coffee
index 5e30af169..acf3f886d 100644
--- a/js/app/directives/undonotification.coffee
+++ b/js/app/directives/undonotification.coffee
@@ -20,23 +20,22 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
###
-angular.module('News').directive 'undoNotification', ['$rootScope',
-($rootScope) ->
+angular.module('News').directive 'undoNotification',
+['$rootScope', '$timeout', 'Config',
+($rootScope, $timeout, Config) ->
return (scope, elm, attr) ->
-
- elm.click ->
- $(@).fadeOut()
-
- scope.$on 'notUndone', ->
- $(elm).fadeOut()
-
undo = ->
caption = ''
+ timeout = null
+
+ $(elm).click ->
+ timout = null
+ $(@).fadeOut()
- link = $(elm).find('a')
- link.click ->
+ $(elm).find('a').click ->
undo()
+ timout = null
$rootScope.$apply()
elm.fadeOut()
@@ -44,9 +43,18 @@ angular.module('News').directive 'undoNotification', ['$rootScope',
return caption
scope.$on 'undoMessage', (scope, data) ->
+ # cancel previous timeouts
+ if timeout
+ $timeout.cancel(timeout.promise)
+
+ # fade out if not reset with a new
+ timeout = $timeout =>
+ $(elm).fadeOut()
+ , Config.undoTimeout
+
undo = data.undoCallback
caption = data.caption
- elm.fadeIn().css("display","inline")
+ $(elm).fadeIn().css("display","inline")
] \ No newline at end of file