flashlight 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +15 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/flashlight.js +2 -0
- data/app/assets/javascripts/flashlight/flashlight.js.coffee +43 -0
- data/app/assets/javascripts/flashlight/jquery.cookie.js.coffee +100 -0
- data/app/assets/stylesheets/flashlight.css +49 -0
- data/flashlight.gemspec +26 -0
- data/lib/flashlight.rb +5 -0
- data/lib/flashlight/concerns/controllers/flashing.rb +18 -0
- data/lib/flashlight/engine.rb +11 -0
- data/lib/flashlight/version.rb +3 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 96a751f7f1c76bf85f5426506f10935e5e075d36
|
4
|
+
data.tar.gz: 0ce844e94f889c84e30dadbd41bffc9cc2a40fe0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3b93e6d194ffea08f4c28dd0d9e933062f5423054261992b68d54ec0e975b71d9477d07f7c75e21320d1535f2524cec4096e0a35fa1a38a1226689dfac8574a7
|
7
|
+
data.tar.gz: 4f4b98ee9af10648e9772387aaadb982aa439271c11a28368ba7862eb6c6701039ca503bd941419fe42fd38f140e80c25d99311926e09c3e776f5f38ab01a50d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Sergio Bayona
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
flashlight
|
2
|
+
=======
|
3
|
+
|
4
|
+
Rails flash that works for ajax and old-fashion page loads. Tested on Rails 4.1 (with Turbolinks).
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
1. Add ```gem 'flashlight', github: "martianinteractive/flashlight"``` to your Gemfile
|
9
|
+
|
10
|
+
2. Add ```//= require flashlight``` to your app/assets/javascripts/application.js
|
11
|
+
|
12
|
+
3. Add ```*= require flashlight``` to your app/assets/stylesheets/application.css
|
13
|
+
|
14
|
+
|
15
|
+
That's it.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,43 @@
|
|
1
|
+
jQuery ->
|
2
|
+
$.cookie.json = true
|
3
|
+
$('<div id="flashlight-container"></div>').prependTo 'body'
|
4
|
+
|
5
|
+
$(document).on 'page:load', ->
|
6
|
+
$('<div id="flashlight-container"></div>').prependTo 'body'
|
7
|
+
|
8
|
+
Flashlight.show()
|
9
|
+
|
10
|
+
$(document).on 'ajaxComplete', (event, request) ->
|
11
|
+
Flashlight.show()
|
12
|
+
|
13
|
+
Flashlight = (->
|
14
|
+
hideFlash = (flash) ->
|
15
|
+
flash.slideUp 100, ->
|
16
|
+
flash.remove()
|
17
|
+
|
18
|
+
flashMessage = (message, options) ->
|
19
|
+
options = $.extend(type: "notice", timeout: 5000, options)
|
20
|
+
|
21
|
+
flash = $("<div class='flashlight-wrapper'><div class='flash #{message['type']}'>#{message['message']}</div></div>")
|
22
|
+
$("#flashlight-container").prepend flash
|
23
|
+
flash.hide().delay(300).slideDown 100
|
24
|
+
flash.click ->
|
25
|
+
hideFlash flash
|
26
|
+
|
27
|
+
setTimeout (->
|
28
|
+
hideFlash flash
|
29
|
+
), options.timeout
|
30
|
+
|
31
|
+
getFlashFromCookies = (request) ->
|
32
|
+
if flash = $.cookie('flash')
|
33
|
+
$.removeCookie('flash');
|
34
|
+
flash
|
35
|
+
|
36
|
+
show: ->
|
37
|
+
flashMessages = getFlashFromCookies() || []
|
38
|
+
$.each flashMessages, (_, message) ->
|
39
|
+
flashMessage(type: message[0], message: message[1])
|
40
|
+
|
41
|
+
)()
|
42
|
+
|
43
|
+
|
@@ -0,0 +1,100 @@
|
|
1
|
+
#!
|
2
|
+
# * jQuery Cookie Plugin v1.4.0
|
3
|
+
# * https://github.com/carhartl/jquery-cookie
|
4
|
+
# *
|
5
|
+
# * Copyright 2013 Klaus Hartl
|
6
|
+
# * Released under the MIT license
|
7
|
+
#
|
8
|
+
((factory) ->
|
9
|
+
if typeof define is "function" and define.amd
|
10
|
+
|
11
|
+
# AMD
|
12
|
+
define ["jquery"], factory
|
13
|
+
else if typeof exports is "object"
|
14
|
+
|
15
|
+
# CommonJS
|
16
|
+
factory require("jquery")
|
17
|
+
else
|
18
|
+
|
19
|
+
# Browser globals
|
20
|
+
factory jQuery
|
21
|
+
return
|
22
|
+
) ($) ->
|
23
|
+
encode = (s) ->
|
24
|
+
(if config.raw then s else encodeURIComponent(s))
|
25
|
+
decode = (s) ->
|
26
|
+
(if config.raw then s else decodeURIComponent(s))
|
27
|
+
stringifyCookieValue = (value) ->
|
28
|
+
encode (if config.json then JSON.stringify(value) else String(value))
|
29
|
+
parseCookieValue = (s) ->
|
30
|
+
|
31
|
+
# This is a quoted cookie as according to RFC2068, unescape...
|
32
|
+
s = s.slice(1, -1).replace(/\\"/g, "\"").replace(/\\\\/g, "\\") if s.indexOf("\"") is 0
|
33
|
+
try
|
34
|
+
|
35
|
+
# Replace server-side written pluses with spaces.
|
36
|
+
# If we can't decode the cookie, ignore it, it's unusable.
|
37
|
+
# If we can't parse the cookie, ignore it, it's unusable.
|
38
|
+
s = decodeURIComponent(s.replace(pluses, " "))
|
39
|
+
return (if config.json then JSON.parse(s) else s)
|
40
|
+
return
|
41
|
+
read = (s, converter) ->
|
42
|
+
value = (if config.raw then s else parseCookieValue(s))
|
43
|
+
(if $.isFunction(converter) then converter(value) else value)
|
44
|
+
pluses = /\+/g
|
45
|
+
config = $.cookie = (key, value, options) ->
|
46
|
+
|
47
|
+
# Write
|
48
|
+
if value isnt `undefined` and not $.isFunction(value)
|
49
|
+
options = $.extend({}, config.defaults, options)
|
50
|
+
if typeof options.expires is "number"
|
51
|
+
days = options.expires
|
52
|
+
t = options.expires = new Date()
|
53
|
+
t.setTime +t + days * 864e+5
|
54
|
+
# use expires attribute, max-age is not supported by IE
|
55
|
+
return (document.cookie = [
|
56
|
+
encode(key)
|
57
|
+
"="
|
58
|
+
stringifyCookieValue(value)
|
59
|
+
(if options.expires then "; expires=" + options.expires.toUTCString() else "")
|
60
|
+
(if options.path then "; path=" + options.path else "")
|
61
|
+
(if options.domain then "; domain=" + options.domain else "")
|
62
|
+
(if options.secure then "; secure" else "")
|
63
|
+
].join(""))
|
64
|
+
|
65
|
+
# Read
|
66
|
+
result = (if key then `undefined` else {})
|
67
|
+
|
68
|
+
# To prevent the for loop in the first place assign an empty array
|
69
|
+
# in case there are no cookies at all. Also prevents odd result when
|
70
|
+
# calling $.cookie().
|
71
|
+
cookies = (if document.cookie then document.cookie.split("; ") else [])
|
72
|
+
i = 0
|
73
|
+
l = cookies.length
|
74
|
+
|
75
|
+
while i < l
|
76
|
+
parts = cookies[i].split("=")
|
77
|
+
name = decode(parts.shift())
|
78
|
+
cookie = parts.join("=")
|
79
|
+
if key and key is name
|
80
|
+
|
81
|
+
# If second argument (value) is a function it's a converter...
|
82
|
+
result = read(cookie, value)
|
83
|
+
break
|
84
|
+
|
85
|
+
# Prevent storing a cookie that we couldn't decode.
|
86
|
+
result[name] = cookie if not key and (cookie = read(cookie)) isnt `undefined`
|
87
|
+
i++
|
88
|
+
result
|
89
|
+
|
90
|
+
config.defaults = {}
|
91
|
+
$.removeCookie = (key, options) ->
|
92
|
+
return false if $.cookie(key) is `undefined`
|
93
|
+
|
94
|
+
# Must not alter options, thus extending a fresh object...
|
95
|
+
$.cookie key, "", $.extend({}, options,
|
96
|
+
expires: -1
|
97
|
+
)
|
98
|
+
not $.cookie(key)
|
99
|
+
|
100
|
+
return
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#flashlight-container {
|
2
|
+
position: fixed;
|
3
|
+
top: 0;
|
4
|
+
left: 0;
|
5
|
+
z-index: 10000;
|
6
|
+
cursor: pointer;
|
7
|
+
width: 100%;
|
8
|
+
text-align: center;
|
9
|
+
}
|
10
|
+
|
11
|
+
#flashlight-container .flashlight-wrapper {
|
12
|
+
margin-top: 4px;
|
13
|
+
text-align: left;
|
14
|
+
width: 340px;
|
15
|
+
display: inline-block;
|
16
|
+
}
|
17
|
+
|
18
|
+
#flashlight-container .flashlight-wrapper .flash {
|
19
|
+
padding: 3px;
|
20
|
+
border-radius: 3px;
|
21
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
22
|
+
border: 1px solid rgba(0, 0, 0, 0);
|
23
|
+
}
|
24
|
+
|
25
|
+
#flashlight-container .flashlight-wrapper .error,
|
26
|
+
#flashlight-container .flashlight-wrapper .alert {
|
27
|
+
background: #F2DEDE;
|
28
|
+
border-color: #EBCCD1;
|
29
|
+
color: #A94442;
|
30
|
+
}
|
31
|
+
|
32
|
+
#flashlight-container .flashlight-wrapper .success {
|
33
|
+
background-color: #DFF0D8;
|
34
|
+
border-color: #D6E9C6;
|
35
|
+
color: #3C763D;
|
36
|
+
}
|
37
|
+
|
38
|
+
#flashlight-container .flashlight-wrapper .notice {
|
39
|
+
background-color: #D9EDF7;
|
40
|
+
border-color: #BCE8F1;
|
41
|
+
color: #31708F;
|
42
|
+
}
|
43
|
+
|
44
|
+
#flashlight-container .flashlight-wrapper .warning {
|
45
|
+
background-color: #FCF8E3;
|
46
|
+
border-color: #FAEBCC;
|
47
|
+
color: #8A6D3B;
|
48
|
+
}
|
49
|
+
|
data/flashlight.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'flashlight/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "flashlight"
|
8
|
+
spec.version = Flashlight::VERSION
|
9
|
+
spec.authors = ["Sergio Bayona"]
|
10
|
+
spec.email = ["sbayona@martianinteractive.com"]
|
11
|
+
spec.summary = "Flash messages for Rails"
|
12
|
+
spec.description = <<EOT
|
13
|
+
flashlight displays your rails flash messages. Works with old flashion page loads and AJAX.
|
14
|
+
EOT
|
15
|
+
spec.homepage = "https://github.com/martianinteractive/flashlight"
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "railties", "~> 3.2"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
data/lib/flashlight.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Flashlight
|
2
|
+
module Concerns
|
3
|
+
module Controllers
|
4
|
+
module Flashing
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.after_filter :flash_to_cookie
|
8
|
+
end
|
9
|
+
|
10
|
+
def flash_to_cookie
|
11
|
+
cookies[:flash] = nil if flash.empty? && cookies[:flash].present?
|
12
|
+
return unless flash.any?
|
13
|
+
cookies[:flash] = {:value => flash.to_json}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'flashlight'
|
2
|
+
require "flashlight/concerns/controllers/flashing"
|
3
|
+
require 'rails'
|
4
|
+
|
5
|
+
module Flashlight
|
6
|
+
class Engine < ::Rails::Engine
|
7
|
+
initializer 'flashlight.initialize', :after => :after_initialize do
|
8
|
+
ActionController::Base.send :include, Flashlight::Concerns::Controllers::Flashing
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flashlight
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergio Bayona
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-12 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: '3.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
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.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: |
|
56
|
+
flashlight displays your rails flash messages. Works with old flashion page loads and AJAX.
|
57
|
+
email:
|
58
|
+
- sbayona@martianinteractive.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- app/assets/javascripts/flashlight.js
|
69
|
+
- app/assets/javascripts/flashlight/flashlight.js.coffee
|
70
|
+
- app/assets/javascripts/flashlight/jquery.cookie.js.coffee
|
71
|
+
- app/assets/stylesheets/flashlight.css
|
72
|
+
- flashlight.gemspec
|
73
|
+
- lib/flashlight.rb
|
74
|
+
- lib/flashlight/concerns/controllers/flashing.rb
|
75
|
+
- lib/flashlight/engine.rb
|
76
|
+
- lib/flashlight/version.rb
|
77
|
+
homepage: https://github.com/martianinteractive/flashlight
|
78
|
+
licenses: []
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.4.7
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Flash messages for Rails
|
100
|
+
test_files: []
|