-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathmarginotes.js
74 lines (71 loc) · 2.31 KB
/
marginotes.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
65
66
67
68
69
70
71
72
73
74
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof module === 'object' && module.exports) {
// Node/CommonJS
module.exports = function( root, jQuery ) {
if ( jQuery === undefined ) {
// require('jQuery') returns a factory that requires window to
// build a jQuery instance, we normalize how we use modules
// that require this pattern but the window provided is a noop
// if it's defined (how jquery works)
if ( typeof window !== 'undefined' ) {
jQuery = require('jquery');
}
else {
jQuery = require('jquery')(root);
}
}
factory(jQuery);
return jQuery;
};
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {
$.fn.marginotes = function (options) {
options = options || {}
var field = options.field || 'desc'
var spans = this.filter('span')
$('body').append('<div class="margintooltip" style="display: none;"></div>')
spans.css({
'border-bottom': '1px dashed #337ab7',
'cursor': 'help'
})
this.hover(function (e) {
var description = $(this).attr(field)
var parent = $(this.parentElement)
var position = parent.position()
var tooltip = $('.margintooltip')
var width = Math.min(options.width || 100, position.left)
if (width < 60 || !description) {
return
}
tooltip
.css({
'border-right': 'solid 2px #337ab7',
'font-size': '13px',
'left': position.left - width - 5,
'min-height': parent.height(),
'padding-right': '7px',
'position': 'absolute',
'text-align': 'right',
'top': position.top,
'width': width
})
.text(description)
.stop()
.fadeIn({
duration:100,
queue: false
})
}, function () {
$('.margintooltip').stop()
$('.margintooltip').fadeOut({
duration: 100
})
})
}
}));