growlyflash 0.1.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzQzZGRiMGIyNTc2MmM5YjkzN2E3MzkxODdiMDJmMWEyNTI2ZTQyNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzYwMTJhYzVhZmJlZTExNzNkMWFkYWJjMjMwNzYxZmM2YWU2MmQ5YQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzRmMGFiYWQyMzIwMDg0ZDAwMmE1N2IwY2NlNzczNWM1MDI4YTEwYTY4M2M2
|
10
|
+
YmMwNDQ1OTY3NzE3NWQ0ZmJmNmFkYmM2Njc5YjM0ODc4OWIxNDAwNjNlOTQ1
|
11
|
+
MTY0MDIwYWU2M2E1NDJjMTYzNjU5NmY1NDQ5OWQ5ZjBhMTlkMzI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NWE5Yjk0YjAzNzk0YjRiNjA1NThjODg5N2FkMTg2NjgxNGM3NjA4MmViZTBm
|
14
|
+
OTEwNzQwMzNmODMxNDlmY2I5YjM5MjUzZWEyMzRkNzI4NDYwM2I5NTQ5MjVj
|
15
|
+
ZjM4MzUwYWIyM2Q1YmZhZTMwNDE0MzhmNzhjM2IxZjA4ODAyMDI=
|
data/lib/growlyflash/version.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
33
|
+
flashes = @get_x_message.call response
|
34
|
+
if flashes?
|
33
35
|
messages = @messages flashes
|
34
|
-
|
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 @
|
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) ->
|