tipsy_svg 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/lib/tipsy_svg/engine.rb +6 -0
- data/lib/tipsy_svg/version.rb +3 -0
- data/lib/tipsy_svg.rb +3 -0
- data/tipsy_svg.gemspec +24 -0
- data/vendor/javascripts/tipsy.js +288 -0
- data/vendor/stylesheets/tipsy.css +25 -0
- metadata +89 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/tipsy_svg.rb
ADDED
data/tipsy_svg.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "tipsy_svg/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "tipsy_svg"
|
7
|
+
s.version = TipsySvg::VERSION
|
8
|
+
s.authors = ["Han"]
|
9
|
+
s.email = ["han@logicallsat.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Jquery Tipsy plugin automated install for Rails 3.1+}
|
12
|
+
s.description = %q{Gem installation for the jquery plugin for nicer tooltips, tipsy. }
|
13
|
+
|
14
|
+
s.rubyforge_project = "tipsy_svg"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib", "vendor"]
|
20
|
+
|
21
|
+
s.add_dependency "railties", ">= 3.1.0"
|
22
|
+
s.add_development_dependency "bundler", "~> 1.0.0"
|
23
|
+
s.add_development_dependency "rails", "~> 3.1"
|
24
|
+
end
|
@@ -0,0 +1,288 @@
|
|
1
|
+
// tipsy, facebook style tooltips for jquery
|
2
|
+
// version 1.0.0a
|
3
|
+
// (c) 2008-2010 jason frame [jason@onehackoranother.com]
|
4
|
+
// released under the MIT license
|
5
|
+
|
6
|
+
(function($) {
|
7
|
+
|
8
|
+
function maybeCall(thing, ctx) {
|
9
|
+
return (typeof thing == 'function') ? (thing.call(ctx)) : thing;
|
10
|
+
}
|
11
|
+
|
12
|
+
function Tipsy(element, options) {
|
13
|
+
this.$element = $(element);
|
14
|
+
this.options = options;
|
15
|
+
this.enabled = true;
|
16
|
+
this.fixTitle();
|
17
|
+
}
|
18
|
+
|
19
|
+
Tipsy.prototype = {
|
20
|
+
show: function() {
|
21
|
+
var title = this.getTitle();
|
22
|
+
if (title && this.enabled) {
|
23
|
+
var $tip = this.tip();
|
24
|
+
|
25
|
+
$tip.find('.tipsy-inner')[this.options.html ? 'html' : 'text'](title);
|
26
|
+
$tip[0].className = 'tipsy'; // reset classname in case of dynamic gravity
|
27
|
+
$tip.remove().css({top: 0, left: 0, visibility: 'hidden', display: 'block'}).prependTo(document.body);
|
28
|
+
|
29
|
+
var pos = $.extend({}, this.$element.offset(), {
|
30
|
+
width: this.$element[0].offsetWidth || 0,
|
31
|
+
height: this.$element[0].offsetHeight || 0
|
32
|
+
});
|
33
|
+
|
34
|
+
if (typeof this.$element[0].nearestViewportElement == 'object') {
|
35
|
+
// SVG
|
36
|
+
var el = this.$element[0];
|
37
|
+
var rect = el.getBoundingClientRect();
|
38
|
+
pos.width = rect.width;
|
39
|
+
pos.height = rect.height;
|
40
|
+
}
|
41
|
+
|
42
|
+
|
43
|
+
var actualWidth = $tip[0].offsetWidth,
|
44
|
+
actualHeight = $tip[0].offsetHeight,
|
45
|
+
gravity = maybeCall(this.options.gravity, this.$element[0]);
|
46
|
+
|
47
|
+
var tp;
|
48
|
+
switch (gravity.charAt(0)) {
|
49
|
+
case 'n':
|
50
|
+
tp = {top: pos.top + pos.height + this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2};
|
51
|
+
break;
|
52
|
+
case 's':
|
53
|
+
tp = {top: pos.top - actualHeight - this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2};
|
54
|
+
break;
|
55
|
+
case 'e':
|
56
|
+
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth - this.options.offset};
|
57
|
+
break;
|
58
|
+
case 'w':
|
59
|
+
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width + this.options.offset};
|
60
|
+
break;
|
61
|
+
}
|
62
|
+
|
63
|
+
if (gravity.length == 2) {
|
64
|
+
if (gravity.charAt(1) == 'w') {
|
65
|
+
tp.left = pos.left + pos.width / 2 - 15;
|
66
|
+
} else {
|
67
|
+
tp.left = pos.left + pos.width / 2 - actualWidth + 15;
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
$tip.css(tp).addClass('tipsy-' + gravity);
|
72
|
+
$tip.find('.tipsy-arrow')[0].className = 'tipsy-arrow tipsy-arrow-' + gravity.charAt(0);
|
73
|
+
if (this.options.className) {
|
74
|
+
$tip.addClass(maybeCall(this.options.className, this.$element[0]));
|
75
|
+
}
|
76
|
+
|
77
|
+
if (this.options.fade) {
|
78
|
+
$tip.stop().css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: this.options.opacity});
|
79
|
+
} else {
|
80
|
+
$tip.css({visibility: 'visible', opacity: this.options.opacity});
|
81
|
+
}
|
82
|
+
|
83
|
+
var t = this;
|
84
|
+
var set_hovered = function(set_hover){
|
85
|
+
return function(){
|
86
|
+
t.$tip.stop();
|
87
|
+
t.tipHovered = set_hover;
|
88
|
+
if (!set_hover){
|
89
|
+
if (t.options.delayOut === 0) {
|
90
|
+
t.hide();
|
91
|
+
} else {
|
92
|
+
setTimeout(function() {
|
93
|
+
if (t.hoverState == 'out') t.hide(); }, t.options.delayOut);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
};
|
97
|
+
};
|
98
|
+
$tip.hover(set_hovered(true), set_hovered(false));
|
99
|
+
}
|
100
|
+
},
|
101
|
+
|
102
|
+
hide: function() {
|
103
|
+
if (this.options.fade) {
|
104
|
+
this.tip().stop().fadeOut(function() { $(this).remove(); });
|
105
|
+
} else {
|
106
|
+
this.tip().remove();
|
107
|
+
}
|
108
|
+
},
|
109
|
+
|
110
|
+
fixTitle: function() {
|
111
|
+
var $e = this.$element;
|
112
|
+
|
113
|
+
if ($e.attr('title') || typeof($e.attr('original-title')) != 'string') {
|
114
|
+
$e.attr('original-title', $e.attr('title') || '').removeAttr('title');
|
115
|
+
}
|
116
|
+
if (typeof $e.context.nearestViewportElement == 'object'){
|
117
|
+
if ($e.children('title').length){
|
118
|
+
$e.append('<original-title>' + ($e.children('title').text() || '') + '</original-title>')
|
119
|
+
.children('title').remove();
|
120
|
+
}
|
121
|
+
}
|
122
|
+
},
|
123
|
+
|
124
|
+
getTitle: function() {
|
125
|
+
|
126
|
+
var title, $e = this.$element, o = this.options;
|
127
|
+
this.fixTitle();
|
128
|
+
|
129
|
+
if (typeof o.title == 'string') {
|
130
|
+
var title_name = o.title == 'title' ? 'original-title' : o.title;
|
131
|
+
if ($e.children(title_name).length){
|
132
|
+
title = $e.children(title_name).html();
|
133
|
+
} else{
|
134
|
+
title = $e.attr(title_name);
|
135
|
+
}
|
136
|
+
|
137
|
+
} else if (typeof o.title == 'function') {
|
138
|
+
title = o.title.call($e[0]);
|
139
|
+
}
|
140
|
+
title = ('' + title).replace(/(^\s*|\s*$)/, "");
|
141
|
+
return title || o.fallback;
|
142
|
+
},
|
143
|
+
|
144
|
+
tip: function() {
|
145
|
+
if (!this.$tip) {
|
146
|
+
this.$tip = $('<div class="tipsy"></div>').html('<div class="tipsy-arrow"></div><div class="tipsy-inner"></div>');
|
147
|
+
}
|
148
|
+
return this.$tip;
|
149
|
+
},
|
150
|
+
|
151
|
+
validate: function() {
|
152
|
+
if (!this.$element[0].parentNode) {
|
153
|
+
this.hide();
|
154
|
+
this.$element = null;
|
155
|
+
this.options = null;
|
156
|
+
}
|
157
|
+
},
|
158
|
+
|
159
|
+
enable: function() { this.enabled = true; },
|
160
|
+
disable: function() { this.enabled = false; },
|
161
|
+
toggleEnabled: function() { this.enabled = !this.enabled; }
|
162
|
+
};
|
163
|
+
|
164
|
+
$.fn.tipsy = function(options) {
|
165
|
+
|
166
|
+
if (options === true) {
|
167
|
+
return this.data('tipsy');
|
168
|
+
} else if (typeof options == 'string') {
|
169
|
+
var tipsy = this.data('tipsy');
|
170
|
+
if (tipsy) tipsy[options]();
|
171
|
+
return this;
|
172
|
+
}
|
173
|
+
|
174
|
+
options = $.extend({}, $.fn.tipsy.defaults, options);
|
175
|
+
|
176
|
+
if (options.hoverlock && options.delayOut === 0) {
|
177
|
+
options.delayOut = 100;
|
178
|
+
}
|
179
|
+
|
180
|
+
function get(ele) {
|
181
|
+
var tipsy = $.data(ele, 'tipsy');
|
182
|
+
if (!tipsy) {
|
183
|
+
tipsy = new Tipsy(ele, $.fn.tipsy.elementOptions(ele, options));
|
184
|
+
$.data(ele, 'tipsy', tipsy);
|
185
|
+
}
|
186
|
+
return tipsy;
|
187
|
+
}
|
188
|
+
|
189
|
+
function enter() {
|
190
|
+
var tipsy = get(this);
|
191
|
+
tipsy.hoverState = 'in';
|
192
|
+
if (options.delayIn === 0) {
|
193
|
+
tipsy.show();
|
194
|
+
} else {
|
195
|
+
tipsy.fixTitle();
|
196
|
+
setTimeout(function() { if (tipsy.hoverState == 'in') tipsy.show(); }, options.delayIn);
|
197
|
+
}
|
198
|
+
}
|
199
|
+
|
200
|
+
function leave() {
|
201
|
+
var tipsy = get(this);
|
202
|
+
tipsy.hoverState = 'out';
|
203
|
+
if (options.delayOut === 0) {
|
204
|
+
tipsy.hide();
|
205
|
+
} else {
|
206
|
+
var to = function() {
|
207
|
+
if (!tipsy.tipHovered || !options.hoverlock){
|
208
|
+
if (tipsy.hoverState == 'out') tipsy.hide();
|
209
|
+
}
|
210
|
+
};
|
211
|
+
setTimeout(to, options.delayOut);
|
212
|
+
}
|
213
|
+
}
|
214
|
+
|
215
|
+
if (options.trigger != 'manual') {
|
216
|
+
var binder = options.live ? 'live' : 'bind',
|
217
|
+
eventIn = options.trigger == 'hover' ? 'mouseenter' : 'focus',
|
218
|
+
eventOut = options.trigger == 'hover' ? 'mouseleave' : 'blur';
|
219
|
+
this[binder](eventIn, enter)[binder](eventOut, leave);
|
220
|
+
}
|
221
|
+
|
222
|
+
return this;
|
223
|
+
|
224
|
+
};
|
225
|
+
|
226
|
+
$.fn.tipsy.defaults = {
|
227
|
+
className: null,
|
228
|
+
delayIn: 0,
|
229
|
+
delayOut: 0,
|
230
|
+
fade: false,
|
231
|
+
fallback: '',
|
232
|
+
gravity: 'n',
|
233
|
+
html: false,
|
234
|
+
live: false,
|
235
|
+
offset: 0,
|
236
|
+
opacity: 0.8,
|
237
|
+
title: 'title',
|
238
|
+
trigger: 'hover',
|
239
|
+
hoverlock: false
|
240
|
+
};
|
241
|
+
|
242
|
+
// Overwrite this method to provide options on a per-element basis.
|
243
|
+
// For example, you could store the gravity in a 'tipsy-gravity' attribute:
|
244
|
+
// return $.extend({}, options, {gravity: $(ele).attr('tipsy-gravity') || 'n' });
|
245
|
+
// (remember - do not modify 'options' in place!)
|
246
|
+
$.fn.tipsy.elementOptions = function(ele, options) {
|
247
|
+
return $.metadata ? $.extend({}, options, $(ele).metadata()) : options;
|
248
|
+
};
|
249
|
+
|
250
|
+
$.fn.tipsy.autoNS = function() {
|
251
|
+
return $(this).offset().top > ($(document).scrollTop() + $(window).height() / 2) ? 's' : 'n';
|
252
|
+
};
|
253
|
+
|
254
|
+
$.fn.tipsy.autoWE = function() {
|
255
|
+
return $(this).offset().left > ($(document).scrollLeft() + $(window).width() / 2) ? 'e' : 'w';
|
256
|
+
};
|
257
|
+
|
258
|
+
/**
|
259
|
+
* yields a closure of the supplied parameters, producing a function that takes
|
260
|
+
* no arguments and is suitable for use as an autogravity function like so:
|
261
|
+
*
|
262
|
+
* @param margin (int) - distance from the viewable region edge that an
|
263
|
+
* element should be before setting its tooltip's gravity to be away
|
264
|
+
* from that edge.
|
265
|
+
* @param prefer (string, e.g. 'n', 'sw', 'w') - the direction to prefer
|
266
|
+
* if there are no viewable region edges effecting the tooltip's
|
267
|
+
* gravity. It will try to vary from this minimally, for example,
|
268
|
+
* if 'sw' is preferred and an element is near the right viewable
|
269
|
+
* region edge, but not the top edge, it will set the gravity for
|
270
|
+
* that element's tooltip to be 'se', preserving the southern
|
271
|
+
* component.
|
272
|
+
*/
|
273
|
+
$.fn.tipsy.autoBounds = function(margin, prefer) {
|
274
|
+
return function() {
|
275
|
+
var dir = {ns: prefer[0], ew: (prefer.length > 1 ? prefer[1] : false)},
|
276
|
+
boundTop = $(document).scrollTop() + margin,
|
277
|
+
boundLeft = $(document).scrollLeft() + margin,
|
278
|
+
$this = $(this);
|
279
|
+
|
280
|
+
if ($this.offset().top < boundTop) dir.ns = 'n';
|
281
|
+
if ($this.offset().left < boundLeft) dir.ew = 'w';
|
282
|
+
if ($(window).width() + $(document).scrollLeft() - $this.offset().left < margin) dir.ew = 'e';
|
283
|
+
if ($(window).height() + $(document).scrollTop() - $this.offset().top < margin) dir.ns = 's';
|
284
|
+
|
285
|
+
return dir.ns + (dir.ew ? dir.ew : '');
|
286
|
+
};
|
287
|
+
};
|
288
|
+
})(jQuery);
|
@@ -0,0 +1,25 @@
|
|
1
|
+
.tipsy { font-size: 10px; position: absolute; padding: 5px; z-index: 100000; }
|
2
|
+
.tipsy-inner { background-color: #000; color: #FFF; max-width: 200px; padding: 5px 8px 4px 8px; text-align: center; }
|
3
|
+
|
4
|
+
/* Rounded corners */
|
5
|
+
.tipsy-inner { border-radius: 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px; }
|
6
|
+
|
7
|
+
/* Uncomment for shadow */
|
8
|
+
/*.tipsy-inner { box-shadow: 0 0 5px #000000; -webkit-box-shadow: 0 0 5px #000000; -moz-box-shadow: 0 0 5px #000000; }*/
|
9
|
+
|
10
|
+
.tipsy-arrow { position: absolute; width: 0; height: 0; line-height: 0; border: 5px dashed #000; }
|
11
|
+
|
12
|
+
/* Rules to colour arrows */
|
13
|
+
.tipsy-arrow-n { border-bottom-color: #000; }
|
14
|
+
.tipsy-arrow-s { border-top-color: #000; }
|
15
|
+
.tipsy-arrow-e { border-left-color: #000; }
|
16
|
+
.tipsy-arrow-w { border-right-color: #000; }
|
17
|
+
|
18
|
+
.tipsy-n .tipsy-arrow { top: 0px; left: 50%; margin-left: -5px; border-bottom-style: solid; border-top: none; border-left-color: transparent; border-right-color: transparent; }
|
19
|
+
.tipsy-nw .tipsy-arrow { top: 0; left: 10px; border-bottom-style: solid; border-top: none; border-left-color: transparent; border-right-color: transparent;}
|
20
|
+
.tipsy-ne .tipsy-arrow { top: 0; right: 10px; border-bottom-style: solid; border-top: none; border-left-color: transparent; border-right-color: transparent;}
|
21
|
+
.tipsy-s .tipsy-arrow { bottom: 0; left: 50%; margin-left: -5px; border-top-style: solid; border-bottom: none; border-left-color: transparent; border-right-color: transparent; }
|
22
|
+
.tipsy-sw .tipsy-arrow { bottom: 0; left: 10px; border-top-style: solid; border-bottom: none; border-left-color: transparent; border-right-color: transparent; }
|
23
|
+
.tipsy-se .tipsy-arrow { bottom: 0; right: 10px; border-top-style: solid; border-bottom: none; border-left-color: transparent; border-right-color: transparent; }
|
24
|
+
.tipsy-e .tipsy-arrow { right: 0; top: 50%; margin-top: -5px; border-left-style: solid; border-right: none; border-top-color: transparent; border-bottom-color: transparent; }
|
25
|
+
.tipsy-w .tipsy-arrow { left: 0; top: 50%; margin-top: -5px; border-right-style: solid; border-left: none; border-top-color: transparent; border-bottom-color: transparent; }
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tipsy_svg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Han
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-28 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: railties
|
16
|
+
requirement: &70162218726020 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.1.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70162218726020
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: bundler
|
27
|
+
requirement: &70162218725520 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.0
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70162218725520
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rails
|
38
|
+
requirement: &70162218725060 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3.1'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70162218725060
|
47
|
+
description: ! 'Gem installation for the jquery plugin for nicer tooltips, tipsy. '
|
48
|
+
email:
|
49
|
+
- han@logicallsat.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- Rakefile
|
57
|
+
- lib/tipsy_svg.rb
|
58
|
+
- lib/tipsy_svg/engine.rb
|
59
|
+
- lib/tipsy_svg/version.rb
|
60
|
+
- tipsy_svg.gemspec
|
61
|
+
- vendor/javascripts/tipsy.js
|
62
|
+
- vendor/stylesheets/tipsy.css
|
63
|
+
homepage: ''
|
64
|
+
licenses: []
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
- vendor
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project: tipsy_svg
|
84
|
+
rubygems_version: 1.8.6
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Jquery Tipsy plugin automated install for Rails 3.1+
|
88
|
+
test_files: []
|
89
|
+
has_rdoc:
|