Skip to content

Commit 3f9a8e7

Browse files
committed
- Added Tipsy (http://onehackoranother.com/projects/jquery/tipsy/) so that one can create tooltips for additional explanations easily.
1 parent 7698b9b commit 3f9a8e7

File tree

8 files changed

+291
-0
lines changed

8 files changed

+291
-0
lines changed

interface/web/js/jquery.tipsy.js

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
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,
31+
height: this.$element[0].offsetHeight
32+
});
33+
34+
var actualWidth = $tip[0].offsetWidth,
35+
actualHeight = $tip[0].offsetHeight,
36+
gravity = maybeCall(this.options.gravity, this.$element[0]);
37+
38+
var tp;
39+
switch (gravity.charAt(0)) {
40+
case 'n':
41+
tp = {top: pos.top + pos.height + this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2};
42+
break;
43+
case 's':
44+
tp = {top: pos.top - actualHeight - this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2};
45+
break;
46+
case 'e':
47+
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth - this.options.offset};
48+
break;
49+
case 'w':
50+
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width + this.options.offset};
51+
break;
52+
}
53+
54+
if (gravity.length == 2) {
55+
if (gravity.charAt(1) == 'w') {
56+
tp.left = pos.left + pos.width / 2 - 15;
57+
} else {
58+
tp.left = pos.left + pos.width / 2 - actualWidth + 15;
59+
}
60+
}
61+
62+
$tip.css(tp).addClass('tipsy-' + gravity);
63+
$tip.find('.tipsy-arrow')[0].className = 'tipsy-arrow tipsy-arrow-' + gravity.charAt(0);
64+
if (this.options.className) {
65+
$tip.addClass(maybeCall(this.options.className, this.$element[0]));
66+
}
67+
68+
if (this.options.fade) {
69+
$tip.stop().css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: this.options.opacity});
70+
} else {
71+
$tip.css({visibility: 'visible', opacity: this.options.opacity});
72+
}
73+
}
74+
},
75+
76+
hide: function() {
77+
if (this.options.fade) {
78+
this.tip().stop().fadeOut(function() { $(this).remove(); });
79+
} else {
80+
this.tip().remove();
81+
}
82+
},
83+
84+
fixTitle: function() {
85+
var $e = this.$element;
86+
if ($e.attr('title') || typeof($e.attr('original-title')) != 'string') {
87+
$e.attr('original-title', $e.attr('title') || '').removeAttr('title');
88+
}
89+
},
90+
91+
getTitle: function() {
92+
var title, $e = this.$element, o = this.options;
93+
this.fixTitle();
94+
var title, o = this.options;
95+
if (typeof o.title == 'string') {
96+
title = $e.attr(o.title == 'title' ? 'original-title' : o.title);
97+
} else if (typeof o.title == 'function') {
98+
title = o.title.call($e[0]);
99+
}
100+
title = ('' + title).replace(/(^\s*|\s*$)/, "");
101+
return title || o.fallback;
102+
},
103+
104+
tip: function() {
105+
if (!this.$tip) {
106+
this.$tip = $('<div class="tipsy"></div>').html('<div class="tipsy-arrow"></div><div class="tipsy-inner"></div>');
107+
}
108+
return this.$tip;
109+
},
110+
111+
validate: function() {
112+
if (!this.$element[0].parentNode) {
113+
this.hide();
114+
this.$element = null;
115+
this.options = null;
116+
}
117+
},
118+
119+
enable: function() { this.enabled = true; },
120+
disable: function() { this.enabled = false; },
121+
toggleEnabled: function() { this.enabled = !this.enabled; }
122+
};
123+
124+
$.fn.tipsy = function(options) {
125+
126+
if (options === true) {
127+
return this.data('tipsy');
128+
} else if (typeof options == 'string') {
129+
var tipsy = this.data('tipsy');
130+
if (tipsy) tipsy[options]();
131+
return this;
132+
}
133+
134+
options = $.extend({}, $.fn.tipsy.defaults, options);
135+
136+
function get(ele) {
137+
var tipsy = $.data(ele, 'tipsy');
138+
if (!tipsy) {
139+
tipsy = new Tipsy(ele, $.fn.tipsy.elementOptions(ele, options));
140+
$.data(ele, 'tipsy', tipsy);
141+
}
142+
return tipsy;
143+
}
144+
145+
function enter() {
146+
var tipsy = get(this);
147+
tipsy.hoverState = 'in';
148+
if (options.delayIn == 0) {
149+
tipsy.show();
150+
} else {
151+
tipsy.fixTitle();
152+
setTimeout(function() { if (tipsy.hoverState == 'in') tipsy.show(); }, options.delayIn);
153+
}
154+
};
155+
156+
function leave() {
157+
var tipsy = get(this);
158+
tipsy.hoverState = 'out';
159+
if (options.delayOut == 0) {
160+
tipsy.hide();
161+
} else {
162+
setTimeout(function() { if (tipsy.hoverState == 'out') tipsy.hide(); }, options.delayOut);
163+
}
164+
};
165+
166+
if (!options.live) this.each(function() { get(this); });
167+
168+
if (options.trigger != 'manual') {
169+
var binder = options.live ? 'live' : 'bind',
170+
eventIn = options.trigger == 'hover' ? 'mouseenter' : 'focus',
171+
eventOut = options.trigger == 'hover' ? 'mouseleave' : 'blur';
172+
this[binder](eventIn, enter)[binder](eventOut, leave);
173+
}
174+
175+
return this;
176+
177+
};
178+
179+
$.fn.tipsy.defaults = {
180+
className: null,
181+
delayIn: 0,
182+
delayOut: 0,
183+
fade: false,
184+
fallback: '',
185+
gravity: 'n',
186+
html: false,
187+
live: false,
188+
offset: 0,
189+
opacity: 0.8,
190+
title: 'title',
191+
trigger: 'hover'
192+
};
193+
194+
// Overwrite this method to provide options on a per-element basis.
195+
// For example, you could store the gravity in a 'tipsy-gravity' attribute:
196+
// return $.extend({}, options, {gravity: $(ele).attr('tipsy-gravity') || 'n' });
197+
// (remember - do not modify 'options' in place!)
198+
$.fn.tipsy.elementOptions = function(ele, options) {
199+
return $.metadata ? $.extend({}, options, $(ele).metadata()) : options;
200+
};
201+
202+
$.fn.tipsy.autoNS = function() {
203+
return $(this).offset().top > ($(document).scrollTop() + $(window).height() / 2) ? 's' : 'n';
204+
};
205+
206+
$.fn.tipsy.autoWE = function() {
207+
return $(this).offset().left > ($(document).scrollLeft() + $(window).width() / 2) ? 'e' : 'w';
208+
};
209+
210+
/**
211+
* yields a closure of the supplied parameters, producing a function that takes
212+
* no arguments and is suitable for use as an autogravity function like so:
213+
*
214+
* @param margin (int) - distance from the viewable region edge that an
215+
* element should be before setting its tooltip's gravity to be away
216+
* from that edge.
217+
* @param prefer (string, e.g. 'n', 'sw', 'w') - the direction to prefer
218+
* if there are no viewable region edges effecting the tooltip's
219+
* gravity. It will try to vary from this minimally, for example,
220+
* if 'sw' is preferred and an element is near the right viewable
221+
* region edge, but not the top edge, it will set the gravity for
222+
* that element's tooltip to be 'se', preserving the southern
223+
* component.
224+
*/
225+
$.fn.tipsy.autoBounds = function(margin, prefer) {
226+
return function() {
227+
var dir = {ns: prefer[0], ew: (prefer.length > 1 ? prefer[1] : false)},
228+
boundTop = $(document).scrollTop() + margin,
229+
boundLeft = $(document).scrollLeft() + margin,
230+
$this = $(this);
231+
232+
if ($this.offset().top < boundTop) dir.ns = 'n';
233+
if ($this.offset().left < boundLeft) dir.ew = 'w';
234+
if ($(window).width() + $(document).scrollLeft() - $this.offset().left < margin) dir.ew = 'e';
235+
if ($(window).height() + $(document).scrollTop() - $this.offset().top < margin) dir.ns = 's';
236+
237+
return dir.ns + (dir.ew ? dir.ew : '');
238+
}
239+
};
240+
241+
})(jQuery);

interface/web/themes/default/css/central.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
@import url(screen/content.css);
2727
@import url(screen/uni-form-generic.css);
2828
@import url(screen/uni-form.css);
29+
@import url(screen/tipsy.css);
2930
@import url(screen/content_ispc.css);
3031

3132
/* import print layout | Druck-Layout einbinden */

interface/web/themes/default/css/screen/content_ispc.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,5 +1260,17 @@
12601260
width:20px;
12611261
margin:0 7px 0 0;
12621262
}
1263+
1264+
.ttip{
1265+
width:16px;
1266+
height:16px;
1267+
cursor:pointer;
1268+
background: url(../../icons/x16/question_frame.png) no-repeat center center;
1269+
float:right;
1270+
display:inline;
1271+
position:absolute;
1272+
right:-2px;
1273+
top:-2px;
1274+
}
12631275
}
12641276

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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; }

interface/web/themes/default/templates/main.tpl.htm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
<script type="text/javascript" src="js/scrigo.js.php"></script>
6262
<script type="text/javascript" src="js/uni-form/uni-form.jquery.js"></script>
6363
<script type="text/javascript" src="js/jquery.ispconfigsearch.js"></script>
64+
<script type="text/javascript" src="js/jquery.tipsy.js"></script>
6465
<script language="JavaScript" type="text/javascript">
6566
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
6667
if(!is_chrome && getInternetExplorerVersion() > 8.0) {
@@ -90,6 +91,8 @@
9091
noResultsLimit: '<tmpl_var name="globalsearch_noresults_limit_txt">',
9192
searchFieldWatermark: '<tmpl_var name="globalsearch_searchfield_watermark_txt">'
9293
});
94+
95+
jQuery('.ttip').tipsy({live: true, gravity: 'sw'});
9396
});
9497

9598

interface/web/themes/default_64_navimg/templates/main.tpl.htm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<script type="text/javascript" src="js/scrigo.js.php"></script>
6363
<script type="text/javascript" src="js/uni-form/uni-form.jquery.js"></script>
6464
<script type="text/javascript" src="js/jquery.ispconfigsearch.js"></script>
65+
<script type="text/javascript" src="js/jquery.tipsy.js"></script>
6566
<script language="JavaScript" type="text/javascript">
6667
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
6768
if(!is_chrome && getInternetExplorerVersion() > 8.0) {
@@ -91,6 +92,8 @@
9192
noResultsLimit: '<tmpl_var name="globalsearch_noresults_limit_txt">',
9293
searchFieldWatermark: '<tmpl_var name="globalsearch_searchfield_watermark_txt">'
9394
});
95+
96+
jQuery('.ttip').tipsy({live: true, gravity: 'sw'});
9497
});
9598

9699
jQuery(document).bind("change", function(event) {

interface/web/themes/default_combobox/templates/main.tpl.htm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<script type="text/javascript" src="js/scrigo.js.php"></script>
6363
<script type="text/javascript" src="js/uni-form/uni-form.jquery.js"></script>
6464
<script type="text/javascript" src="js/jquery.ispconfigsearch.js"></script>
65+
<script type="text/javascript" src="js/jquery.tipsy.js"></script>
6566
<script language="JavaScript" type="text/javascript">
6667
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
6768
if(!is_chrome && getInternetExplorerVersion() > 8.0) {
@@ -92,6 +93,8 @@
9293
noResultsLimit: '<tmpl_var name="globalsearch_noresults_limit_txt">',
9394
searchFieldWatermark: '<tmpl_var name="globalsearch_searchfield_watermark_txt">'
9495
});
96+
97+
jQuery('.ttip').tipsy({live: true, gravity: 'sw'});
9598
});
9699

97100
jQuery(document).bind("change", function(event) {

interface/web/themes/default_no_navimg/templates/main.tpl.htm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<script type="text/javascript" src="js/scrigo.js.php"></script>
6363
<script type="text/javascript" src="js/uni-form/uni-form.jquery.js"></script>
6464
<script type="text/javascript" src="js/jquery.ispconfigsearch.js"></script>
65+
<script type="text/javascript" src="js/jquery.tipsy.js"></script>
6566
<script language="JavaScript" type="text/javascript">
6667
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
6768
if(!is_chrome && getInternetExplorerVersion() > 8.0) {
@@ -91,6 +92,8 @@
9192
noResultsLimit: '<tmpl_var name="globalsearch_noresults_limit_txt">',
9293
searchFieldWatermark: '<tmpl_var name="globalsearch_searchfield_watermark_txt">'
9394
});
95+
96+
jQuery('.ttip').tipsy({live: true, gravity: 'sw'});
9497
});
9598

9699
jQuery(document).bind("change", function(event) {

0 commit comments

Comments
 (0)