-
Notifications
You must be signed in to change notification settings - Fork 562
/
Copy pathjquery.placement.above.js
64 lines (62 loc) · 1.71 KB
/
jquery.placement.above.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
*
* Copyright (c) 2007 Sam Collett (http://www.texotela.co.uk)
* Licensed under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
*
* $LastChangedDate: 2007-07-27 14:44:11 +0100 (Fri, 27 Jul 2007) $
* $Rev: 2499 $
*
*/
/**
* Places selected element above another one
*
* @name above
* @name element Which element to place the current one above
* @param options Hash with the following options:
* adjustRight How many pixels to adjust right by
* adjustDown How many pixels to adjust down by
* @author Sam Collett (http://www.texotela.co.uk)
* @example $("#mytip").above("#myinput");
* @example $("#mytip").above("#myinput", {adjustRight: 10});
*/
jQuery.fn.above = function(element, options)
{
element = element || null;
options = jQuery.extend({adjustRight: 0, adjustDown: 0}, options);
getCSS = function(el, prop)
{
return (parseInt(jQuery.css(el, prop)) || 0);
}
return this.each(
function()
{
if(element == null) return false;
var what = jQuery(element);
var left = what[0].offsetWidth - options.adjustRight, top = options.adjustDown +
getCSS(this, 'borderBottomWidth') +
getCSS(this, 'borderTopWidth') +
getCSS(this, 'paddingBottom') +
getCSS(this, 'paddingTop') +
getCSS(this, 'height');
if(jQuery.browser.opera)
{
var version = navigator.userAgent.match(/\d+\.\d+/);
if(version < 9)
{
left += getCSS(what[0], 'borderLeftWidth') +
getCSS(what.parent()[0], 'paddingLeft');
}
}
what.after(this);
jQuery(this).css(
{
position: "absolute",
display: "inline",
marginLeft: "-" + left + "px",
marginTop: "-" + top + "px"
}
);
}
);
}