-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.linkqtip.js
68 lines (61 loc) · 2.08 KB
/
jquery.linkqtip.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
(function($) {
$.LinkQTip = function(element, options) {
var defaults = {
thumbnailWidth: 320,
thumbnailHeight: 240,
viewPortWidth: 1024,
offsetTop: 0,
offsetLeft: 20,
onLinkQTipShow: function() {}
};
var qtip = this;
var div = null;
qtip.settings = {};
qtip.init = function() {
qtip.settings = $.extend({}, defaults, options);
$(element).hover(showQTip, hideQTip);
};
qtip.toggle = function() {
if(div != null) {
hideQTip();
} else {
showQTip();
}
};
var showQTip = function() {
if(div != null) {
return;
}
var o = qtip.settings;
var topPosition = $(element).offset().top + o.offsetTop;
var leftPosition = $(element).offset().left + $(element).width() + o.offsetLeft;
div = $('<div/>');
$(div).css({
left: leftPosition+'px',
top: topPosition+'px',
width: o.thumbnailWidth+'px',
height: o.thumbnailHeight+'px'
});
$(div).addClass('link-qtip');
var imgUrl = 'http://api.webthumbnail.org?width='+o.thumbnailWidth+'&height='+o.thumbnailHeight+'&format=png&screen='+o.viewPortWidth+'&url='+$(element).attr("href");
var img = $('<img />');
img.attr('src', imgUrl);
$(div).append(img);
$('body').append(div);
o.onLinkQTipShow();
};
var hideQTip = function() {
$(div).remove();
div = null;
};
qtip.init();
};
$.fn.linkQTip = function (options) {
return this.each(function () {
if (undefined == $(this).data('LinkQTip')) {
var qtip = new $.LinkQTip(this, options);
$(this).data('LinkQTip', qtip);
}
});
};
})(jQuery);