/
jquery.qs.infobox.js
103 lines (93 loc) · 3.98 KB
/
jquery.qs.infobox.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//===================================================================================
// Microsoft patterns & practices
// Silk : Web Client Guidance
//===================================================================================
// Copyright (c) Microsoft Corporation. All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===================================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious. No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===================================================================================
(function ($) {
var offsetX = 20,
offsetY = 20,
mouseOverBox = false,
leftSideAdjustment = -270;
$.widget('qs.infobox', {
options: {
dataUrl: '',
maxItems: 10
},
_create: function () {
var that = this,
name = this.name;
this.infoboxElement = $('<div class="qs-infobox" />');
this.infoboxElement.appendTo('body')
.bind('mouseenter.' + name, function () {
mouseOverBox = true;
})
.bind('mouseleave.' + name, function () {
mouseOverBox = false;
that.hideTagLinks();
});
},
hideTagLinks: function () {
if (!mouseOverBox) {
this.infoboxElement.hide();
}
},
displayTagLinks: function (event, tagName) {
var i,
html,
that = this,
options = this.options,
elem = this.infoboxElement,
top = event.pageY + offsetY,
left = event.pageX + offsetX,
url = options.dataUrl + tagName + '?count=' + options.maxItems,
displayResult = function () {
elem.html(html);
elem.css({ top: top, left: left });
elem.show();
};
if (event.pageX > window.screenWidth / 2) {
left = event.pageX + leftSideAdjustment;
}
$.ajax({
url: url,
dataType: 'jsonp',
success: function (data) {
if (data != null) {
html = '<h1>Popular Links for ' + tagName + '</h1><ul>';
for (i = 0; i < data.length - 1; i += 1) {
html += '<li><a href="' +
data[i].u +
'" target="_blank">' +
data[i].d + '</a></li>';
}
html += '</ul>';
} else {
html = '<h1>Data Error</h1><p>The AJAX call returned null. This happens when using non-Internet Explorer browsers and is the expected behavior when viewing file based HTML files.</p><p>Please use Internet Explorer 9 and click the "Allow Blocked Content" button to run this QuickStart.</p>';
}
displayResult();
},
error: function (jqXHR, textStatus, errorThrown) {
html = '<h1>AJAX Error</h1>' +
'<p>The AJAX call returned the following error: ' +
jqXHR.statusText + '.</p>';
displayResult();
}
});
},
destroy: function () {
$.Widget.prototype.destroy.call(this);
this.infoboxElement.remove();
}
});
} (jQuery));