ultimate-flash 0.6.1.1 → 0.7.1
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.
- data/Gemfile.lock +3 -3
- data/README.md +10 -0
- data/app/assets/javascripts/ultimate/flash.js.coffee +101 -95
- data/app/assets/stylesheets/ultimate/flash.scss +1 -0
- data/lib/ultimate-flash/version.rb +1 -1
- data/ultimate-flash.gemspec +1 -1
- metadata +4 -4
data/Gemfile.lock
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ultimate-flash (0.
|
5
|
-
ultimate-base (~> 0.3.
|
4
|
+
ultimate-flash (0.7.1)
|
5
|
+
ultimate-base (~> 0.3.3)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
-
ultimate-base (0.3.
|
10
|
+
ultimate-base (0.3.3)
|
11
11
|
|
12
12
|
PLATFORMS
|
13
13
|
ruby
|
data/README.md
CHANGED
@@ -7,6 +7,16 @@ Ruby on Rails oriented jQuery plugin for smart notifications
|
|
7
7
|
window.flash = $(".l-page__flashes").ultimateFlash({locale: "ru"}, true);
|
8
8
|
```
|
9
9
|
|
10
|
+
**Usage**:
|
11
|
+
|
12
|
+
```javascript
|
13
|
+
$(".l-page__flashes").ultimateFlash('notice', 'Hello.');
|
14
|
+
```
|
15
|
+
or
|
16
|
+
```javascript
|
17
|
+
flash.notice('Hello.');
|
18
|
+
```
|
19
|
+
|
10
20
|
## Licence ##
|
11
21
|
|
12
22
|
The MIT License
|
@@ -1,11 +1,7 @@
|
|
1
1
|
###*
|
2
|
-
* Ultimate Flash 0.
|
3
|
-
*
|
2
|
+
* Ultimate Flash 0.7.1 - Ruby on Rails oriented jQuery plugin for smart notifications
|
4
3
|
* Copyright 2011-2012 Karpunin Dmitry (KODer) / Evrone.com
|
5
|
-
*
|
6
|
-
* Dual licensed under the MIT and GPL licenses:
|
7
|
-
* http://www.opensource.org/licenses/mit-license.php
|
8
|
-
* http://www.gnu.org/licenses/gpl.html
|
4
|
+
* Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
|
9
5
|
*
|
10
6
|
###
|
11
7
|
|
@@ -18,17 +14,16 @@
|
|
18
14
|
* standart actions:
|
19
15
|
* construction .ultimateFlash([Object options = {}]) : {jQuery} jContainer
|
20
16
|
* updateOptions .pluginName({Object} options) : {Object} view options
|
21
|
-
* get options .pluginName(
|
22
|
-
* show .ultimateFlash(
|
23
|
-
* notice .ultimateFlash(
|
24
|
-
* alert .ultimateFlash(
|
17
|
+
* get options .pluginName('options') : {Object} view options
|
18
|
+
* show .ultimateFlash('show', String type, String text) : {jQuery} jFlash | {Boolean} false
|
19
|
+
* notice .ultimateFlash('notice', String text) : {jQuery} jFlash | {Boolean} false
|
20
|
+
* alert .ultimateFlash('alert', String text) : {jQuery} jFlash | {Boolean} false
|
25
21
|
* extended actions:
|
26
|
-
* auto .ultimateFlash(
|
27
|
-
* ajaxSuccess .ultimateFlash(
|
28
|
-
* ajaxError .ultimateFlash(
|
22
|
+
* auto .ultimateFlash('auto', {ArrayOrObject} obj) : {Array} ajFlashes | {Boolean} false
|
23
|
+
* ajaxSuccess .ultimateFlash('ajaxSuccess'[, Arguments successArgs = []])
|
24
|
+
* ajaxError .ultimateFlash('ajaxError'[, String text = translations.defaultErrorText][, Arguments errorArgs = []])
|
29
25
|
###
|
30
26
|
|
31
|
-
# TODO customizable show() and hide()
|
32
27
|
# TODO improve English
|
33
28
|
# TODO jGrowl features
|
34
29
|
|
@@ -39,25 +34,28 @@ Ultimate.Plugins ||= {}
|
|
39
34
|
|
40
35
|
class Ultimate.Plugins.Flash extends Ultimate.Plugin
|
41
36
|
|
42
|
-
el:
|
37
|
+
el: '.l-page__flashes'
|
43
38
|
|
44
|
-
@defaultLocales
|
39
|
+
@defaultLocales =
|
45
40
|
en:
|
46
|
-
defaultErrorText:
|
47
|
-
defaultThrownError:
|
48
|
-
formFieldsError:
|
41
|
+
defaultErrorText: 'Error'
|
42
|
+
defaultThrownError: 'server connection error'
|
43
|
+
formFieldsError: 'Form filled with errors'
|
49
44
|
ru:
|
50
|
-
defaultErrorText:
|
51
|
-
defaultThrownError:
|
52
|
-
formFieldsError:
|
45
|
+
defaultErrorText: 'Ошибка'
|
46
|
+
defaultThrownError: 'ошибка соединения с сервером'
|
47
|
+
formFieldsError: 'Форма заполнена с ошибками'
|
53
48
|
|
54
|
-
|
55
|
-
showTime: 3600
|
56
|
-
showTimePerChar: 30
|
49
|
+
flashClass: 'flash' # css-class of message container
|
57
50
|
showAjaxErrors: true # catch global jQuery.ajaxErrors(), try detect message and show it
|
58
51
|
showAjaxSuccesses: true # catch global jQuery.ajaxSuccessess(), try detect message and show it
|
59
52
|
detectFormErrors: true # can be function (parsedJSON)
|
60
53
|
detectPlainTextMaxLength: 200 # if response has plain text and its length fits, show it
|
54
|
+
productionMode: true
|
55
|
+
|
56
|
+
slideTime: 200 # show and hide animate duration
|
57
|
+
showTime: 3600 # base time for show flash message
|
58
|
+
showTimePerChar: 30 # show time per char of flash message
|
61
59
|
hideOnClick: true # click on notice fire hide()
|
62
60
|
removeOnHide: true # remove notice DOM-element on hide
|
63
61
|
forceAddDotsAfterLastWord: false
|
@@ -65,94 +63,103 @@ class Ultimate.Plugins.Flash extends Ultimate.Plugin
|
|
65
63
|
regExpLastWordWithoutDot: /[\wа-яёА-ЯЁ]{3,}$/
|
66
64
|
regExpLastWordWithDot: /([\wа-яёА-ЯЁ]{3,})\.$/
|
67
65
|
|
68
|
-
events:
|
69
|
-
|
66
|
+
events: ->
|
67
|
+
_events = {}
|
68
|
+
_events["click .#{@flashClass}:not(:animated)"] = 'closeFlashClick'
|
69
|
+
_events
|
70
70
|
|
71
71
|
initialize: (options) ->
|
72
|
-
super
|
73
72
|
# init flashes come from server in page
|
74
73
|
@jFlashes().each (index, flash) =>
|
75
74
|
jFlash = $(flash)
|
76
|
-
jFlash.html @_prepareText(jFlash.html())
|
75
|
+
jFlash.html @_prepareText(jFlash.html(), jFlash)
|
77
76
|
@_setTimeout jFlash
|
78
77
|
# binding hook ajaxError handler
|
79
78
|
@$el.ajaxError =>
|
80
79
|
if @showAjaxErrors
|
81
|
-
a = @
|
82
|
-
Ultimate.debug(".Plugins.Flash.ajaxError", a) if _.isFunction(Ultimate.debug)
|
80
|
+
a = @_ajaxParseArguments(arguments)
|
83
81
|
@ajaxError a.data, a.jqXHR
|
84
82
|
# binding hook ajaxSuccess handler
|
85
83
|
@$el.ajaxSuccess =>
|
86
84
|
if @showAjaxSuccesses
|
87
|
-
a = @
|
88
|
-
Ultimate.debug(".Plugins.Flash.ajaxSuccess", a) if _.isFunction(Ultimate.debug)
|
85
|
+
a = @_ajaxParseArguments(arguments)
|
89
86
|
@ajaxSuccess a.data, a.jqXHR
|
90
87
|
|
91
88
|
# delegate event for hide on click
|
92
89
|
closeFlashClick: (event) ->
|
93
|
-
|
94
|
-
|
90
|
+
jFlash = $(event.currentTarget)
|
91
|
+
if @_getOptionOverFlash('hideOnClick', jFlash)
|
92
|
+
@hide jFlash
|
95
93
|
false
|
96
94
|
|
97
95
|
jFlashes: (filterSelector) ->
|
98
|
-
_jFlashes = @$("
|
96
|
+
_jFlashes = @$(".#{@flashClass}")
|
99
97
|
if filterSelector then _jFlashes.filter(filterSelector) else _jFlashes
|
100
98
|
|
101
|
-
|
102
|
-
|
99
|
+
_getOptionOverFlash: (optionName, jFlashOrOptions = {}) ->
|
100
|
+
option = if jFlashOrOptions instanceof jQuery then jFlashOrOptions.data(optionName) else jFlashOrOptions[optionName]
|
101
|
+
option ? @[optionName]
|
102
|
+
|
103
|
+
_prepareText: (text, jFlashOrOptions) ->
|
104
|
+
text = _.string.clean(text)
|
103
105
|
# Add dot after last word (if word has minimum 3 characters)
|
104
|
-
|
105
|
-
|
106
|
+
if @_getOptionOverFlash('forceAddDotsAfterLastWord', jFlashOrOptions) and @_getOptionOverFlash('regExpLastWordWithoutDot', jFlashOrOptions).test(text)
|
107
|
+
text += '.'
|
108
|
+
# Remove dot after last word (if word has minimum 3 characters)
|
109
|
+
if @_getOptionOverFlash('forceRemoveDotsAfterLastWord', jFlashOrOptions)
|
110
|
+
text = text.replace(@_getOptionOverFlash('regExpLastWordWithDot', jFlashOrOptions), '$1')
|
106
111
|
text
|
107
112
|
|
108
|
-
|
109
|
-
|
110
|
-
jFlash.slideUp @slideTime, =>
|
111
|
-
jFlash.remove() if @removeOnHide
|
112
|
-
|
113
|
-
_setTimeout: (jFlash, timeout = @showTime + jFlash.text().length * @showTimePerChar) ->
|
113
|
+
_setTimeout: (jFlash, timeout) ->
|
114
|
+
timeout ?= @_getOptionOverFlash('showTime', jFlash) + jFlash.text().length * @_getOptionOverFlash('showTimePerChar', jFlash)
|
114
115
|
if timeout
|
115
|
-
jFlash.data
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
116
|
+
jFlash.data 'timeoutId', setTimeout =>
|
117
|
+
jFlash.removeData 'timeoutId'
|
118
|
+
@hide jFlash
|
119
|
+
, timeout
|
120
|
+
|
121
|
+
hide: (jFlashes = @jFlashes()) ->
|
122
|
+
jFlashes.each (index, element) =>
|
123
|
+
jFlash = $(element)
|
124
|
+
clearTimeout jFlash.data('timeoutId')
|
125
|
+
jFlash.slideUp @_getOptionOverFlash('slideTime', jFlash), =>
|
126
|
+
jFlash.remove() if @_getOptionOverFlash('removeOnHide', jFlash)
|
127
|
+
|
128
|
+
show: (type, text, timeout = null, perFlashOptions = null) ->
|
129
|
+
text = @_prepareText(text, perFlashOptions)
|
130
|
+
return false if not _.isString(text) or _.string.isBlank(text)
|
131
|
+
jFlash = $("<div class=\"#{@flashClass} #{type}\" style=\"display: none;\">#{text}</div>")
|
132
|
+
jFlash.appendTo(@$el).slideDown @_getOptionOverFlash('slideTime', perFlashOptions)
|
133
|
+
if perFlashOptions
|
134
|
+
jFlash.data(key, value) for key, value of perFlashOptions
|
124
135
|
@_setTimeout jFlash, timeout
|
125
136
|
jFlash
|
126
137
|
|
127
|
-
notice: (text, timeout = null) -> @show
|
138
|
+
notice: (text, timeout = null, perFlashOptions = null) -> @show 'notice', arguments...
|
128
139
|
|
129
|
-
alert: (text, timeout = null) -> @show
|
140
|
+
alert: (text, timeout = null, perFlashOptions = null) -> @show 'alert', arguments...
|
130
141
|
|
131
142
|
auto: (obj) ->
|
132
143
|
if _.isArray(obj)
|
133
144
|
@show(pair[0], pair[1]) for pair in obj
|
134
|
-
else if
|
145
|
+
else if $.isPlainObject(obj)
|
135
146
|
@show(key, text) for key, text of obj
|
136
147
|
else false
|
137
148
|
|
138
|
-
|
139
|
-
* @param {Arguments} successArgs=[] аргументы колбэка jQuery.success()
|
140
|
-
* @return {data: data, jqXHR: jqXHR}
|
141
|
-
###
|
142
|
-
_ajaxSuccessParseArguments: (successArgs) ->
|
149
|
+
_ajaxParseArguments: (args) ->
|
143
150
|
# detect event as first element
|
144
|
-
if
|
151
|
+
if args[0] instanceof jQuery.Event
|
145
152
|
# convert arguments to Array
|
146
|
-
|
153
|
+
args = _.toArray(args)
|
147
154
|
# remove event
|
148
|
-
|
155
|
+
args.shift()
|
149
156
|
# arrange arguments
|
150
|
-
if _.isString(
|
157
|
+
if _.isString(args[0])
|
151
158
|
# from jQuery.ajax().success()
|
152
|
-
[data, _textStatus, jqXHR] =
|
159
|
+
[data, _textStatus, jqXHR] = args
|
153
160
|
else
|
154
161
|
# from jQuery.ajaxSuccess() or jQuery.ajaxError()
|
155
|
-
[jqXHR, _ajaxSettings, data] =
|
162
|
+
[jqXHR, _ajaxSettings, data] = args
|
156
163
|
data: data
|
157
164
|
jqXHR: jqXHR
|
158
165
|
|
@@ -169,15 +176,15 @@ class Ultimate.Plugins.Flash extends Ultimate.Plugin
|
|
169
176
|
# detect notice
|
170
177
|
if _.isString(data)
|
171
178
|
# catch plain text message
|
172
|
-
data = _.trim(data)
|
179
|
+
data = _.string.trim(data)
|
173
180
|
return @notice(data) if data.length <= @detectPlainTextMaxLength and not $.isHTML(data)
|
174
181
|
else if _.isObject(data)
|
175
182
|
# catch json data with flash-notice
|
176
|
-
return @auto(data[
|
183
|
+
return @auto(data['flash']) if data['flash']
|
177
184
|
false
|
178
185
|
|
179
186
|
###*
|
180
|
-
* @param {String} [text=
|
187
|
+
* @param {String} [text='Ошибка'] вступительный (либо полный) текст формируемой ошибки
|
181
188
|
* @param {String} thrownError some error from ajax response
|
182
189
|
* @param {jqXHR} jqXHR jQuery XHR
|
183
190
|
* @return {Boolean} статус выполнения показа сообщения
|
@@ -186,9 +193,9 @@ class Ultimate.Plugins.Flash extends Ultimate.Plugin
|
|
186
193
|
unless _.isObject(jqXHR)
|
187
194
|
jqXHR = thrownError
|
188
195
|
thrownError = text
|
189
|
-
text = @
|
196
|
+
text = @t('defaultErrorText')
|
190
197
|
# prevent undefined responses
|
191
|
-
return false if jqXHR.status < 100
|
198
|
+
#return false if jqXHR.status < 100
|
192
199
|
# prevent recall
|
193
200
|
return false if jqXHR.breakFlash
|
194
201
|
jqXHR.breakFlash = true
|
@@ -196,14 +203,14 @@ class Ultimate.Plugins.Flash extends Ultimate.Plugin
|
|
196
203
|
try
|
197
204
|
# try parse respose as json
|
198
205
|
if parsedJSON = $.parseJSON(jqXHR.responseText)
|
199
|
-
# catch
|
200
|
-
return @auto(parsedJSON[
|
201
|
-
# catch
|
202
|
-
return @alert(parsedJSON[
|
206
|
+
# catch 'flash' object and call auto() method with autodetecting flash-notice type
|
207
|
+
return @auto(parsedJSON['flash']) if parsedJSON['flash']
|
208
|
+
# catch 'error' object and call alert() method
|
209
|
+
return @alert(parsedJSON['error']) if parsedJSON['error']
|
203
210
|
# may be parsedJSON is form errors
|
204
211
|
if @detectFormErrors is true
|
205
212
|
# show message about form with errors
|
206
|
-
return @alert(@
|
213
|
+
return @alert(@t('formFieldsError'))
|
207
214
|
else if _.isFunction(@detectFormErrors)
|
208
215
|
# using showFormError as callback
|
209
216
|
return @detectFormErrors.apply(@, [parsedJSON])
|
@@ -212,24 +219,23 @@ class Ultimate.Plugins.Flash extends Ultimate.Plugin
|
|
212
219
|
return false
|
213
220
|
catch e
|
214
221
|
# nop
|
215
|
-
if
|
216
|
-
|
217
|
-
if raiseMatches = jqXHR.responseText.match(/<\/h1>\n<pre>(.+?)<\/pre>/)
|
218
|
-
Ultimate.debug("replace thrownError = \"#{thrownError}\" with raiseMatches[1] = \"#{raiseMatches[1]}\"") if _.isFunction(Ultimate.debug)
|
219
|
-
thrownError = raiseMatches[1]
|
220
|
-
else
|
221
|
-
# try detect short text message as error
|
222
|
-
if jqXHR.responseText.length <= @detectPlainTextMaxLength
|
223
|
-
Ultimate.debug("replace thrownError = \"#{thrownError}\" with jqXHR.responseText = \"#{jqXHR.responseText}\"") if _.isFunction(Ultimate.debug)
|
224
|
-
thrownError = jqXHR.responseText
|
222
|
+
if @productionMode
|
223
|
+
thrownError = @t('defaultThrownError')
|
225
224
|
else
|
226
|
-
if
|
227
|
-
|
228
|
-
|
229
|
-
|
225
|
+
if jqXHR.status >= 400 and jqXHR.responseText
|
226
|
+
# try detect Rails raise message
|
227
|
+
if raiseMatches = jqXHR.responseText.match(/<\/h1>\n<pre>(.+?)<\/pre>/)
|
228
|
+
thrownError = raiseMatches[1]
|
229
|
+
else
|
230
|
+
# try detect short text message as error
|
231
|
+
if not _.string.isBlank(jqXHR.responseText) and jqXHR.responseText.length <= @detectPlainTextMaxLength
|
232
|
+
thrownError = jqXHR.responseText
|
233
|
+
else if _.string.isBlank(thrownError)
|
234
|
+
thrownError = @t('defaultThrownError')
|
235
|
+
text += ': ' if text
|
230
236
|
text += "#{thrownError} [#{jqXHR.status}]"
|
231
|
-
|
237
|
+
@alert(text)
|
232
238
|
|
233
239
|
|
234
240
|
|
235
|
-
Ultimate.createJQueryPlugin
|
241
|
+
Ultimate.createJQueryPlugin 'ultimateFlash', Ultimate.Plugins.Flash
|
data/ultimate-flash.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
|
14
14
|
s.rubyforge_project = "ultimate-flash"
|
15
15
|
|
16
|
-
s.add_dependency "ultimate-base", "~> 0.3.
|
16
|
+
s.add_dependency "ultimate-base", "~> 0.3.3"
|
17
17
|
|
18
18
|
s.files = `git ls-files`.split("\n")
|
19
19
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ultimate-flash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ultimate-base
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.3.
|
21
|
+
version: 0.3.3
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.3.
|
29
|
+
version: 0.3.3
|
30
30
|
description: Ruby on Rails oriented jQuery plugin for smart notifications
|
31
31
|
email:
|
32
32
|
- koderfunk@gmail.com
|