powertip-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +22 -0
- data/README.md +25 -0
- data/lib/powertip-rails.rb +6 -0
- data/lib/powertip-rails/version.rb +3 -0
- data/vendor/assets/javascripts/core.js +257 -0
- data/vendor/assets/javascripts/csscoordinates.js +34 -0
- data/vendor/assets/javascripts/displaycontroller.js +120 -0
- data/vendor/assets/javascripts/grunt.js +74 -0
- data/vendor/assets/javascripts/intro.js +10 -0
- data/vendor/assets/javascripts/outro.js +10 -0
- data/vendor/assets/javascripts/placementcalculator.js +224 -0
- data/vendor/assets/javascripts/tooltipcontroller.js +383 -0
- data/vendor/assets/javascripts/utility.js +169 -0
- data/vendor/assets/stylesheets/jquery.powertip.blue.css +88 -0
- data/vendor/assets/stylesheets/jquery.powertip.css +85 -0
- data/vendor/assets/stylesheets/jquery.powertip.dark.css +88 -0
- data/vendor/assets/stylesheets/jquery.powertip.green.css +88 -0
- data/vendor/assets/stylesheets/jquery.powertip.light.css +88 -0
- data/vendor/assets/stylesheets/jquery.powertip.orange.css +88 -0
- data/vendor/assets/stylesheets/jquery.powertip.purple.css +88 -0
- data/vendor/assets/stylesheets/jquery.powertip.red.css +88 -0
- data/vendor/assets/stylesheets/jquery.powertip.yellow.css +88 -0
- metadata +84 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 mahm
|
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,25 @@
|
|
1
|
+
# powertip-rails
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this to your `Gemfile`:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
group :assets do
|
9
|
+
gem 'sass-rails'
|
10
|
+
gem 'compass-rails'
|
11
|
+
gem 'powertip-rails'
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
- [http://stevenbenner.github.com/jquery-powertip/](http://stevenbenner.github.com/jquery-powertip/)
|
18
|
+
|
19
|
+
## Contributing
|
20
|
+
|
21
|
+
1. Fork it
|
22
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
23
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
24
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
25
|
+
5. Create new Pull Request
|
@@ -0,0 +1,257 @@
|
|
1
|
+
/**
|
2
|
+
* PowerTip Core
|
3
|
+
*
|
4
|
+
* @fileoverview Core variables, plugin object, and API.
|
5
|
+
* @link http://stevenbenner.github.com/jquery-powertip/
|
6
|
+
* @author Steven Benner (http://stevenbenner.com/)
|
7
|
+
* @requires jQuery 1.7+
|
8
|
+
*/
|
9
|
+
|
10
|
+
// useful private variables
|
11
|
+
var $document = $(window.document),
|
12
|
+
$window = $(window),
|
13
|
+
$body = $('body');
|
14
|
+
|
15
|
+
// constants
|
16
|
+
var DATA_DISPLAYCONTROLLER = 'displayController',
|
17
|
+
DATA_HASACTIVEHOVER = 'hasActiveHover',
|
18
|
+
DATA_FORCEDOPEN = 'forcedOpen',
|
19
|
+
DATA_HASMOUSEMOVE = 'hasMouseMove',
|
20
|
+
DATA_MOUSEONTOTIP = 'mouseOnToPopup',
|
21
|
+
DATA_ORIGINALTITLE = 'originalTitle',
|
22
|
+
DATA_POWERTIP = 'powertip',
|
23
|
+
DATA_POWERTIPJQ = 'powertipjq',
|
24
|
+
DATA_POWERTIPTARGET = 'powertiptarget',
|
25
|
+
RAD2DEG = 180 / Math.PI;
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Session data
|
29
|
+
* Private properties global to all powerTip instances
|
30
|
+
*/
|
31
|
+
var session = {
|
32
|
+
isTipOpen: false,
|
33
|
+
isFixedTipOpen: false,
|
34
|
+
isClosing: false,
|
35
|
+
tipOpenImminent: false,
|
36
|
+
activeHover: null,
|
37
|
+
currentX: 0,
|
38
|
+
currentY: 0,
|
39
|
+
previousX: 0,
|
40
|
+
previousY: 0,
|
41
|
+
desyncTimeout: null,
|
42
|
+
mouseTrackingActive: false,
|
43
|
+
delayInProgress: false
|
44
|
+
};
|
45
|
+
|
46
|
+
/**
|
47
|
+
* Collision enumeration
|
48
|
+
* @enum {number}
|
49
|
+
*/
|
50
|
+
var Collision = {
|
51
|
+
none: 0,
|
52
|
+
top: 1,
|
53
|
+
bottom: 2,
|
54
|
+
left: 4,
|
55
|
+
right: 8
|
56
|
+
};
|
57
|
+
|
58
|
+
/**
|
59
|
+
* Display hover tooltips on the matched elements.
|
60
|
+
* @param {(Object|string)} opts The options object to use for the plugin, or
|
61
|
+
* the name of a method to invoke on the first matched element.
|
62
|
+
* @param {*=} [arg] Argument for an invoked method (optional).
|
63
|
+
* @return {jQuery} jQuery object for the matched selectors.
|
64
|
+
*/
|
65
|
+
$.fn.powerTip = function(opts, arg) {
|
66
|
+
// don't do any work if there were no matched elements
|
67
|
+
if (!this.length) {
|
68
|
+
return this;
|
69
|
+
}
|
70
|
+
|
71
|
+
// handle api method calls on the plugin, e.g. powerTip('hide')
|
72
|
+
if (typeof opts === 'string' && $.powerTip[opts]) {
|
73
|
+
return $.powerTip[opts].call(this, this, arg);
|
74
|
+
}
|
75
|
+
|
76
|
+
// extend options
|
77
|
+
var options = $.extend({}, $.fn.powerTip.defaults, opts),
|
78
|
+
tipController = new TooltipController(options);
|
79
|
+
|
80
|
+
// hook mouse tracking
|
81
|
+
initMouseTracking();
|
82
|
+
|
83
|
+
// setup the elements
|
84
|
+
this.each(function elementSetup() {
|
85
|
+
var $this = $(this),
|
86
|
+
dataPowertip = $this.data(DATA_POWERTIP),
|
87
|
+
dataElem = $this.data(DATA_POWERTIPJQ),
|
88
|
+
dataTarget = $this.data(DATA_POWERTIPTARGET),
|
89
|
+
title = $this.attr('title');
|
90
|
+
|
91
|
+
// handle repeated powerTip calls on the same element by destroying the
|
92
|
+
// original instance hooked to it and replacing it with this call
|
93
|
+
if ($this.data(DATA_DISPLAYCONTROLLER)) {
|
94
|
+
$.powerTip.destroy($this);
|
95
|
+
title = $this.attr('title');
|
96
|
+
}
|
97
|
+
|
98
|
+
// attempt to use title attribute text if there is no data-powertip,
|
99
|
+
// data-powertipjq or data-powertiptarget. If we do use the title
|
100
|
+
// attribute, delete the attribute so the browser will not show it
|
101
|
+
if (!dataPowertip && !dataTarget && !dataElem && title) {
|
102
|
+
$this.data(DATA_POWERTIP, title);
|
103
|
+
$this.data(DATA_ORIGINALTITLE, title);
|
104
|
+
$this.removeAttr('title');
|
105
|
+
}
|
106
|
+
|
107
|
+
// create hover controllers for each element
|
108
|
+
$this.data(
|
109
|
+
DATA_DISPLAYCONTROLLER,
|
110
|
+
new DisplayController($this, options, tipController)
|
111
|
+
);
|
112
|
+
});
|
113
|
+
|
114
|
+
// attach events to matched elements if the manual options is not enabled
|
115
|
+
if (!options.manual) {
|
116
|
+
this.on({
|
117
|
+
// mouse events
|
118
|
+
'mouseenter.powertip': function elementMouseEnter(event) {
|
119
|
+
$.powerTip.show(this, event);
|
120
|
+
},
|
121
|
+
'mouseleave.powertip': function elementMouseLeave() {
|
122
|
+
$.powerTip.hide(this);
|
123
|
+
},
|
124
|
+
// keyboard events
|
125
|
+
'focus.powertip': function elementFocus() {
|
126
|
+
$.powerTip.show(this);
|
127
|
+
},
|
128
|
+
'blur.powertip': function elementBlur() {
|
129
|
+
$.powerTip.hide(this, true);
|
130
|
+
},
|
131
|
+
'keydown.powertip': function elementKeyDown(event) {
|
132
|
+
// close tooltip when the escape key is pressed
|
133
|
+
if (event.keyCode === 27) {
|
134
|
+
$.powerTip.hide(this, true);
|
135
|
+
}
|
136
|
+
}
|
137
|
+
});
|
138
|
+
}
|
139
|
+
|
140
|
+
return this;
|
141
|
+
};
|
142
|
+
|
143
|
+
/**
|
144
|
+
* Default options for the powerTip plugin.
|
145
|
+
*/
|
146
|
+
$.fn.powerTip.defaults = {
|
147
|
+
fadeInTime: 200,
|
148
|
+
fadeOutTime: 100,
|
149
|
+
followMouse: false,
|
150
|
+
popupId: 'powerTip',
|
151
|
+
intentSensitivity: 7,
|
152
|
+
intentPollInterval: 100,
|
153
|
+
closeDelay: 100,
|
154
|
+
placement: 'n',
|
155
|
+
smartPlacement: false,
|
156
|
+
offset: 10,
|
157
|
+
mouseOnToPopup: false,
|
158
|
+
manual: false
|
159
|
+
};
|
160
|
+
|
161
|
+
/**
|
162
|
+
* Default smart placement priority lists.
|
163
|
+
* The first item in the array is the highest priority, the last is the lowest.
|
164
|
+
* The last item is also the default, which will be used if all previous options
|
165
|
+
* do not fit.
|
166
|
+
*/
|
167
|
+
$.fn.powerTip.smartPlacementLists = {
|
168
|
+
n: ['n', 'ne', 'nw', 's'],
|
169
|
+
e: ['e', 'ne', 'se', 'w', 'nw', 'sw', 'n', 's', 'e'],
|
170
|
+
s: ['s', 'se', 'sw', 'n'],
|
171
|
+
w: ['w', 'nw', 'sw', 'e', 'ne', 'se', 'n', 's', 'w'],
|
172
|
+
nw: ['nw', 'w', 'sw', 'n', 's', 'se', 'nw'],
|
173
|
+
ne: ['ne', 'e', 'se', 'n', 's', 'sw', 'ne'],
|
174
|
+
sw: ['sw', 'w', 'nw', 's', 'n', 'ne', 'sw'],
|
175
|
+
se: ['se', 'e', 'ne', 's', 'n', 'nw', 'se'],
|
176
|
+
'nw-alt': ['nw-alt', 'n', 'ne-alt', 'sw-alt', 's', 'se-alt', 'w', 'e'],
|
177
|
+
'ne-alt': ['ne-alt', 'n', 'nw-alt', 'se-alt', 's', 'sw-alt', 'e', 'w'],
|
178
|
+
'sw-alt': ['sw-alt', 's', 'se-alt', 'nw-alt', 'n', 'ne-alt', 'w', 'e'],
|
179
|
+
'se-alt': ['se-alt', 's', 'sw-alt', 'ne-alt', 'n', 'nw-alt', 'e', 'w']
|
180
|
+
};
|
181
|
+
|
182
|
+
/**
|
183
|
+
* Public API
|
184
|
+
*/
|
185
|
+
$.powerTip = {
|
186
|
+
/**
|
187
|
+
* Attempts to show the tooltip for the specified element.
|
188
|
+
* @param {jQuery|Element} element The element to open the tooltip for.
|
189
|
+
* @param {jQuery.Event=} event jQuery event for hover intent and mouse
|
190
|
+
* tracking (optional).
|
191
|
+
*/
|
192
|
+
show: function apiShowTip(element, event) {
|
193
|
+
if (event) {
|
194
|
+
trackMouse(event);
|
195
|
+
session.previousX = event.pageX;
|
196
|
+
session.previousY = event.pageY;
|
197
|
+
$(element).data(DATA_DISPLAYCONTROLLER).show();
|
198
|
+
} else {
|
199
|
+
$(element).first().data(DATA_DISPLAYCONTROLLER).show(true, true);
|
200
|
+
}
|
201
|
+
return element;
|
202
|
+
},
|
203
|
+
|
204
|
+
/**
|
205
|
+
* Repositions the tooltip on the element.
|
206
|
+
* @param {jQuery|Element} element The element the tooltip is shown for.
|
207
|
+
*/
|
208
|
+
reposition: function apiResetPosition(element) {
|
209
|
+
$(element).first().data(DATA_DISPLAYCONTROLLER).resetPosition();
|
210
|
+
return element;
|
211
|
+
},
|
212
|
+
|
213
|
+
/**
|
214
|
+
* Attempts to close any open tooltips.
|
215
|
+
* @param {(jQuery|Element)=} element The element with the tooltip that
|
216
|
+
* should be closed (optional).
|
217
|
+
* @param {boolean=} immediate Disable close delay (optional).
|
218
|
+
*/
|
219
|
+
hide: function apiCloseTip(element, immediate) {
|
220
|
+
if (element) {
|
221
|
+
$(element).first().data(DATA_DISPLAYCONTROLLER).hide(immediate);
|
222
|
+
} else {
|
223
|
+
if (session.activeHover) {
|
224
|
+
session.activeHover.data(DATA_DISPLAYCONTROLLER).hide(true);
|
225
|
+
}
|
226
|
+
}
|
227
|
+
return element;
|
228
|
+
},
|
229
|
+
|
230
|
+
/**
|
231
|
+
* Destroy and roll back any powerTip() instance on the specified element.
|
232
|
+
* @param {jQuery|Element} element The element with the powerTip instance.
|
233
|
+
*/
|
234
|
+
destroy: function apiDestroy(element) {
|
235
|
+
$(element).off('.powertip').each(function destroy() {
|
236
|
+
var $this = $(this),
|
237
|
+
dataAttributes = [
|
238
|
+
DATA_ORIGINALTITLE,
|
239
|
+
DATA_DISPLAYCONTROLLER,
|
240
|
+
DATA_HASACTIVEHOVER,
|
241
|
+
DATA_FORCEDOPEN
|
242
|
+
];
|
243
|
+
|
244
|
+
if ($this.data(DATA_ORIGINALTITLE)) {
|
245
|
+
$this.attr('title', $this.data(DATA_ORIGINALTITLE));
|
246
|
+
dataAttributes.push(DATA_POWERTIP);
|
247
|
+
}
|
248
|
+
|
249
|
+
$this.removeData(dataAttributes);
|
250
|
+
});
|
251
|
+
return element;
|
252
|
+
}
|
253
|
+
};
|
254
|
+
|
255
|
+
// API aliasing
|
256
|
+
$.powerTip.showTip = $.powerTip.show;
|
257
|
+
$.powerTip.closeTip = $.powerTip.hide;
|
@@ -0,0 +1,34 @@
|
|
1
|
+
/**
|
2
|
+
* PowerTip CSSCoordinates
|
3
|
+
*
|
4
|
+
* @fileoverview CSSCoordinates object for describing CSS positions.
|
5
|
+
* @link http://stevenbenner.github.com/jquery-powertip/
|
6
|
+
* @author Steven Benner (http://stevenbenner.com/)
|
7
|
+
* @requires jQuery 1.7+
|
8
|
+
*/
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Creates a new CSSCoordinates object.
|
12
|
+
* @private
|
13
|
+
* @constructor
|
14
|
+
*/
|
15
|
+
function CSSCoordinates() {
|
16
|
+
var me = this;
|
17
|
+
|
18
|
+
// initialize object properties
|
19
|
+
me.top = 'auto';
|
20
|
+
me.left = 'auto';
|
21
|
+
me.right = 'auto';
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Set a property to a value.
|
25
|
+
* @private
|
26
|
+
* @param {string} property The name of the property.
|
27
|
+
* @param {number} value The value of the property.
|
28
|
+
*/
|
29
|
+
me.set = function(property, value) {
|
30
|
+
if ($.isNumeric(value)) {
|
31
|
+
me[property] = Math.round(value);
|
32
|
+
}
|
33
|
+
};
|
34
|
+
}
|
@@ -0,0 +1,120 @@
|
|
1
|
+
/**
|
2
|
+
* PowerTip DisplayController
|
3
|
+
*
|
4
|
+
* @fileoverview DisplayController object used to manage tooltips for elements.
|
5
|
+
* @link http://stevenbenner.github.com/jquery-powertip/
|
6
|
+
* @author Steven Benner (http://stevenbenner.com/)
|
7
|
+
* @requires jQuery 1.7+
|
8
|
+
*/
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Creates a new tooltip display controller.
|
12
|
+
* @private
|
13
|
+
* @constructor
|
14
|
+
* @param {jQuery} element The element that this controller will handle.
|
15
|
+
* @param {Object} options Options object containing settings.
|
16
|
+
* @param {TooltipController} tipController The TooltipController object for
|
17
|
+
* this instance.
|
18
|
+
*/
|
19
|
+
function DisplayController(element, options, tipController) {
|
20
|
+
var hoverTimer = null;
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Begins the process of showing a tooltip.
|
24
|
+
* @private
|
25
|
+
* @param {boolean=} immediate Skip intent testing (optional).
|
26
|
+
* @param {boolean=} forceOpen Ignore cursor position and force tooltip to
|
27
|
+
* open (optional).
|
28
|
+
*/
|
29
|
+
function openTooltip(immediate, forceOpen) {
|
30
|
+
cancelTimer();
|
31
|
+
if (!element.data(DATA_HASACTIVEHOVER)) {
|
32
|
+
if (!immediate) {
|
33
|
+
session.tipOpenImminent = true;
|
34
|
+
hoverTimer = window.setTimeout(
|
35
|
+
function intentDelay() {
|
36
|
+
hoverTimer = null;
|
37
|
+
checkForIntent();
|
38
|
+
},
|
39
|
+
options.intentPollInterval
|
40
|
+
);
|
41
|
+
} else {
|
42
|
+
if (forceOpen) {
|
43
|
+
element.data(DATA_FORCEDOPEN, true);
|
44
|
+
}
|
45
|
+
tipController.showTip(element);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Begins the process of closing a tooltip.
|
52
|
+
* @private
|
53
|
+
* @param {boolean=} disableDelay Disable close delay (optional).
|
54
|
+
*/
|
55
|
+
function closeTooltip(disableDelay) {
|
56
|
+
cancelTimer();
|
57
|
+
session.tipOpenImminent = false;
|
58
|
+
if (element.data(DATA_HASACTIVEHOVER)) {
|
59
|
+
element.data(DATA_FORCEDOPEN, false);
|
60
|
+
if (!disableDelay) {
|
61
|
+
session.delayInProgress = true;
|
62
|
+
hoverTimer = window.setTimeout(
|
63
|
+
function closeDelay() {
|
64
|
+
hoverTimer = null;
|
65
|
+
tipController.hideTip(element);
|
66
|
+
session.delayInProgress = false;
|
67
|
+
},
|
68
|
+
options.closeDelay
|
69
|
+
);
|
70
|
+
} else {
|
71
|
+
tipController.hideTip(element);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Checks mouse position to make sure that the user intended to hover on the
|
78
|
+
* specified element before showing the tooltip.
|
79
|
+
* @private
|
80
|
+
*/
|
81
|
+
function checkForIntent() {
|
82
|
+
// calculate mouse position difference
|
83
|
+
var xDifference = Math.abs(session.previousX - session.currentX),
|
84
|
+
yDifference = Math.abs(session.previousY - session.currentY),
|
85
|
+
totalDifference = xDifference + yDifference;
|
86
|
+
|
87
|
+
// check if difference has passed the sensitivity threshold
|
88
|
+
if (totalDifference < options.intentSensitivity) {
|
89
|
+
tipController.showTip(element);
|
90
|
+
} else {
|
91
|
+
// try again
|
92
|
+
session.previousX = session.currentX;
|
93
|
+
session.previousY = session.currentY;
|
94
|
+
openTooltip();
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
/**
|
99
|
+
* Cancels active hover timer.
|
100
|
+
* @private
|
101
|
+
*/
|
102
|
+
function cancelTimer() {
|
103
|
+
hoverTimer = window.clearTimeout(hoverTimer);
|
104
|
+
session.delayInProgress = false;
|
105
|
+
}
|
106
|
+
|
107
|
+
/**
|
108
|
+
* Repositions the tooltip on this element.
|
109
|
+
* @private
|
110
|
+
*/
|
111
|
+
function repositionTooltip() {
|
112
|
+
tipController.resetPosition(element);
|
113
|
+
}
|
114
|
+
|
115
|
+
// expose the methods
|
116
|
+
this.show = openTooltip;
|
117
|
+
this.hide = closeTooltip;
|
118
|
+
this.cancel = cancelTimer;
|
119
|
+
this.resetPosition = repositionTooltip;
|
120
|
+
}
|