unobtrusive_flash 0.0.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MWU1ZTA0MjUzNzMyYmY4MTkzZGUzMzE3MmEzNmE1NTc2YWEwYTA4NQ==
5
+ data.tar.gz: !binary |-
6
+ OTVhNmFkNWI2YTFjYjk3MjY2YjI5YjI2Yjg5MDY1YjQzNzc3YTM2NQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MDkwODU2YmEzNTJjODJmYTg2MDhhZDllMzUwYmRiYjdiNjNlNTY0MDcyMjdi
10
+ NDkzYTk4MjVmYjk5N2RhMjEyN2NhYTBkZjg2ODU2NDZhYmMzNTJkNDNhNjkz
11
+ NzI3NGIxODQwMmI1NTU3MjUzYjRkNGQzOGJkODA3MTNmMTcwY2M=
12
+ data.tar.gz: !binary |-
13
+ YjIxMGFkMjkzZjMyYjg0ZWQ5NWQ1OWU1YmJkZTk3ZDk3MTVmZTgxZjY1NTI5
14
+ N2M5ZGVlNTlhYjA5ODY1OGIxM2ZhOTZjYjYwNGJiZjQxOTgwYmE0NWVmNTEx
15
+ OWUyZjE0MGMwMjE5Yjk2NzM1MDNkMjk3NDcwYmM0Mjg3YzZiMjc=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ ## 2013-10-09 2.0.0
2
+
3
+ * Grand refactoring
4
+ * Compatibility with Rails 3 Asset Pipeline
5
+ * Dropped compatibility with Rails 2
6
+ * Decoupled logic from presentation
7
+ * Compatibility with Bootstrap
8
+ * Event-driven architecture
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in unobtrusive_flash.gemspec
4
+ gemspec
data/README.markdown CHANGED
@@ -1,5 +1,7 @@
1
1
  # Unobtrusive flash messages for Rails
2
2
 
3
+ **Version 1 users:** this gem got a major redesign in version 2, please read the documentation
4
+
3
5
  Ever got tired of pages that can't be cached because they contain flash messages?
4
6
 
5
7
  Ever got tired of writing custom code to handle flash messages passed in AJAX responses?
@@ -13,32 +15,64 @@ about 3 extra lines of code in your app - how's that for unobtrusive?
13
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
14
16
  cleared immediately upon rendering.
15
17
 
16
- Tested and fully functional in:
18
+ Tested in:
17
19
 
18
- * Internet Explorer 8
19
- * Firefox 4b7
20
- * Chrome 7
21
- * Safari 5
22
- * Opera 10.6
23
- * *please let me know if it works in firefox 3 and ie 6, 7*
20
+ * Internet Explorer 8 and later
21
+ * Firefox up to v24
22
+ * Chrome up to v30
23
+ * Safari 6
24
+ * Opera 12
24
25
 
25
26
  ## Requirements
26
27
 
27
- * Rails 2.3 or 3
28
- * jQuery (maybe I'll make it agnostic in the future)
28
+ * Rails 3
29
+ * jQuery (tested with v1.10)
29
30
 
30
31
  ## Usage
31
32
 
32
33
  1. Add the gem to your Rails app.
33
- 2. Run `script/generate unobtrusive_flash` or `rails g unobtrusive_flash:install`
34
- 3. Add the following to the controllers that generate flash messages (or better, to the `ApplicationController`):
34
+ 2. Add the following to the controllers that generate flash messages (or better, to the `ApplicationController`):
35
35
 
36
36
  after_filter :prepare_unobtrusive_flash
37
+
38
+ Important! **Flash messages are NOT HTML escaped**, so you can use any markup in them. Take additional care to protect yourself from injection attacks if necessary.
39
+
40
+ 3. Include `require unobtrusive_flash` in your `application.js`.
41
+
42
+ 4. Delete flash rendering code from your views, if there was any.
43
+
44
+ 5. You have three options to render flash messages on the frontend:
45
+
46
+ ### Option 1: For Bootstrap projects
47
+
48
+ Also `require unobtrusive_flash_bootstrap` in your `application.js`. This file contains flash message UI based on the [Bootstrap alert component](http://getbootstrap.com/components/#alerts).
49
+
50
+ Either declare a `.unobtrusive-flash-container` element somewhere on the page to contain the alerts, or Unobtrusive flash will choose the first `.container` or `.container-fluid` element on the page, or fall back to the `body`.
51
+
52
+ ### Option 2: For non-Bootstrap projects
53
+
54
+ Also `require unobtrusive_flash_ui` in your `application.js` and `require unobtrusive_flash_ui` in your `application.css`. These files contain a no-frills flash message UI that works out of the box.
55
+
56
+ ### Option 3: Roll your own
57
+
58
+ Unobtrusive Flash triggers jQuery events when flash is received. If you want to integrate it with your own UI, implement and bind a handler:
59
+
60
+ flashHandler = function(e, params) {
61
+ alert('Received flash message '+params.message+' with type '+params.type);
62
+ };
63
+
64
+ $(window).bind('rails:flash', flashHandler);
65
+
37
66
 
38
- 4. Include `unobtrusive_flash.css` and `unobtrusive_flash.js` in your layouts. No custom markup is needed.
39
- 5. Remove existing flash rendering code from your layouts.
40
- 6. That's all! You can also edit the generated CSS/JS to your liking.
67
+ ## Bonus: show 'flash messages' from the front-end
68
+
69
+ Both Bootstrap and non-Bootstrap versions contain a function to display flash messages:
70
+
71
+ // Shown for 5 seconds (default)
72
+ $.showFlashMessage('Hello World', {type: 'notice'})
73
+ // Shown forever
74
+ $.showFlashMessage('Error', {type: 'error', timeout: 0})
41
75
 
42
76
  * * *
43
77
 
44
- © 2010 Leonid Shevtsov, released under the MIT license
78
+ © 2010-2013 Leonid Shevtsov, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ module UnobtrusiveFlash
2
+ module ControllerMixin
3
+ protected
4
+
5
+ def prepare_unobtrusive_flash
6
+ if flash.any?
7
+ cookie_flash = []
8
+ if cookies['flash']
9
+ cookie_flash = JSON.parse(cookies['flash']) rescue nil
10
+ cookie_flash=[] unless cookie_flash.is_a? Array
11
+ end
12
+
13
+ cookie_flash += flash.to_a
14
+ cookies[:flash] = {:value => cookie_flash.to_json, :domain => :all}
15
+ flash.discard
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,10 +1,11 @@
1
1
  require 'unobtrusive_flash'
2
+ require "unobtrusive_flash/controller_mixin"
2
3
  require 'rails'
3
4
 
4
5
  module UnobtrusiveFlash
5
- class Railtie < Rails::Railtie
6
+ class Engine < ::Rails::Engine
6
7
  initializer 'unobtrusive_flash.initialize', :after => :after_initialize do
7
- ActionController::Base.send :include, UnobtrusiveFlash
8
+ ActionController::Base.send :include, UnobtrusiveFlash::ControllerMixin
8
9
  end
9
10
  end
10
11
  end
@@ -0,0 +1,3 @@
1
+ module UnobtrusiveFlash
2
+ VERSION = "2.0.0"
3
+ end
@@ -1,21 +1,5 @@
1
- require File.join(File.dirname(__FILE__), *%w[unobtrusive_flash railtie]) if defined?(::Rails::Railtie)
1
+ require "unobtrusive_flash/version"
2
+ require "unobtrusive_flash/engine"
2
3
 
3
4
  module UnobtrusiveFlash
4
-
5
- protected
6
-
7
- def prepare_unobtrusive_flash
8
- if flash.any?
9
- cookie_flash = []
10
- if cookies['flash']
11
- cookie_flash = JSON.parse(cookies['flash']) rescue nil
12
- cookie_flash=[] unless cookie_flash.is_a? Array
13
- end
14
-
15
- cookie_flash += flash.to_a
16
-
17
- cookies['flash'] = cookie_flash.to_json
18
- flash.discard
19
- end
20
- end
21
5
  end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'unobtrusive_flash/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "unobtrusive_flash"
8
+ spec.version = UnobtrusiveFlash::VERSION
9
+ spec.authors = ["Leonid Shevtsov"]
10
+ spec.email = ["leonid@shevtsov.me"]
11
+ spec.summary = "Unobtrusive flash messages for Rails"
12
+ spec.description = <<EOT
13
+ unobtrusive_flash takes your flash messages for the backend and automagically passes them to the frontend via HTTP cookies.
14
+ This works with both regular page loads and AJAX requests, does not tamper with the page body and requires about 3 extra
15
+ lines of code in your app - how's that for unobtrusive?
16
+ EOT
17
+ spec.homepage = "https://github.com/leonid-shevtsov/unobtrusive_flash"
18
+
19
+ spec.files = `git ls-files`.split($/)
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "railties"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.3"
27
+ spec.add_development_dependency "rake"
28
+ end
@@ -0,0 +1,61 @@
1
+ $(function() {
2
+ // Delete the cookie regardless of the domain it was set from
3
+ // Partial credit to http://stackoverflow.com/a/2959110/6678
4
+ function nukeCookie(cookieName) {
5
+ var yesterday = new Date();
6
+ yesterday.setDate(yesterday.getDate() - 1);
7
+ var hostParts = window.location.host.split('.').reverse();
8
+ var expireHost = hostParts.shift();
9
+ $.each(hostParts, function(i,part) {
10
+ expireHost = part + '.' + expireHost;
11
+ document.cookie = cookieName+'=; path=/;expires='+yesterday+'; domain='+expireHost;
12
+ });
13
+ document.cookie = cookieName+'=; path=/';expires=+yesterday+'; domain=';
14
+ }
15
+
16
+ // Extracts flash array stored in cookie and clears the cookie
17
+ function extractFlashFromCookies() {
18
+ var data = null;
19
+ if (document.cookie && document.cookie !== '') {
20
+ var cookies = document.cookie.split(';');
21
+ var name = 'flash';
22
+ var cookieValue = null;
23
+
24
+ for (var i = 0; i < cookies.length; i++) {
25
+ var cookie = jQuery.trim(cookies[i]);
26
+ if (cookie.substring(0, name.length + 1) == (name + '=')) {
27
+ // replace fixes problems with Rails escaping. Duh.
28
+ cookieValue = decodeURIComponent(cookie.substring(name.length + 1).replace(/\+/g,'%20'));
29
+ if (cookieValue.length > 0) break; // there might be empty "flash=" cookies
30
+ }
31
+ }
32
+
33
+ try {
34
+ data = $.parseJSON(cookieValue);
35
+ } catch(e) {
36
+ }
37
+
38
+ nukeCookie('flash');
39
+ }
40
+
41
+ return data;
42
+ }
43
+
44
+ // Reads flash messages from cookies and fires corresponding events
45
+ function showFlashFromCookies() {
46
+ var flashMessages = extractFlashFromCookies();
47
+ if (flashMessages !== null) {
48
+ $.each(flashMessages, function(_, flashMessage) {
49
+ $(window).trigger('rails:flash', {type: flashMessage[0], message: flashMessage[1]});
50
+ });
51
+ }
52
+ }
53
+
54
+ $(function() {
55
+ showFlashFromCookies();
56
+ });
57
+
58
+ $(document).ajaxSuccess(function(event,request,options) {
59
+ showFlashFromCookies();
60
+ });
61
+ });
@@ -0,0 +1,35 @@
1
+ // Unobtrusive flash UI implementation with Bootstrap 3
2
+ // For sites that use Bootstrap http://getbootstrap.com/
3
+ //
4
+ // Declare a .unobtrusive-flash-container wherever you want the messages to appear
5
+ // Defaults to .container, .container-fluid (core Bootstrap classes), or just the body tag, whichever is present
6
+ $(function() {
7
+ var $flashContainer = $($('.unobtrusive-flash-container')[0] || $('.container')[0] || $('.container-fluid')[0] || $('body')[0]);
8
+
9
+ $.showFlashMessage = function(message, options) {
10
+ options = $.extend({type: 'notice', timeout: 5000}, options);
11
+
12
+ // Workaround for common Rails flash type to match common Bootstrap alert type
13
+ if (options.type=='notice') options.type = 'info';
14
+
15
+ var $flash = $('<div class="alert alert-'+options.type+'"><button type="button" class="close" data-dismiss="alert">&times;</button>'+message+'</div>');
16
+
17
+ $flashContainer.prepend($flash);
18
+
19
+ $flash.hide().delay(300).slideDown(100);
20
+
21
+ $flash.alert();
22
+
23
+ if (options.timeout>0) {
24
+ setTimeout(function() {
25
+ $flash.alert('close');
26
+ },options.timeout);
27
+ }
28
+ };
29
+
30
+ flashHandler = function(e, params) {
31
+ $.showFlashMessage(params.message, {type: params.type});
32
+ };
33
+
34
+ $(window).bind('rails:flash', flashHandler);
35
+ });
@@ -0,0 +1,38 @@
1
+ // Unobtrusive flash UI implementation, design agnostic
2
+ // Remember to link unobtrusive_flash_ui.css as well
3
+ //
4
+ // Shows flash messages as translucent bars on top of the page
5
+ $(function() {
6
+ $('<div id="unobtrusive-flash-messages"></div>').prependTo('body');
7
+
8
+ function hideFlash($flash) {
9
+ $flash.slideUp(100,function(){
10
+ $flash.remove();
11
+ });
12
+ }
13
+
14
+ $.showFlashMessage = function(message, options) {
15
+ options = $.extend({type: 'notice', timeout: 5000}, options);
16
+
17
+ var $flash = $('<div class="unobtrusive-flash-message-wrapper unobtrusive-flash-'+options.type+'"><div class="unobtrusive-flash-message">'+message+'</div></div>');
18
+
19
+ $('#unobtrusive-flash-messages').prepend($flash);
20
+ $flash.hide().delay(300).slideDown(100);
21
+
22
+ $flash.click(function() {
23
+ hideFlash($flash);
24
+ });
25
+
26
+ if (options.timeout>0) {
27
+ setTimeout(function() {
28
+ hideFlash($flash);
29
+ },options.timeout);
30
+ }
31
+ };
32
+
33
+ flashHandler = function(e, params) {
34
+ $.showFlashMessage(params.message, {type: params.type});
35
+ };
36
+
37
+ $(window).bind('rails:flash', flashHandler);
38
+ });
@@ -0,0 +1,23 @@
1
+ #unobtrusive-flash-messages {
2
+ position: fixed;
3
+ top: 0;
4
+ left: 0;
5
+ width: 100%;
6
+ z-index: 10000;
7
+ }
8
+
9
+ #unobtrusive-flash-messages .unobtrusive-flash-message-wrapper {
10
+ padding: 10px 0;
11
+ background: #dcecaa;
12
+ opacity: 0.8;
13
+ }
14
+
15
+ #unobtrusive-flash-messages .unobtrusive-flash-message-wrapper.unobtrusive-flash-error {
16
+ background: #ffe2e2;
17
+ }
18
+
19
+ #unobtrusive-flash-messages .unobtrusive-flash-message-wrapper .unobtrusive-flash-message {
20
+ width: 960px;
21
+ margin: 0 auto;
22
+ }
23
+
metadata CHANGED
@@ -1,79 +1,107 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: unobtrusive_flash
3
- version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 0
9
- - 2
10
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Leonid Shevtsov
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
11
+ date: 2013-10-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: ! 'unobtrusive_flash takes your flash messages for the backend and automagically
56
+ passes them to the frontend via HTTP cookies.
17
57
 
18
- date: 2010-11-18 00:00:00 +02:00
19
- default_executable:
20
- dependencies: []
58
+ This works with both regular page loads and AJAX requests, does not tamper with
59
+ the page body and requires about 3 extra
21
60
 
22
- description: |
23
- unobtrusive_flash takes your flash messages for the backend and automagically passes them to the frontend via HTTP cookies.
24
- This works with both regular page loads and AJAX requests, does not tamper with the page body and requires about 3 extra
25
- lines of code in your app - how's that for unobtrusive?
61
+ lines of code in your app - how''s that for unobtrusive?
26
62
 
27
- email: leonid@shevtsov.me
63
+ '
64
+ email:
65
+ - leonid@shevtsov.me
28
66
  executables: []
29
-
30
67
  extensions: []
31
-
32
68
  extra_rdoc_files: []
33
-
34
- files:
35
- - lib/generators/templates/unobtrusive_flash.css
36
- - lib/generators/templates/unobtrusive_flash.js
37
- - lib/generators/unobtrusive_flash/install/install_generator.rb
38
- - lib/unobtrusive_flash.rb
39
- - lib/unobtrusive_flash/railtie.rb
40
- - generators/unobtrusive_flash/unobtrusive_flash_generator.rb
41
- - rails/init.rb
42
- - init.rb
69
+ files:
70
+ - .gitignore
71
+ - CHANGELOG.md
72
+ - Gemfile
43
73
  - README.markdown
44
- has_rdoc: true
45
- homepage: http://github.com/leonid-shevtsov/unobtrusive_flash
74
+ - Rakefile
75
+ - lib/unobtrusive_flash.rb
76
+ - lib/unobtrusive_flash/controller_mixin.rb
77
+ - lib/unobtrusive_flash/engine.rb
78
+ - lib/unobtrusive_flash/version.rb
79
+ - unobtrusive_flash.gemspec
80
+ - vendor/assets/javascripts/unobtrusive_flash.js
81
+ - vendor/assets/javascripts/unobtrusive_flash_bootstrap.js
82
+ - vendor/assets/javascripts/unobtrusive_flash_ui.js
83
+ - vendor/assets/stylesheets/unobtrusive_flash_ui.css
84
+ homepage: https://github.com/leonid-shevtsov/unobtrusive_flash
46
85
  licenses: []
47
-
86
+ metadata: {}
48
87
  post_install_message:
49
88
  rdoc_options: []
50
-
51
- require_paths:
89
+ require_paths:
52
90
  - lib
53
- required_ruby_version: !ruby/object:Gem::Requirement
54
- none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
62
- required_rubygems_version: !ruby/object:Gem::Requirement
63
- none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- hash: 3
68
- segments:
69
- - 0
70
- version: "0"
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
71
101
  requirements: []
72
-
73
102
  rubyforge_project:
74
- rubygems_version: 1.3.7
103
+ rubygems_version: 2.0.5
75
104
  signing_key:
76
- specification_version: 3
105
+ specification_version: 4
77
106
  summary: Unobtrusive flash messages for Rails
78
107
  test_files: []
79
-
@@ -1,27 +0,0 @@
1
- # encoding: utf-8
2
-
3
- class UnobtrusiveFlashGenerator < Rails::Generator::Base
4
-
5
- def manifest
6
- record do |m|
7
- m.directory File.join('public', 'stylesheets')
8
- m.template 'unobtrusive_flash.css', File.join('public', 'stylesheets', 'unobtrusive_flash.css')
9
-
10
- m.directory File.join('public', 'javascripts')
11
- m.template 'unobtrusive_flash.js', File.join('public', 'javascripts', 'unobtrusive_flash.js')
12
- end
13
- end
14
-
15
- protected
16
-
17
- def banner
18
- %{Usage: #{$0} #{spec.name}\nCopies unobtrusive_flash.css and .js to their corresponding locations}
19
- end
20
-
21
- def source_root
22
- File.expand_path('../../../lib/generators/templates', __FILE__)
23
- end
24
-
25
- end
26
-
27
-
data/init.rb DELETED
@@ -1,2 +0,0 @@
1
- require 'unobtrusive_flash'
2
- ::ActionController::Base.send(:include, UnobtrusiveFlash)
@@ -1,23 +0,0 @@
1
- #flash-messages {
2
- position: fixed;
3
- top: 0;
4
- left: 0;
5
- width: 100%;
6
- z-index: 10000;
7
- }
8
-
9
- #flash-messages .flash-message {
10
- padding: 10px 0;
11
- background: #dcecaa;
12
- opacity: 0.8;
13
- }
14
-
15
- #flash-messages .flash-message.flash-error {
16
- background: #ffe2e2;
17
- }
18
-
19
- #flash-messages .flash-message .message {
20
- width: 960px;
21
- margin: 0 auto;
22
- }
23
-
@@ -1,67 +0,0 @@
1
- // This requires jQuery at least for now
2
- $(function() {
3
- $('<div id="flash-messages"></div>').prependTo('body');
4
-
5
- function hideFlash($flash) {
6
- $flash.slideUp(100,function(){$flash.remove()});
7
- }
8
-
9
- $.flash = function(message, options) {
10
-
11
- options = $.extend({type: 'notice', timeout: 5000}, options);
12
-
13
- var $flash = $('<div class="flash-message flash-'+options.type+' invisible"><div class="message">'+message+'</div></div>');
14
-
15
- $('#flash-messages').prepend($flash);
16
- $flash.slideDown(100);
17
-
18
- $flash.click(function() {
19
- hideFlash($flash);
20
- });
21
-
22
- if (options.timeout>0) {
23
- setTimeout(function() {
24
- hideFlash($flash);
25
- },options.timeout);
26
- }
27
- }
28
-
29
-
30
-
31
- function loadFlashFromCookies() {
32
- if (document.cookie && document.cookie != '') {
33
- var cookies = document.cookie.split(';');
34
- var name = 'flash';
35
- var cookieValue = null;
36
- var data = null;
37
-
38
- for (var i = 0; i < cookies.length; i++) {
39
- var cookie = jQuery.trim(cookies[i]);
40
- if (cookie.substring(0, name.length + 1) == (name + '=')) {
41
- // replace fixes problems with Rails escaping. Duh.
42
- cookieValue = decodeURIComponent(cookie.substring(name.length + 1).replace(/\+/g,'%20'));
43
- break;
44
- }
45
- }
46
-
47
- try {
48
- data = $.parseJSON(cookieValue);
49
- } catch(e) {
50
- }
51
-
52
- if (data!=null) {
53
- $.each(data, function(i, d) {
54
- $.flash(d[1], {type: d[0]});
55
- });
56
- }
57
-
58
- document.cookie = 'flash=; path=/';
59
- }
60
- }
61
-
62
- loadFlashFromCookies();
63
-
64
- $('html').ajaxSuccess(function(event,request,options) {
65
- loadFlashFromCookies();
66
- });
67
- });
@@ -1,15 +0,0 @@
1
- # encoding: utf-8
2
- module UnobtrusiveFlash
3
- class InstallGenerator < Rails::Generators::Base
4
- desc "Copies unobtrusive_flash.css and .js to their corresponding locations"
5
-
6
- source_root File.expand_path('../../../templates', __FILE__)
7
-
8
- def copy_files
9
- empty_directory 'public/stylesheets'
10
- template 'unobtrusive_flash.css', 'public/stylesheets/unobtrusive_flash.css'
11
- empty_directory 'public/javascripts'
12
- template 'unobtrusive_flash.js', 'public/javascripts/unobtrusive_flash.js'
13
- end
14
- end
15
- end
data/rails/init.rb DELETED
@@ -1 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "init.rb"))