accessible_tooltip 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in accessible_tooltip.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Daniel Vandersluis
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,31 @@
1
+ # AccessibleTooltip
2
+
3
+ Rails helper for creating a balloon style tooltip that is WCAG compliant.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'accessible_tooltip'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install accessible_tooltip
18
+
19
+ ## Usage
20
+
21
+ <%= accessible_tooltip(:help, label: "Help Me", title: "Dogs & Foxes") do>
22
+ The quick brown fox jumped over the lazy dog.
23
+ <% end %>
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'accessible_tooltip/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "accessible_tooltip"
8
+ gem.version = AccessibleTooltip::VERSION
9
+ gem.authors = ["Daniel Vandersluis"]
10
+ gem.email = ["dvandersluis@selfmgmt.com"]
11
+ gem.description = %q{WCAG compliant balloon-style tooltip helper for Rails}
12
+ gem.summary = %q{Accessible tooltip helper for Rails}
13
+ gem.homepage = "https://github.com/dvandersluis/accessible_tooltip"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'rails', '>= 3.0.0'
21
+ gem.add_dependency 'sass-rails', '>= 3.0.0'
22
+ end
Binary file
Binary file
@@ -0,0 +1,114 @@
1
+ .accessible_tooltip {
2
+ a {
3
+ color: #000000;
4
+ font-weight: normal;
5
+ outline: none;
6
+ cursor: help;
7
+ text-decoration: none;
8
+ position: relative;
9
+ padding: auto;
10
+
11
+ &:hover, &:focus {
12
+ color: #000000;
13
+ text-decoration: none;
14
+
15
+ // Make the span visible
16
+ & > span.tooltip {
17
+ overflow: visible;
18
+ left: 1em;
19
+ top: 2em;
20
+ z-index: 99;
21
+ height: auto;
22
+ width: 250px;
23
+ padding: 0.5em 0.8em 0.8em 2em;
24
+ border-width: 1px;
25
+ border-style: solid;
26
+ // Clipping values will need to be adjusted if the large icon is moved
27
+ // clip: auto - Does not work properly in IE < 9 with negative positioning
28
+ clip: rect(-10px auto auto -55px);
29
+ clip: rect(-10px, auto, auto, -55px);
30
+ }
31
+ }
32
+
33
+ &:focus img.small-icon {
34
+ outline: 1px dashed #999;
35
+ }
36
+
37
+ & > span.tooltip {
38
+ @include border-radius(5px, 5px);
39
+ @include single-box-shadow(rgba(0, 0, 0, 0.1), 5px, 5px, 5px);
40
+ position: absolute;
41
+ font-weight: normal;
42
+ font-size: 12px;
43
+ color: #000000;
44
+ cursor: auto;
45
+ }
46
+
47
+ span.label {
48
+ border-bottom: 1px dotted #000000;
49
+ margin-right: 4px;
50
+ }
51
+
52
+ img.small-icon {
53
+ padding: 1px;
54
+ position: relative;
55
+ top: -2px;
56
+ border: 0;
57
+ }
58
+ }
59
+
60
+ ul {
61
+ margin-left: 1em;
62
+ margin-top: 10px;
63
+ padding: 0;
64
+ }
65
+
66
+ img.icon {
67
+ height: 48px;
68
+ width: 48px;
69
+ border: 0;
70
+ top: -5px;
71
+ left: -30px;
72
+ float: left;
73
+ position: absolute;
74
+ }
75
+
76
+ em {
77
+ font-size: 14px;
78
+ font-weight: bold;
79
+ display: block;
80
+ padding: 0.2em 0 0.6em 0;
81
+ }
82
+
83
+ * html a:hover { background: transparent; }
84
+ .classic {
85
+ padding: 0.8em 1em;
86
+ background: #FFFFAA;
87
+ border: 1px solid #FFAD33;
88
+ }
89
+ .critical { background: #FFCCAA; border-color: #FF3334; }
90
+ .help, .info { background: #9FDAEE; border-color: #2BB0D7; }
91
+ .warning { background: #FFFFAA; border-color: #FFAD33; }
92
+
93
+ &.left
94
+ {
95
+ a
96
+ {
97
+ &:hover, &:focus
98
+ {
99
+ img.icon
100
+ {
101
+ left: auto;
102
+ right: -30px;
103
+ }
104
+
105
+ & > span.tooltip {
106
+ left: -230px;
107
+ padding: 0.5em 2em 0.8em 0.8em;
108
+ clip: rect(-10px 315px auto -55px);
109
+ clip: rect(-10px, 315px, auto, -55px);
110
+ }
111
+ }
112
+ }
113
+ }
114
+ }
@@ -0,0 +1,55 @@
1
+ module AccessibleTooltip
2
+ module Helpers
3
+ def accessible_tooltip(type, *args, &block)
4
+ partial_name = (block_given? ? Time.now.to_i + rand : args.shift)
5
+ raise ArgumentError, "Either a block or a partial name must be specified" if !partial_name or partial_name.is_a?(Hash)
6
+ partial_name = partial_name.to_s
7
+
8
+ type = type.to_sym
9
+ types = [:critical, :info, :help, :warning]
10
+ raise ArgumentError, "type must be one of #{types.join(", ")}" unless types.include?(type)
11
+
12
+ if args.first.is_a? Hash
13
+ element = :span
14
+ options = args.shift || {}
15
+ else
16
+ element = args.shift.andand.to_sym || :span
17
+ options = args.shift || {}
18
+ end
19
+
20
+ html_options = options.delete(:html) || {}
21
+ link_options = options.delete(:link) || {}
22
+ link_options.reverse_merge!(onclick: "return false")
23
+ title = options.delete(:title)
24
+ label = options.delete(:label)
25
+ position = options.delete(:position)
26
+ container_class = ["accessible_tooltip"]
27
+ container_class << "left" if position == :left
28
+
29
+ content_tag(:span, class: container_class.join(" ")) do
30
+ link_to options.fetch(:url, "#"), link_options do
31
+
32
+ title = t(title) if title.is_a?(Symbol)
33
+ label = t(label) if label.is_a?(Symbol)
34
+ tooltip = (type == :help and !title.blank?) ? :tooltip_help_for : :"tooltip_#{type}"
35
+
36
+ out = ActiveSupport::SafeBuffer.new
37
+ out << content_tag(:span, label, class: "label") unless label.blank?
38
+ out << image_tag("tooltip_#{type}_small.png", alt: t(:tooltip_help), style: 'vertical-align: middle;', class: "small-icon") if options.fetch(:icon, true)
39
+ out << content_tag(:span, class: "custom #{type} tooltip") do
40
+ popup = ActiveSupport::SafeBuffer.new
41
+ popup << image_tag("tooltip_#{type}.png", alt: t(tooltip), class: "icon")
42
+ popup << content_tag(:em, title) unless title.blank?
43
+
44
+ if block_given?
45
+ popup << capture(&block)
46
+ else
47
+ # Try to find a partial with a _tooltip suffix, or just the given partial name if not found
48
+ popup << (render(:partial => "#{partial_name}_tooltip") rescue render(:partial => partial_name))
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ module AccessibleTooltip
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,12 @@
1
+ require 'accessible_tooltip/version'
2
+ require 'accessible_tooltip/helpers'
3
+
4
+ module AccessibleTooltip
5
+ class Engine < Rails::Engine
6
+ initializer 'accessible_tooltip.hook_into_action_view' do
7
+ ActiveSupport.on_load :action_view do
8
+ include AccessibleTooltip::Helpers
9
+ end
10
+ end
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: accessible_tooltip
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Daniel Vandersluis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ prerelease: false
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ none: false
23
+ type: :runtime
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ! '>='
27
+ - !ruby/object:Gem::Version
28
+ version: 3.0.0
29
+ none: false
30
+ - !ruby/object:Gem::Dependency
31
+ name: sass-rails
32
+ prerelease: false
33
+ requirement: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 3.0.0
38
+ none: false
39
+ type: :runtime
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: 3.0.0
45
+ none: false
46
+ description: WCAG compliant balloon-style tooltip helper for Rails
47
+ email:
48
+ - dvandersluis@selfmgmt.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - accessible_tooltip.gemspec
59
+ - app/assets/images/tooltip_critical.png
60
+ - app/assets/images/tooltip_critical_small.png
61
+ - app/assets/images/tooltip_help.png
62
+ - app/assets/images/tooltip_help_small.png
63
+ - app/assets/images/tooltip_info.png
64
+ - app/assets/images/tooltip_warning.png
65
+ - app/assets/stylesheets/accessible_tooltip/styles.css.scss
66
+ - lib/accessible_tooltip.rb
67
+ - lib/accessible_tooltip/helpers.rb
68
+ - lib/accessible_tooltip/version.rb
69
+ homepage: https://github.com/dvandersluis/accessible_tooltip
70
+ licenses: []
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ none: false
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ none: false
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 1.8.24
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Accessible tooltip helper for Rails
93
+ test_files: []
94
+ has_rdoc: