glimpse 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +7 -0
- data/app/assets/javascripts/glimpse/vendor/jquery.tipsy.js +258 -0
- data/app/assets/javascripts/glimpse.coffee +23 -6
- data/app/assets/stylesheets/glimpse/vendor/tipsy.scss +24 -0
- data/app/assets/stylesheets/glimpse.scss +2 -0
- data/lib/glimpse/version.rb +1 -1
- metadata +4 -2
- data/app/assets/javascripts/glimpse/vendor/jquery.cookies.js +0 -94
data/CHANGELOG.md
ADDED
@@ -0,0 +1,258 @@
|
|
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 isElementInDOM(ele) {
|
13
|
+
while (ele = ele.parentNode) {
|
14
|
+
if (ele == document) return true;
|
15
|
+
}
|
16
|
+
return false;
|
17
|
+
};
|
18
|
+
|
19
|
+
function Tipsy(element, options) {
|
20
|
+
this.$element = $(element);
|
21
|
+
this.options = options;
|
22
|
+
this.enabled = true;
|
23
|
+
this.fixTitle();
|
24
|
+
};
|
25
|
+
|
26
|
+
Tipsy.prototype = {
|
27
|
+
show: function() {
|
28
|
+
var title = this.getTitle();
|
29
|
+
if (title && this.enabled) {
|
30
|
+
var $tip = this.tip();
|
31
|
+
|
32
|
+
$tip.find('.tipsy-inner')[this.options.html ? 'html' : 'text'](title);
|
33
|
+
$tip[0].className = 'tipsy'; // reset classname in case of dynamic gravity
|
34
|
+
$tip.remove().css({top: 0, left: 0, visibility: 'hidden', display: 'block'}).prependTo(document.body);
|
35
|
+
|
36
|
+
var pos = $.extend({}, this.$element.offset(), {
|
37
|
+
width: this.$element[0].offsetWidth,
|
38
|
+
height: this.$element[0].offsetHeight
|
39
|
+
});
|
40
|
+
|
41
|
+
var actualWidth = $tip[0].offsetWidth,
|
42
|
+
actualHeight = $tip[0].offsetHeight,
|
43
|
+
gravity = maybeCall(this.options.gravity, this.$element[0]);
|
44
|
+
|
45
|
+
var tp;
|
46
|
+
switch (gravity.charAt(0)) {
|
47
|
+
case 'n':
|
48
|
+
tp = {top: pos.top + pos.height + this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2};
|
49
|
+
break;
|
50
|
+
case 's':
|
51
|
+
tp = {top: pos.top - actualHeight - this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2};
|
52
|
+
break;
|
53
|
+
case 'e':
|
54
|
+
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth - this.options.offset};
|
55
|
+
break;
|
56
|
+
case 'w':
|
57
|
+
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width + this.options.offset};
|
58
|
+
break;
|
59
|
+
}
|
60
|
+
|
61
|
+
if (gravity.length == 2) {
|
62
|
+
if (gravity.charAt(1) == 'w') {
|
63
|
+
tp.left = pos.left + pos.width / 2 - 15;
|
64
|
+
} else {
|
65
|
+
tp.left = pos.left + pos.width / 2 - actualWidth + 15;
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
$tip.css(tp).addClass('tipsy-' + gravity);
|
70
|
+
$tip.find('.tipsy-arrow')[0].className = 'tipsy-arrow tipsy-arrow-' + gravity.charAt(0);
|
71
|
+
if (this.options.className) {
|
72
|
+
$tip.addClass(maybeCall(this.options.className, this.$element[0]));
|
73
|
+
}
|
74
|
+
|
75
|
+
if (this.options.fade) {
|
76
|
+
$tip.stop().css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: this.options.opacity});
|
77
|
+
} else {
|
78
|
+
$tip.css({visibility: 'visible', opacity: this.options.opacity});
|
79
|
+
}
|
80
|
+
}
|
81
|
+
},
|
82
|
+
|
83
|
+
hide: function() {
|
84
|
+
if (this.options.fade) {
|
85
|
+
this.tip().stop().fadeOut(function() { $(this).remove(); });
|
86
|
+
} else {
|
87
|
+
this.tip().remove();
|
88
|
+
}
|
89
|
+
},
|
90
|
+
|
91
|
+
fixTitle: function() {
|
92
|
+
var $e = this.$element;
|
93
|
+
if ($e.attr('title') || typeof($e.attr('original-title')) != 'string') {
|
94
|
+
$e.attr('original-title', $e.attr('title') || '').removeAttr('title');
|
95
|
+
}
|
96
|
+
},
|
97
|
+
|
98
|
+
getTitle: function() {
|
99
|
+
var title, $e = this.$element, o = this.options;
|
100
|
+
this.fixTitle();
|
101
|
+
var title, o = this.options;
|
102
|
+
if (typeof o.title == 'string') {
|
103
|
+
title = $e.attr(o.title == 'title' ? 'original-title' : o.title);
|
104
|
+
} else if (typeof o.title == 'function') {
|
105
|
+
title = o.title.call($e[0]);
|
106
|
+
}
|
107
|
+
title = ('' + title).replace(/(^\s*|\s*$)/, "");
|
108
|
+
return title || o.fallback;
|
109
|
+
},
|
110
|
+
|
111
|
+
tip: function() {
|
112
|
+
if (!this.$tip) {
|
113
|
+
this.$tip = $('<div class="tipsy"></div>').html('<div class="tipsy-arrow"></div><div class="tipsy-inner"></div>');
|
114
|
+
this.$tip.data('tipsy-pointee', this.$element[0]);
|
115
|
+
}
|
116
|
+
return this.$tip;
|
117
|
+
},
|
118
|
+
|
119
|
+
validate: function() {
|
120
|
+
if (!this.$element[0].parentNode) {
|
121
|
+
this.hide();
|
122
|
+
this.$element = null;
|
123
|
+
this.options = null;
|
124
|
+
}
|
125
|
+
},
|
126
|
+
|
127
|
+
enable: function() { this.enabled = true; },
|
128
|
+
disable: function() { this.enabled = false; },
|
129
|
+
toggleEnabled: function() { this.enabled = !this.enabled; }
|
130
|
+
};
|
131
|
+
|
132
|
+
$.fn.tipsy = function(options) {
|
133
|
+
|
134
|
+
if (options === true) {
|
135
|
+
return this.data('tipsy');
|
136
|
+
} else if (typeof options == 'string') {
|
137
|
+
var tipsy = this.data('tipsy');
|
138
|
+
if (tipsy) tipsy[options]();
|
139
|
+
return this;
|
140
|
+
}
|
141
|
+
|
142
|
+
options = $.extend({}, $.fn.tipsy.defaults, options);
|
143
|
+
|
144
|
+
function get(ele) {
|
145
|
+
var tipsy = $.data(ele, 'tipsy');
|
146
|
+
if (!tipsy) {
|
147
|
+
tipsy = new Tipsy(ele, $.fn.tipsy.elementOptions(ele, options));
|
148
|
+
$.data(ele, 'tipsy', tipsy);
|
149
|
+
}
|
150
|
+
return tipsy;
|
151
|
+
}
|
152
|
+
|
153
|
+
function enter() {
|
154
|
+
var tipsy = get(this);
|
155
|
+
tipsy.hoverState = 'in';
|
156
|
+
if (options.delayIn == 0) {
|
157
|
+
tipsy.show();
|
158
|
+
} else {
|
159
|
+
tipsy.fixTitle();
|
160
|
+
setTimeout(function() { if (tipsy.hoverState == 'in') tipsy.show(); }, options.delayIn);
|
161
|
+
}
|
162
|
+
};
|
163
|
+
|
164
|
+
function leave() {
|
165
|
+
var tipsy = get(this);
|
166
|
+
tipsy.hoverState = 'out';
|
167
|
+
if (options.delayOut == 0) {
|
168
|
+
tipsy.hide();
|
169
|
+
} else {
|
170
|
+
setTimeout(function() { if (tipsy.hoverState == 'out') tipsy.hide(); }, options.delayOut);
|
171
|
+
}
|
172
|
+
};
|
173
|
+
|
174
|
+
if (!options.live) this.each(function() { get(this); });
|
175
|
+
|
176
|
+
if (options.trigger != 'manual') {
|
177
|
+
var binder = options.live ? 'live' : 'bind',
|
178
|
+
eventIn = options.trigger == 'hover' ? 'mouseenter' : 'focus',
|
179
|
+
eventOut = options.trigger == 'hover' ? 'mouseleave' : 'blur';
|
180
|
+
this[binder](eventIn, enter)[binder](eventOut, leave);
|
181
|
+
}
|
182
|
+
|
183
|
+
return this;
|
184
|
+
|
185
|
+
};
|
186
|
+
|
187
|
+
$.fn.tipsy.defaults = {
|
188
|
+
className: null,
|
189
|
+
delayIn: 0,
|
190
|
+
delayOut: 0,
|
191
|
+
fade: false,
|
192
|
+
fallback: '',
|
193
|
+
gravity: 'n',
|
194
|
+
html: false,
|
195
|
+
live: false,
|
196
|
+
offset: 0,
|
197
|
+
opacity: 0.8,
|
198
|
+
title: 'title',
|
199
|
+
trigger: 'hover'
|
200
|
+
};
|
201
|
+
|
202
|
+
$.fn.tipsy.revalidate = function() {
|
203
|
+
$('.tipsy').each(function() {
|
204
|
+
var pointee = $.data(this, 'tipsy-pointee');
|
205
|
+
if (!pointee || !isElementInDOM(pointee)) {
|
206
|
+
$(this).remove();
|
207
|
+
}
|
208
|
+
});
|
209
|
+
};
|
210
|
+
|
211
|
+
// Overwrite this method to provide options on a per-element basis.
|
212
|
+
// For example, you could store the gravity in a 'tipsy-gravity' attribute:
|
213
|
+
// return $.extend({}, options, {gravity: $(ele).attr('tipsy-gravity') || 'n' });
|
214
|
+
// (remember - do not modify 'options' in place!)
|
215
|
+
$.fn.tipsy.elementOptions = function(ele, options) {
|
216
|
+
return $.metadata ? $.extend({}, options, $(ele).metadata()) : options;
|
217
|
+
};
|
218
|
+
|
219
|
+
$.fn.tipsy.autoNS = function() {
|
220
|
+
return $(this).offset().top > ($(document).scrollTop() + $(window).height() / 2) ? 's' : 'n';
|
221
|
+
};
|
222
|
+
|
223
|
+
$.fn.tipsy.autoWE = function() {
|
224
|
+
return $(this).offset().left > ($(document).scrollLeft() + $(window).width() / 2) ? 'e' : 'w';
|
225
|
+
};
|
226
|
+
|
227
|
+
/**
|
228
|
+
* yields a closure of the supplied parameters, producing a function that takes
|
229
|
+
* no arguments and is suitable for use as an autogravity function like so:
|
230
|
+
*
|
231
|
+
* @param margin (int) - distance from the viewable region edge that an
|
232
|
+
* element should be before setting its tooltip's gravity to be away
|
233
|
+
* from that edge.
|
234
|
+
* @param prefer (string, e.g. 'n', 'sw', 'w') - the direction to prefer
|
235
|
+
* if there are no viewable region edges effecting the tooltip's
|
236
|
+
* gravity. It will try to vary from this minimally, for example,
|
237
|
+
* if 'sw' is preferred and an element is near the right viewable
|
238
|
+
* region edge, but not the top edge, it will set the gravity for
|
239
|
+
* that element's tooltip to be 'se', preserving the southern
|
240
|
+
* component.
|
241
|
+
*/
|
242
|
+
$.fn.tipsy.autoBounds = function(margin, prefer) {
|
243
|
+
return function() {
|
244
|
+
var dir = {ns: prefer[0], ew: (prefer.length > 1 ? prefer[1] : false)},
|
245
|
+
boundTop = $(document).scrollTop() + margin,
|
246
|
+
boundLeft = $(document).scrollLeft() + margin,
|
247
|
+
$this = $(this);
|
248
|
+
|
249
|
+
if ($this.offset().top < boundTop) dir.ns = 'n';
|
250
|
+
if ($this.offset().left < boundLeft) dir.ew = 'w';
|
251
|
+
if ($(window).width() + $(document).scrollLeft() - $this.offset().left < margin) dir.ew = 'e';
|
252
|
+
if ($(window).height() + $(document).scrollTop() - $this.offset().top < margin) dir.ns = 's';
|
253
|
+
|
254
|
+
return dir.ns + (dir.ew ? dir.ew : '');
|
255
|
+
}
|
256
|
+
};
|
257
|
+
|
258
|
+
})(jQuery);
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#= require glimpse/vendor/jquery.
|
1
|
+
#= require glimpse/vendor/jquery.tipsy
|
2
2
|
|
3
3
|
updatePerformanceBar = ->
|
4
4
|
glimpseResults = $('#glimpse-results')
|
@@ -7,16 +7,33 @@ updatePerformanceBar = ->
|
|
7
7
|
data = glimpseResults.data deferKey
|
8
8
|
$(this).text data
|
9
9
|
|
10
|
+
initializeTipsy = ->
|
11
|
+
$('#glimpse .tooltip').each ->
|
12
|
+
el = $(this)
|
13
|
+
gravity = if el.hasClass('rightwards') then 'w' else 'n'
|
14
|
+
gravity = if el.hasClass('leftwards') then 'e' else gravity
|
15
|
+
el.tipsy { gravity }
|
16
|
+
|
10
17
|
toggleBar = (event) ->
|
11
18
|
return if $(event.target).is ':input'
|
12
19
|
|
13
20
|
if event.keyCode == 96
|
14
|
-
$('#glimpse')
|
15
|
-
|
16
|
-
|
21
|
+
wrapper = $('#glimpse')
|
22
|
+
if wrapper.hasClass 'disabled'
|
23
|
+
wrapper.removeClass 'disabled'
|
24
|
+
document.cookie = "glimpse=true; path=/";
|
25
|
+
else
|
26
|
+
wrapper.addClass 'disabled'
|
27
|
+
document.cookie = "glimpse=false; path=/";
|
17
28
|
|
18
|
-
$(document).on 'pjax:end', updatePerformanceBar
|
19
29
|
$(document).on 'keypress', toggleBar
|
20
30
|
|
31
|
+
$(document).on 'glimpse:update', updatePerformanceBar
|
32
|
+
$(document).on 'glimpse:update', initializeTipsy
|
33
|
+
|
34
|
+
# Fire the event for our own listeners.
|
35
|
+
$(document).on 'pjax:end', ->
|
36
|
+
$(this).trigger 'glimpse:update'
|
37
|
+
|
21
38
|
$ ->
|
22
|
-
|
39
|
+
$(this).trigger 'glimpse:update'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#glimpse {
|
2
|
+
.tipsy { font-size: 10px; position: absolute; padding: 5px; z-index: 100000; }
|
3
|
+
.tipsy-inner { background-color: #000; color: #FFF; max-width: 200px; padding: 5px 8px 4px 8px; text-align: center; }
|
4
|
+
|
5
|
+
/* Rounded corners */
|
6
|
+
.tipsy-inner { border-radius: 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px; }
|
7
|
+
|
8
|
+
.tipsy-arrow { position: absolute; width: 0; height: 0; line-height: 0; border: 5px dashed #000; }
|
9
|
+
|
10
|
+
/* Rules to colour arrows */
|
11
|
+
.tipsy-arrow-n { border-bottom-color: #000; }
|
12
|
+
.tipsy-arrow-s { border-top-color: #000; }
|
13
|
+
.tipsy-arrow-e { border-left-color: #000; }
|
14
|
+
.tipsy-arrow-w { border-right-color: #000; }
|
15
|
+
|
16
|
+
.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; }
|
17
|
+
.tipsy-nw .tipsy-arrow { top: 0; left: 10px; border-bottom-style: solid; border-top: none; border-left-color: transparent; border-right-color: transparent;}
|
18
|
+
.tipsy-ne .tipsy-arrow { top: 0; right: 10px; border-bottom-style: solid; border-top: none; border-left-color: transparent; border-right-color: transparent;}
|
19
|
+
.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; }
|
20
|
+
.tipsy-sw .tipsy-arrow { bottom: 0; left: 10px; border-top-style: solid; border-bottom: none; border-left-color: transparent; border-right-color: transparent; }
|
21
|
+
.tipsy-se .tipsy-arrow { bottom: 0; right: 10px; border-top-style: solid; border-bottom: none; border-left-color: transparent; border-right-color: transparent; }
|
22
|
+
.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; }
|
23
|
+
.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; }
|
24
|
+
}
|
data/lib/glimpse/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glimpse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -35,6 +35,7 @@ extensions: []
|
|
35
35
|
extra_rdoc_files: []
|
36
36
|
files:
|
37
37
|
- .gitignore
|
38
|
+
- CHANGELOG.md
|
38
39
|
- Gemfile
|
39
40
|
- LICENSE.txt
|
40
41
|
- README.md
|
@@ -43,8 +44,9 @@ files:
|
|
43
44
|
- app/assets/images/glimpse/bar/production.gif
|
44
45
|
- app/assets/images/glimpse/bar/staging.gif
|
45
46
|
- app/assets/javascripts/glimpse.coffee
|
46
|
-
- app/assets/javascripts/glimpse/vendor/jquery.
|
47
|
+
- app/assets/javascripts/glimpse/vendor/jquery.tipsy.js
|
47
48
|
- app/assets/stylesheets/glimpse.scss
|
49
|
+
- app/assets/stylesheets/glimpse/vendor/tipsy.scss
|
48
50
|
- app/views/glimpse/_bar.html.erb
|
49
51
|
- app/views/glimpse/_results.html.erb
|
50
52
|
- glimpse.gemspec
|
@@ -1,94 +0,0 @@
|
|
1
|
-
/*!
|
2
|
-
* jQuery Cookie Plugin v1.3.1
|
3
|
-
* https://github.com/carhartl/jquery-cookie
|
4
|
-
*
|
5
|
-
* Copyright 2013 Klaus Hartl
|
6
|
-
* Released under the MIT license
|
7
|
-
*/
|
8
|
-
(function (factory) {
|
9
|
-
if (typeof define === 'function' && define.amd) {
|
10
|
-
// AMD. Register as anonymous module.
|
11
|
-
define(['jquery'], factory);
|
12
|
-
} else {
|
13
|
-
// Browser globals.
|
14
|
-
factory(jQuery);
|
15
|
-
}
|
16
|
-
}(function ($) {
|
17
|
-
|
18
|
-
var pluses = /\+/g;
|
19
|
-
|
20
|
-
function raw(s) {
|
21
|
-
return s;
|
22
|
-
}
|
23
|
-
|
24
|
-
function decoded(s) {
|
25
|
-
return decodeURIComponent(s.replace(pluses, ' '));
|
26
|
-
}
|
27
|
-
|
28
|
-
function converted(s) {
|
29
|
-
if (s.indexOf('"') === 0) {
|
30
|
-
// This is a quoted cookie as according to RFC2068, unescape
|
31
|
-
s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
|
32
|
-
}
|
33
|
-
try {
|
34
|
-
return config.json ? JSON.parse(s) : s;
|
35
|
-
} catch(er) {}
|
36
|
-
}
|
37
|
-
|
38
|
-
var config = $.cookie = function (key, value, options) {
|
39
|
-
|
40
|
-
// write
|
41
|
-
if (value !== undefined) {
|
42
|
-
options = $.extend({}, config.defaults, options);
|
43
|
-
|
44
|
-
if (typeof options.expires === 'number') {
|
45
|
-
var days = options.expires, t = options.expires = new Date();
|
46
|
-
t.setDate(t.getDate() + days);
|
47
|
-
}
|
48
|
-
|
49
|
-
value = config.json ? JSON.stringify(value) : String(value);
|
50
|
-
|
51
|
-
return (document.cookie = [
|
52
|
-
config.raw ? key : encodeURIComponent(key),
|
53
|
-
'=',
|
54
|
-
config.raw ? value : encodeURIComponent(value),
|
55
|
-
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
|
56
|
-
options.path ? '; path=' + options.path : '',
|
57
|
-
options.domain ? '; domain=' + options.domain : '',
|
58
|
-
options.secure ? '; secure' : ''
|
59
|
-
].join(''));
|
60
|
-
}
|
61
|
-
|
62
|
-
// read
|
63
|
-
var decode = config.raw ? raw : decoded;
|
64
|
-
var cookies = document.cookie.split('; ');
|
65
|
-
var result = key ? undefined : {};
|
66
|
-
for (var i = 0, l = cookies.length; i < l; i++) {
|
67
|
-
var parts = cookies[i].split('=');
|
68
|
-
var name = decode(parts.shift());
|
69
|
-
var cookie = decode(parts.join('='));
|
70
|
-
|
71
|
-
if (key && key === name) {
|
72
|
-
result = converted(cookie);
|
73
|
-
break;
|
74
|
-
}
|
75
|
-
|
76
|
-
if (!key) {
|
77
|
-
result[name] = converted(cookie);
|
78
|
-
}
|
79
|
-
}
|
80
|
-
|
81
|
-
return result;
|
82
|
-
};
|
83
|
-
|
84
|
-
config.defaults = {};
|
85
|
-
|
86
|
-
$.removeCookie = function (key, options) {
|
87
|
-
if ($.cookie(key) !== undefined) {
|
88
|
-
$.cookie(key, '', $.extend(options, { expires: -1 }));
|
89
|
-
return true;
|
90
|
-
}
|
91
|
-
return false;
|
92
|
-
};
|
93
|
-
|
94
|
-
}));
|