Skip to content

Buttons disable timeout config #193

Closed
thomasf1 opened this Issue Mar 14, 2014 · 1 comment

2 participants

@thomasf1

I´m trying to add an undo button or link to a notification. (Inspired by http://www.goodui.org/ item 8).

It seems noty ignores the timeout supplied when a button is set (which in most cases makes sense, just not in my use-case). Not sure that´s intentional or not. A workaround is to close the noty by ID with a setTimeout.

#coffeescript
x = noty
  text: "Item y deleted"
  timeout: 2000 #Doesn´t work
  buttons: [
    {
      addClass: "btn btn-primary"
      text: "undo"
      onClick: ($noty) ->
        $noty.close()
        noty
          text: "Delete aborted"
          type: "success"
          timeout: 1000
    }
  ]

#works - delay is a helper function that calls setTimeout with reversed params (much nicher in coffee)
delay 2000, ->
  x.close()
@thomasf1

I´ve worked around that now with a template. Works well, looks subtle.

#coffeescript
aborted = false

x = noty
  text: msg
  timeout: timeout
  type: type
  template: '<div class="noty_message"><span class="noty_text"></span><a style="float:right">undo</a><div class="noty_close"></div></div>',
  callback:
    afterClose: ->
      unless aborted
        action()

x.$message.find("a").click ->
  aborted = true
  noty
    text: undoMsg
    type: undoType
    timeout: 1000
@needim needim closed this Dec 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.