simple-tooltip 0.0.1 → 0.0.2
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/README.markdown +27 -6
- data/lib/generators/simple_tooltip/templates/app/helpers/tooltip_helper.rb +4 -2
- data/lib/generators/simple_tooltip/templates/app/models/tooltip.rb +2 -3
- data/lib/generators/simple_tooltip/templates/app/views/tooltips/_form.html.erb +6 -4
- data/lib/generators/simple_tooltip/templates/public/javascripts/simple_tooltip.js +24 -9
- data/lib/generators/simple_tooltip/templates/public/stylesheets/simple_tooltip.css +1 -0
- data/lib/simple_tooltip/version.rb +1 -1
- data/simple_tooltip.gemspec +2 -2
- metadata +5 -5
data/README.markdown
CHANGED
@@ -9,7 +9,7 @@ text of the help message directly in the content of each page.
|
|
9
9
|
But this approach fails when the information requires more than one paragraph and when more than plain
|
10
10
|
text is required. For example, the help message might require a link to an external web site.
|
11
11
|
|
12
|
-
With
|
12
|
+
With Simple Tooltip you create tooltip help content in a web form and record it in the database via a Tooltip model.
|
13
13
|
Content can be created in plain text, HTML, Markdown and Textile, allowing tooltips to use the
|
14
14
|
full features of HTML, including links, CSS styling, etc.
|
15
15
|
|
@@ -20,9 +20,9 @@ Tooltip records include a locale column that defines the language used for their
|
|
20
20
|
be created with the same title but different locales. When a given title is requested, the code tries to find
|
21
21
|
a version that matches the user's current locale.
|
22
22
|
|
23
|
-
|
23
|
+
Simple Tooltip helps bridge the gap between short, fixed tooltips and full help pages.
|
24
24
|
|
25
|
-
Tooltips are displayed via
|
25
|
+
Tooltips are displayed via [jQuery](http://jquery.com "jQuery") script. They can be configured to appear transiently when a user hovers over a link icon,
|
26
26
|
or to appear when the link icon is clicked, remaining until closed by a click within the tooltip.
|
27
27
|
|
28
28
|
|
@@ -35,13 +35,13 @@ Developers can customize the styling of the tooltip content via CSS definitions
|
|
35
35
|
Prerequisites
|
36
36
|
=============
|
37
37
|
|
38
|
-
The initial release of
|
38
|
+
The initial release of Simple Tooltip works with [Rails 3](http://rubyonrails.org "Rails 3") and [jQuery](http://jquery.com "jQuery"). It is not expected to work with Rails 2.
|
39
39
|
|
40
40
|
|
41
41
|
Installation
|
42
42
|
============
|
43
43
|
|
44
|
-
|
44
|
+
Simple Tooltip is distributed as a Ruby Gem and is installed in an application via a Rails generator.
|
45
45
|
|
46
46
|
1: Install the gem on your system
|
47
47
|
|
@@ -129,7 +129,28 @@ tooltip content is displayed.
|
|
129
129
|
|
130
130
|
The jQuery JavaScript is found at `public/javascripts/simple_tooltip.js`. You should not need to modify this file.
|
131
131
|
|
132
|
-
|
132
|
+
|
133
|
+
Internationaliztion
|
134
|
+
===================
|
135
|
+
|
136
|
+
Simple Tooltip helps you provide help in multiple languages. Rails itself provides extensive support through the <a href="http://guides.rubyonrails.org/i18n.html">I18n functions</a>, but this mostly targets short text strings, such as
|
137
|
+
labels for form fields, standard error messages, etc.
|
138
|
+
|
139
|
+
To support multiple languages in Simple Tooltip, you create multiple Tooltip database records with the same Title but
|
140
|
+
different Locales (specified in ISO-639-1 Two letter format, e.g. 'de').
|
141
|
+
|
142
|
+
The code uses the value of I18n.locale as defined by your application, and defaults to I18n.default_locale. If it can find
|
143
|
+
a version of the tooltip that matches the user's locale then it will use it.
|
144
|
+
|
145
|
+
If you don't want to use internationalization then don't worry about it. Just leave the 'locale' field blank in the tooltip form.
|
146
|
+
|
147
|
+
While this mechanism is separate from the Rails I18n approach, I think it offers some advantages when you want to create
|
148
|
+
large blocks of help text.
|
149
|
+
|
150
|
+
Author
|
151
|
+
======
|
152
|
+
|
153
|
+
Simple Tooltip is written by [Rob Jones](http://github.com/craic "Rob Jones") at [Craic Computing](http://craic.com "Craic Computing") in Seattle. It is distributed freely under the MIT license.
|
133
154
|
|
134
155
|
|
135
156
|
|
@@ -15,9 +15,11 @@ module TooltipHelper
|
|
15
15
|
else
|
16
16
|
title = text
|
17
17
|
end
|
18
|
-
|
18
|
+
# Add the locale to the class string - e.g. locale_de
|
19
|
+
class_str << " locale_#{I18n.locale.to_s}"
|
20
|
+
|
19
21
|
link_to(image_tag(tooltip_help_icon_file),
|
20
|
-
tooltip_content_tooltips_path(:title => text),
|
22
|
+
tooltip_content_tooltips_path(:title => text, :locale => I18n.locale.to_s),
|
21
23
|
:name => text, :title => title,
|
22
24
|
:class => class_str)
|
23
25
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
require 'rdiscount'
|
4
|
+
require 'RedCloth'
|
4
5
|
|
5
6
|
class Tooltip < ActiveRecord::Base
|
6
7
|
|
@@ -24,9 +25,8 @@ class Tooltip < ActiveRecord::Base
|
|
24
25
|
validate :validate_unique_title_locale_combination, :on => :create
|
25
26
|
|
26
27
|
|
27
|
-
# find the tooltip that matches the title and locale
|
28
|
+
# find the tooltip that matches the title and locale - locale is a string
|
28
29
|
def self.from_title_and_locale(title, user_locale = I18n.locale.to_s)
|
29
|
-
|
30
30
|
tooltip = nil
|
31
31
|
tooltips = Tooltip.where(:title => title).all
|
32
32
|
|
@@ -35,7 +35,6 @@ class Tooltip < ActiveRecord::Base
|
|
35
35
|
tooltip = tooltips.first
|
36
36
|
|
37
37
|
elsif tooltips.count > 1
|
38
|
-
|
39
38
|
# Try and match by locale
|
40
39
|
default_tooltip = nil
|
41
40
|
tooltips.each do |tooltip_i|
|
@@ -17,11 +17,11 @@
|
|
17
17
|
</div>
|
18
18
|
<div class="field">
|
19
19
|
<%= f.label :content %><br />
|
20
|
-
<%= f.text_area :content %>
|
20
|
+
<%= f.text_area :content, :rows => 10, :cols => 70 %>
|
21
21
|
</div>
|
22
22
|
<div class="field">
|
23
23
|
<%= f.label :locale %><br />
|
24
|
-
<%= f.text_field :locale %> Use two letter ISO-639-1 code
|
24
|
+
<%= f.text_field :locale, :size => 5 %> Use two letter ISO-639-1 code (e.g. en, de, etc)
|
25
25
|
</div>
|
26
26
|
<div class="field">
|
27
27
|
<%= f.label :markup %><br />
|
@@ -29,9 +29,11 @@
|
|
29
29
|
<%= f.radio_button :markup, 'textile' %> Textile
|
30
30
|
<%= f.radio_button :markup, 'html' %> HTML / Plain Text
|
31
31
|
<br/>
|
32
|
-
<
|
32
|
+
<p>
|
33
|
+
<a href="http://en.wikipedia.org/wiki/Markdown">Markdown syntax reference</a>
|
33
34
|
<br/>
|
34
|
-
<a href="http://redcloth.org/textile">Textile syntax</a>
|
35
|
+
<a href="http://redcloth.org/textile">Textile syntax reference</a>
|
36
|
+
</p>
|
35
37
|
|
36
38
|
</div>
|
37
39
|
|
@@ -2,20 +2,22 @@
|
|
2
2
|
jQuery(document).ready(function() {
|
3
3
|
|
4
4
|
var close_icon_file = "/images/simple_tooltip_close_icon.png";
|
5
|
-
|
5
|
+
var url = null;
|
6
|
+
|
6
7
|
jQuery('.simple-tooltip-help-icon').mouseenter(function(e) {
|
7
8
|
// remove any existing tooltip - should not be necessary, just a safety clause
|
8
9
|
|
9
|
-
// this has the side efect of removing any other visible tooltip on entering any other icon
|
10
|
+
// this has the side efect of removing any other visible tooltip on entering any other icon
|
10
11
|
jQuery("#simple-tooltip").remove();
|
11
12
|
|
12
13
|
// setup tooltip on hover
|
13
14
|
if(!jQuery(this).hasClass('simple-tooltip-clickable')) {
|
14
15
|
// Remove the 'title' attribute to prevent it appearing on hover
|
15
16
|
this.title = null;
|
16
|
-
|
17
|
+
|
17
18
|
// get the content for this tooltip by ajax and create the popup
|
18
|
-
|
19
|
+
url = "/tooltips/tooltip_content?js=true&title=" + this.name + "&locale=" + get_locale(this.className);
|
20
|
+
jQuery.get(url, function(data) {
|
19
21
|
|
20
22
|
jQuery("body").append("<div id='simple-tooltip'>" + data + "</div>");
|
21
23
|
|
@@ -37,9 +39,9 @@ jQuery(document).ready(function() {
|
|
37
39
|
|
38
40
|
// setup tooltip on click
|
39
41
|
if(jQuery(this).hasClass('simple-tooltip-clickable')) {
|
40
|
-
|
41
|
-
|
42
|
-
jQuery.get(
|
42
|
+
|
43
|
+
url = "/tooltips/tooltip_content?js=true&title=" + this.name + "&locale=" + get_locale(this.className);
|
44
|
+
jQuery.get(url, function(data) {
|
43
45
|
|
44
46
|
// setup a close button within the tooltip at top right
|
45
47
|
var close_div = "<div id=\"simple-tooltip-close\" class=\"simple-tooltip-close\">" +
|
@@ -54,8 +56,7 @@ jQuery(document).ready(function() {
|
|
54
56
|
jQuery('#simple-tooltip-close').click(function() {
|
55
57
|
jQuery("#simple-tooltip").remove();
|
56
58
|
});
|
57
|
-
// ?? remove tooltip if the tooltip_icon is clicked a second time ??
|
58
|
-
|
59
|
+
// ?? remove tooltip if the tooltip_icon is clicked a second time ??
|
59
60
|
});
|
60
61
|
}
|
61
62
|
|
@@ -66,3 +67,17 @@ jQuery(document).ready(function() {
|
|
66
67
|
}
|
67
68
|
});
|
68
69
|
});
|
70
|
+
|
71
|
+
|
72
|
+
// Get the current local from a class called 'locale_xx' - e.g. locale_de
|
73
|
+
function get_locale(class_string) {
|
74
|
+
var locale = null;
|
75
|
+
var classes = class_string.split(/\s+/);
|
76
|
+
for (var i=0;i<classes.length;i++) {
|
77
|
+
var match = classes[i].match(/locale_(\S+)/)
|
78
|
+
if(match) {
|
79
|
+
locale = match[1];
|
80
|
+
}
|
81
|
+
}
|
82
|
+
return locale;
|
83
|
+
}
|
data/simple_tooltip.gemspec
CHANGED
@@ -11,8 +11,8 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.homepage = "http://rubygems.org/gems/simple-tooltip"
|
12
12
|
s.summary = %q{Create and display Tooltip Help in view pages in Rails applications}
|
13
13
|
s.description = %q{Create and display Tooltip Help in view pages in Rails applications.
|
14
|
-
Uses jQuery to display tooltips, with fallback if
|
15
|
-
Makes use of help text in the user's locale if available.
|
14
|
+
Uses jQuery to display tooltips, with html fallback if JavaScript is not available.
|
15
|
+
Makes use of help text in the user's locale if available.}
|
16
16
|
|
17
17
|
|
18
18
|
s.add_dependency "rails", "~> 3.0"
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Robert Jones
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-03-
|
17
|
+
date: 2011-03-07 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -102,8 +102,8 @@ dependencies:
|
|
102
102
|
version_requirements: *id006
|
103
103
|
description: |-
|
104
104
|
Create and display Tooltip Help in view pages in Rails applications.
|
105
|
-
Uses jQuery to display tooltips, with fallback if
|
106
|
-
Makes use of help text in the user's locale if available.
|
105
|
+
Uses jQuery to display tooltips, with html fallback if JavaScript is not available.
|
106
|
+
Makes use of help text in the user's locale if available.
|
107
107
|
email:
|
108
108
|
- jones@craic.com
|
109
109
|
executables: []
|