growlyflash 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4fe2e425f9270e864559a019546d124c48240bb
|
4
|
+
data.tar.gz: d5933ef2d1f5f593f6c064607725ece3904f787a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c875f93ca757ddbc7be54ec7e30f7ac0a56807739ff0b23f1527be98ad950a0fe949487320f67ef4da1c7b768b9a34013f825f89fa63adc3df0818f448528fd9
|
7
|
+
data.tar.gz: eeffa29ebc62987c1c2cd9450e4da8971f68971347cb73fc7bb1b5a7e5c373707e1245d5f8513962c43ea4d5d1897fc160a852c6e9ae916d0b48b93c2c692930
|
@@ -1,77 +1,82 @@
|
|
1
1
|
class Growlyflash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
class
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
).
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
css
|
2
|
+
@defaults =
|
3
|
+
align: 'right' # horizontal aligning (left, right or center)
|
4
|
+
delay: 4000 # auto-dismiss timeout (false to disable auto-dismiss)
|
5
|
+
dismiss: yes # allow to show close button
|
6
|
+
spacing: 10 # spacing between alerts
|
7
|
+
target: 'body' # selector to target element where to place alerts
|
8
|
+
title: no # switch for adding a title
|
9
|
+
type: null # bootstrap alert class by default
|
10
|
+
class: ['alert', 'growlyflash', 'fade']
|
11
|
+
|
12
|
+
# customizable callback to set notification position before it shows
|
13
|
+
before_show: ->
|
14
|
+
@el.css @calc_css_position()
|
15
|
+
|
16
|
+
@KEY_MAPPING =
|
17
|
+
alert: 'warning'
|
18
|
+
error: 'danger'
|
19
|
+
notice: 'info'
|
20
|
+
success: 'success'
|
21
|
+
|
22
|
+
@DISMISS = """<button type="close" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>"""
|
23
|
+
|
24
|
+
_titleize = (s) -> s.replace /^./, (m) -> do m.toUpperCase
|
25
|
+
|
26
|
+
h = @helpers =
|
27
|
+
dismiss: -> Growlyflash.DISMISS
|
28
|
+
title: (s) -> "<strong>#{_titleize(s)}!</strong> "
|
29
|
+
|
30
|
+
# Flash message struct
|
31
|
+
class @FlashStruct
|
32
|
+
toString: -> JSON.stringify "#{@msg}": @key
|
33
|
+
constructor: (@msg, @key) ->
|
34
|
+
@type = Growlyflash.KEY_MAPPING[@key]
|
35
|
+
|
36
|
+
class @Alert
|
37
|
+
_add = (orig, add) -> @splice -~@indexOf(orig), 0, "#{orig}-#{add}"
|
38
|
+
_top = (e) -> parseInt ($ e).css('top')
|
39
|
+
|
40
|
+
constructor: (@flash, @opts) ->
|
41
|
+
{title, target, dismiss, delay, before_show} = @opts
|
42
|
+
|
43
|
+
html = ""
|
44
|
+
html += h.dismiss() if dismiss
|
45
|
+
html += h.title(@opts) if title
|
46
|
+
html += @flash.msg
|
47
|
+
|
48
|
+
@el = ($ '<div>', html: html, class: @class_list().join(' '), role: "alert")
|
49
|
+
@el.appendTo(target)
|
50
|
+
|
51
|
+
before_show?.call(this)
|
52
|
+
@show()
|
53
|
+
setTimeout(@close, @opts.delay) if delay
|
54
|
+
|
55
|
+
class_list: ->
|
56
|
+
list = [].concat(@opts.class)
|
57
|
+
add = _add.bind(list)
|
58
|
+
add 'alert', "dismissable" if @opts.dismiss
|
59
|
+
add 'alert', @opts.type if @opts.type?
|
60
|
+
add 'growlyflash', @opts.align if @opts.align?
|
61
|
+
list
|
62
|
+
|
63
|
+
show: => @el.toggleClass('in', on)
|
64
|
+
close: => @el.alert('close')
|
65
|
+
|
66
|
+
calc_top_offset: ({spacing}) ->
|
67
|
+
amount = _top(@el)
|
68
|
+
(@el.siblings '.growlyflash').each ->
|
69
|
+
amount = Math.max(amount, _top(@) + ($ @).outerHeight() + spacing)
|
70
|
+
return amount
|
71
|
+
|
72
|
+
calc_css_position: (css = {}) ->
|
73
|
+
css.top = "#{@calc_top_offset(@opts)}px"
|
74
|
+
css.marginLeft = "-#{@el.outerWidth() / 2}px" if @opts.align is 'center'
|
75
|
+
css
|
76
|
+
|
77
|
+
window.Growlyflash = Growlyflash
|
73
78
|
|
74
79
|
$.growlyflash = (flash, options = {}) ->
|
75
|
-
|
76
|
-
alert
|
80
|
+
options = $.extend on, {}, Growlyflash.defaults, type: flash.type, options
|
81
|
+
alert = new Growlyflash.Alert(flash, options)
|
77
82
|
if flash instanceof Growlyflash.FlashStruct then flash else alert
|
@@ -1,40 +1,40 @@
|
|
1
1
|
class Growlyflash.Listener
|
2
|
-
HEADER = 'X-Message'
|
3
|
-
EVENTS = 'ajax:complete ajaxComplete'
|
4
|
-
|
5
2
|
# Alerts stack
|
6
|
-
class Stack
|
7
|
-
constructor: (items...) ->
|
8
|
-
|
9
|
-
has_uniq_in: (alerts, counter = 0) ->
|
10
|
-
return true unless @length > 0
|
11
|
-
recent = @slice -alerts.length
|
12
|
-
counter++ for id, item of alerts when recent[id].isnt_equal? item
|
13
|
-
counter > 0
|
14
|
-
push_all: (alerts) ->
|
15
|
-
@push alert.growl() for alert in alerts
|
16
|
-
this
|
17
|
-
push_once: (alerts) ->
|
18
|
-
@push_all alerts if @has_uniq_in alerts
|
19
|
-
@purge()
|
3
|
+
class Stack
|
4
|
+
constructor: (@items...) ->
|
5
|
+
|
20
6
|
purge: ->
|
21
|
-
setTimeout (=> @splice
|
22
|
-
|
7
|
+
setTimeout (=> @items.splice(0)), 100
|
8
|
+
|
9
|
+
push: (alert, dumped) ->
|
10
|
+
$.growlyflash(alert)
|
11
|
+
@items.push(dumped ? alert.toString())
|
12
|
+
|
13
|
+
push_only_fresh: (alerts) ->
|
14
|
+
recent = @items[-alerts.length..]
|
15
|
+
for alert in alerts
|
16
|
+
dumped = alert.toString()
|
17
|
+
@push(alert, dumped) if dumped not in recent
|
18
|
+
do @purge
|
19
|
+
|
20
|
+
HEADER = 'X-Message'
|
21
|
+
EVENTS = 'ajax:complete ajaxComplete'
|
22
|
+
|
23
23
|
process = (alerts = {}) ->
|
24
24
|
new Growlyflash.FlashStruct(msg, type) for type, msg of alerts when msg?
|
25
|
-
|
25
|
+
|
26
26
|
process_from_header = (source) ->
|
27
27
|
return [] unless source?
|
28
|
-
process $.parseJSON(decodeURIComponent
|
29
|
-
|
28
|
+
process $.parseJSON(decodeURIComponent(source))
|
29
|
+
|
30
30
|
constructor: (context) ->
|
31
31
|
@stack ?= new Stack()
|
32
32
|
@process_static() if window.flashes?
|
33
33
|
($ context).on EVENTS, (_, xhr) =>
|
34
|
-
@stack.
|
35
|
-
|
34
|
+
@stack.push_only_fresh process_from_header(xhr.getResponseHeader(HEADER))
|
35
|
+
|
36
36
|
process_static: ->
|
37
|
-
@stack.
|
37
|
+
@stack.push alert for alert in process(window.flashes)
|
38
38
|
delete window.flashes
|
39
39
|
|
40
40
|
Growlyflash.listen_on = (context) ->
|
data/growlyflash.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.version = Growlyflash::VERSION
|
10
10
|
spec.authors = ['Tõnis Simo']
|
11
11
|
spec.email = ['anton.estum@gmail.com']
|
12
|
-
spec.summary = %q{
|
13
|
-
spec.description = %q{
|
12
|
+
spec.summary = %q{Popup ActionDispatch::Flash within Bootstrap alert in Rails app like a growl notification.}
|
13
|
+
spec.description = %q{This gem popups Rails' ActionDispatch::Flash within Bootstrap alert like a growl notification. It serves messages with both of AJAX (XHR) and regular requests inside HTTP headers.}
|
14
14
|
spec.homepage = 'https://github.com/estum/growlyflash'
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
data/lib/growlyflash/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: growlyflash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tõnis Simo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -72,9 +72,9 @@ dependencies:
|
|
72
72
|
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
|
-
description:
|
76
|
-
|
77
|
-
|
75
|
+
description: This gem popups Rails' ActionDispatch::Flash within Bootstrap alert like
|
76
|
+
a growl notification. It serves messages with both of AJAX (XHR) and regular requests
|
77
|
+
inside HTTP headers.
|
78
78
|
email:
|
79
79
|
- anton.estum@gmail.com
|
80
80
|
executables: []
|
@@ -120,5 +120,6 @@ rubyforge_project:
|
|
120
120
|
rubygems_version: 2.4.7
|
121
121
|
signing_key:
|
122
122
|
specification_version: 4
|
123
|
-
summary:
|
123
|
+
summary: Popup ActionDispatch::Flash within Bootstrap alert in Rails app like a growl
|
124
|
+
notification.
|
124
125
|
test_files: []
|