Skip to content

Commit

Permalink
Fixes for turbolinks
Browse files Browse the repository at this point in the history
  • Loading branch information
estum committed Sep 3, 2016
1 parent 5f332ea commit 4de82b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
7 changes: 3 additions & 4 deletions app/assets/javascripts/growlyflash/alert.coffee
@@ -1,4 +1,4 @@
class Growlyflash
class @Growlyflash
@debug = off

@defaults =
Expand Down Expand Up @@ -48,7 +48,7 @@ class Growlyflash
html += @flash.msg

@el = ($ '<div>', html: html, class: @class_list().join(' '), role: "alert")
@el.appendTo(target)
@el = @el.appendTo(($ target))

before_show?.call(this)

Expand Down Expand Up @@ -95,5 +95,4 @@ class Growlyflash
Growlyflash[name] ?= Growlyflash[type]
return

window.Growlyflash = Growlyflash
jQuery.growlyflash = Growlyflash.growl
jQuery.growlyflash = Growlyflash.growl
10 changes: 6 additions & 4 deletions app/assets/javascripts/growlyflash/listener.coffee
@@ -1,4 +1,4 @@
class Growlyflash.Listener
class Listener
# Alerts stack
class Stack
constructor: (@items...) ->
Expand All @@ -20,7 +20,7 @@ class Growlyflash.Listener
do @purge

@HEADER = 'X-Message'
@EVENTS = 'ajax:complete ajaxComplete turbolinks:request-end'
@EVENTS = 'ajax:complete ajaxComplete'

process = (alerts = {}) ->
new Growlyflash.FlashStruct(msg, type) for type, msg of alerts when msg?
Expand All @@ -34,11 +34,13 @@ class Growlyflash.Listener
@process_static() if window.flashes?
($ context).on Growlyflash.Listener.EVENTS, (event, xhr) =>
xhr ?= event.data?.xhr
@stack.push_only_fresh process_from_header(xhr.getResponseHeader(Growlyflash.Listener.HEADER))
source = process_from_header(xhr.getResponseHeader(Growlyflash.Listener.HEADER))
@stack.push_only_fresh source

process_static: ->
@stack.push alert for alert in process(window.flashes)
delete window.flashes

Growlyflash.listen_on = (context) ->
@Growlyflash.Listener = Listener
@Growlyflash.listen_on = (context) ->
@listener ?= new @Listener(context)

0 comments on commit 4de82b7

Please sign in to comment.