growlyflash 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzVlZDcwMDJhN2Y3ZWViNzA5ODkzYTUxMzg0YmUyZGM0ZGQ3NGVhNg==
4
+ MzQzZGRiMGIyNTc2MmM5YjkzN2E3MzkxODdiMDJmMWEyNTI2ZTQyNA==
5
5
  data.tar.gz: !binary |-
6
- ZTI2Nzc3ZDhjODMwODlhODJkYWEyNDQ1MWI0YWQ0OTUzYjBlOGYzZg==
6
+ MzYwMTJhYzVhZmJlZTExNzNkMWFkYWJjMjMwNzYxZmM2YWU2MmQ5YQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MjM4OTMxNjMwNjQ2YjNjZGM1NjZkNmI4NDVjMTdiYTE0MDljZGRmMDVlN2Zj
10
- MjE1OTkzMWE3NmM3NmI1YmJkODFlMWZiNTgyMzc3N2FjMDkxODFmNTMyYmMy
11
- NmI1N2EwYzE2YjU3YTkzNzgyNTIzMjU3YmM5ZTk5Mzk0MjQ3YzY=
9
+ MzRmMGFiYWQyMzIwMDg0ZDAwMmE1N2IwY2NlNzczNWM1MDI4YTEwYTY4M2M2
10
+ YmMwNDQ1OTY3NzE3NWQ0ZmJmNmFkYmM2Njc5YjM0ODc4OWIxNDAwNjNlOTQ1
11
+ MTY0MDIwYWU2M2E1NDJjMTYzNjU5NmY1NDQ5OWQ5ZjBhMTlkMzI=
12
12
  data.tar.gz: !binary |-
13
- ZmNlYjVhOGIwY2NmYjJkNzcwZGMxMGI3MmE1M2ViY2I2NjNkYWZhNjc3NjZi
14
- NDBiNTNjMjM3ZWQyMmRlMGViYWM3MDFmZTljNzQwNzMzYWQ5NjM3NjU3ODQz
15
- ZmZjMWU0MjlmYTY5OTkxMTk2MDFjNWIwOTIzZWFlYjRmMGM1YzI=
13
+ NWE5Yjk0YjAzNzk0YjRiNjA1NThjODg5N2FkMTg2NjgxNGM3NjA4MmViZTBm
14
+ OTEwNzQwMzNmODMxNDlmY2I5YjM5MjUzZWEyMzRkNzI4NDYwM2I5NTQ5MjVj
15
+ ZjM4MzUwYWIyM2Q1YmZhZTMwNDE0MzhmNzhjM2IxZjA4ODAyMDI=
@@ -1,3 +1,3 @@
1
1
  module Growlyflash
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -12,36 +12,46 @@ class Growlyflash
12
12
  constructor: (@context) ->
13
13
  @flash_log = []
14
14
  @growl window.flashes if window.flashes?
15
+ # we have to bind both of ajax-complete events
16
+ # sometimes one of them takes messages and they are skipping
17
+ # but in mostly, they produce duplicates :(
15
18
  $(@context).on 'ajax:complete ajaxComplete', @ajax_complete
16
19
 
17
20
  growl: (flashes) ->
18
21
  for type, msg of flashes when msg?
19
- @log type:type, msg:msg
22
+ @log type: type, msg: msg
20
23
  $.bootstrapGrowl msg, type: TYPE_MAPPING[type]
21
24
 
22
25
  log: (xmessage) -> @flash_log.push(xmessage)
23
- log_is_not_empty: -> @flash_log.length > 0
24
- purge_log: ->
25
- @flash_log = []
26
- true
26
+ log_isnt_empty: -> @flash_log.length > 0
27
+ purge_log: -> @flash_log = []
27
28
 
28
29
  messages: (flashes) ->
29
30
  { type:type, msg:msg } for type, msg of flashes
30
31
 
31
32
  ajax_complete: (e, response, settings) =>
32
- if flashes = @get_x_message.call response
33
+ flashes = @get_x_message.call response
34
+ if flashes?
33
35
  messages = @messages flashes
34
- @reduce_duplicates messages, => @growl flashes
36
+ # Reduce duplicates (because binded twice)
37
+ @reduce_duplicates messages, =>
38
+ @growl flashes
39
+ # To prevent reducing similar messages on
40
+ # the next event, log should flushes after
41
+ window.setTimeout =>
42
+ do @purge_log
43
+ , 100
35
44
  true
36
45
 
46
+ # Parse encoded messages
37
47
  get_x_message: ->
38
48
  encoded = @getResponseHeader 'X-Message'
39
49
  decoded = decodeURIComponent encoded
40
50
  $.parseJSON decoded if decoded?
41
51
 
42
52
  reduce_duplicates: (messages, callback) ->
43
- if @log_is_not_empty()
44
- return @purge_log unless @get_log_matches messages
53
+ if @log_isnt_empty()
54
+ return @purge_log() unless @get_log_matches messages
45
55
  do callback
46
56
 
47
57
  get_log_matches: (messages) ->
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: growlyflash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tõnis Simo