unobtrusive_flash 2.1.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YTFiNGZlYTIwNDBjMDEwZTVmMGM3Mzc4YTExZDEyNTJlZmNlYjNlNw==
5
- data.tar.gz: !binary |-
6
- NGE5MWVkZWVhODFlZGNmYWM1YzRhZWZkNDczYWQ3YWFlY2FkYmEzYw==
2
+ SHA1:
3
+ metadata.gz: dcf558cc6c7773077a8b0e9b02a16d747785424c
4
+ data.tar.gz: 572d0ec1cddc18f14f601738a12e62b17a012d30
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YzExMDQ1YjM2ODA3YjFmOGZlZWM5MWY3MjViYmYzYmRmMjc3Y2NhYjc2NGUw
10
- ZTJlOWJlZjdjNzllMTdmOTYxMWI5OWI5YWY5ZGQ3MDRkMmVkNmNkNDg1NTdh
11
- NTUwNmM1YTRjNWM5Y2FjNzJiOTg5YjQ2YmYwNDc4Mzk0OGJmNjE=
12
- data.tar.gz: !binary |-
13
- MzU3YTc0NDI5OGI2NjY2MjEzZjI3NmNmODlmYmE4OWRmNTRjNmE5MTY5OTk4
14
- Nzc1NDI3OWUwNzk1YjMzNWY0Njg5YmU3OWYyN2VlNDNkM2FlMzhkMWZkYjEz
15
- NjY2NWZkOTZlMTFjNzI2NTI1NTRhYWY4MTA3NTQzMmU0OWY0NDk=
6
+ metadata.gz: a158ce2b5636919e08e3bbfcb9c0bb1070c3064416353b84edca1f3ac42cb8fab19ad24ab3354ba3b2fc59180fdb8515905d50c2e7cf8d67aa1f0263b7a6ce72
7
+ data.tar.gz: 75aa65125e9e74ab6dc6785a61f8b14f31acb28bde4cba869f1642303e738a8250b77e109707a206141869d48a515d72b8c430c81780b4cf7b8c251e9cb62393
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 2014-03-07 3.0.0
2
+
3
+ * Moved Javascript methods to an `UnobtrusiveFlash` module. This breaks calling `$.showFlashMessage`, hence another major release [#11]
4
+ * Make sure that the flash events are invoked after a handler had a chance to bind [#10]
5
+ * Changed default alerts to never autohide [#6]
6
+ * Bootstrap handler: All conventional Rails notices are correctly styled by @conzett [#12]
7
+ * Turbolinks are supported thanks to @yoyos [#13]
8
+ * Fixes to cookie nuking by @asaletnik [#7]
9
+
1
10
  ## 2013-12-21 2.1.0
2
11
 
3
12
  * Changed message escaping logic to use the Rails html_safe conventions (Possibly breaking change)
data/README.markdown CHANGED
@@ -9,7 +9,7 @@ Ever got tired of writing custom code to handle flash messages passed in AJAX re
9
9
  Here comes the solution.
10
10
 
11
11
  `unobtrusive_flash` takes your flash messages for the backend and automagically passes them to the frontend via
12
- HTTP cookies. This works with both regular page loads and AJAX requests, does not tamper with the page body and requires
12
+ HTTP cookies. This works with both **regular page loads**, **jQuery AJAX requests**, and **turbolinks** (from v3), does not tamper with the page body and requires
13
13
  about 3 extra lines of code in your app - how's that for unobtrusive?
14
14
 
15
15
  You can pass up to 4K of text into flash this way, and you don't need to worry about cookie size since they are
@@ -25,14 +25,14 @@ Tested in:
25
25
 
26
26
  ## Requirements
27
27
 
28
- * Rails 3
28
+ * Rails >=3
29
29
  * jQuery (tested with v1.10)
30
30
 
31
31
  ## Usage
32
32
 
33
33
  1. Add the `unobtrusive_flash` gem to your Gemfile.
34
34
 
35
- gem 'unobtrusive_flash', '~>2'
35
+ gem 'unobtrusive_flash', '>=3'
36
36
 
37
37
  2. Add the following to the controllers that generate flash messages (or better, to the `ApplicationController`):
38
38
 
@@ -66,16 +66,20 @@ Unobtrusive Flash triggers jQuery events when flash is received. If you want to
66
66
 
67
67
  $(window).bind('rails:flash', flashHandler);
68
68
 
69
+
70
+ ## Using UnobtrusiveFlash with a frontend framework that doesn't use jQuery for AJAX
71
+
72
+ Call `UnobtrusiveFlash.showFlashFromCookies()` in your Javascript after a completed request.
69
73
 
70
74
  ## Bonus: show 'flash messages' from the front-end
71
75
 
72
76
  Both Bootstrap and non-Bootstrap versions contain a function to display flash messages:
73
77
 
74
78
  // Shown for 5 seconds (default)
75
- $.showFlashMessage('Hello World', {type: 'notice'})
79
+ UnobtrusiveFlash.showFlashMessage('Hello World', {type: 'notice'})
76
80
  // Shown forever
77
- $.showFlashMessage('Error', {type: 'error', timeout: 0})
81
+ UnobtrusiveFlash.showFlashMessage('Error', {type: 'error', timeout: 0})
78
82
 
79
83
  * * *
80
84
 
81
- © 2010-2013 Leonid Shevtsov, released under the MIT license
85
+ © 2010-2014 Leonid Shevtsov, released under the MIT license
@@ -6,6 +6,7 @@ $(function() {
6
6
  yesterday.setDate(yesterday.getDate() - 1);
7
7
  var hostParts = window.location.host.split('.').reverse();
8
8
  var expireHost = hostParts.shift();
9
+ expireHost = expireHost.replace(/^([a-z]{1,})\:[0-9]{1,5}/, '$1');
9
10
  $.each(hostParts, function(i,part) {
10
11
  expireHost = part + '.' + expireHost;
11
12
  document.cookie = cookieName+'=; path=/;expires='+yesterday+'; domain='+expireHost;
@@ -42,7 +43,8 @@ $(function() {
42
43
  }
43
44
 
44
45
  // Reads flash messages from cookies and fires corresponding events
45
- function showFlashFromCookies() {
46
+ window.UnobtrusiveFlash = {}
47
+ window.UnobtrusiveFlash['showFlashFromCookies'] = function() {
46
48
  var flashMessages = extractFlashFromCookies();
47
49
  if (flashMessages !== null) {
48
50
  $.each(flashMessages, function(_, flashMessage) {
@@ -51,11 +53,13 @@ $(function() {
51
53
  }
52
54
  }
53
55
 
54
- $(function() {
55
- showFlashFromCookies();
56
+ $(window).load(function() {
57
+ UnobtrusiveFlash.showFlashFromCookies();
56
58
  });
57
59
 
60
+ $(document).on('page:change page:load', UnobtrusiveFlash.showFlashFromCookies);
61
+
58
62
  $(document).ajaxSuccess(function(event,request,options) {
59
- showFlashFromCookies();
63
+ UnobtrusiveFlash.showFlashFromCookies();
60
64
  });
61
65
  });
@@ -6,11 +6,17 @@
6
6
  $(function() {
7
7
  var $flashContainer = $($('.unobtrusive-flash-container')[0] || $('.container')[0] || $('.container-fluid')[0] || $('body')[0]);
8
8
 
9
- $.showFlashMessage = function(message, options) {
10
- options = $.extend({type: 'notice', timeout: 5000}, options);
9
+ UnobtrusiveFlash.showFlashMessage = function(message, options) {
10
+ options = $.extend({type: 'notice', timeout: 0}, options);
11
11
 
12
12
  // Workaround for common Rails flash type to match common Bootstrap alert type
13
- if (options.type=='notice') options.type = 'info';
13
+ if (options.type=='notice') {
14
+ options.type = 'info';
15
+ } else if(options.type=='alert') {
16
+ options.type = 'warning';
17
+ } else if(options.type=='error') {
18
+ options.type = 'danger';
19
+ }
14
20
 
15
21
  var $flash = $('<div class="alert alert-'+options.type+'"><button type="button" class="close" data-dismiss="alert">&times;</button>'+message+'</div>');
16
22
 
@@ -28,7 +34,7 @@ $(function() {
28
34
  };
29
35
 
30
36
  flashHandler = function(e, params) {
31
- $.showFlashMessage(params.message, {type: params.type});
37
+ UnobtrusiveFlash.showFlashMessage(params.message, {type: params.type});
32
38
  };
33
39
 
34
40
  $(window).bind('rails:flash', flashHandler);
@@ -11,8 +11,8 @@ $(function() {
11
11
  });
12
12
  }
13
13
 
14
- $.showFlashMessage = function(message, options) {
15
- options = $.extend({type: 'notice', timeout: 5000}, options);
14
+ UnobtrusiveFlash.showFlashMessage = function(message, options) {
15
+ options = $.extend({type: 'notice', timeout: 0}, options);
16
16
 
17
17
  var $flash = $('<div class="unobtrusive-flash-message-wrapper unobtrusive-flash-'+options.type+'"><div class="unobtrusive-flash-message">'+message+'</div></div>');
18
18
 
@@ -31,7 +31,7 @@ $(function() {
31
31
  };
32
32
 
33
33
  flashHandler = function(e, params) {
34
- $.showFlashMessage(params.message, {type: params.type});
34
+ UnobtrusiveFlash.showFlashMessage(params.message, {type: params.type});
35
35
  };
36
36
 
37
37
  $(window).bind('rails:flash', flashHandler);
@@ -1,3 +1,3 @@
1
1
  module UnobtrusiveFlash
2
- VERSION = "2.1.0"
2
+ VERSION = "3.0.0"
3
3
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unobtrusive_flash
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonid Shevtsov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-21 00:00:00.000000000 Z
11
+ date: 2014-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
@@ -42,39 +42,34 @@ dependencies:
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description: ! 'unobtrusive_flash takes your flash messages for the backend and automagically
70
- passes them to the frontend via HTTP cookies.
71
-
72
- This works with both regular page loads and AJAX requests, does not tamper with
73
- the page body and requires about 3 extra
74
-
75
- lines of code in your app - how''s that for unobtrusive?
76
-
77
- '
69
+ description: |
70
+ unobtrusive_flash takes your flash messages for the backend and automagically passes them to the frontend via HTTP cookies.
71
+ This works with both regular page loads and AJAX requests, does not tamper with the page body and requires about 3 extra
72
+ lines of code in your app - how's that for unobtrusive?
78
73
  email:
79
74
  - leonid@shevtsov.me
80
75
  executables: []
@@ -106,12 +101,12 @@ require_paths:
106
101
  - lib
107
102
  required_ruby_version: !ruby/object:Gem::Requirement
108
103
  requirements:
109
- - - ! '>='
104
+ - - '>='
110
105
  - !ruby/object:Gem::Version
111
106
  version: '0'
112
107
  required_rubygems_version: !ruby/object:Gem::Requirement
113
108
  requirements:
114
- - - ! '>='
109
+ - - '>='
115
110
  - !ruby/object:Gem::Version
116
111
  version: '0'
117
112
  requirements: []