This repository has been archived by the owner on Jan 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
118 lines (94 loc) · 2.82 KB
/
script.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
function rrdDropDownSelected(graphId, element)
{
rangeId = jQuery(element).val();
rrdSwitchRange(graphId, rangeId);
}
function rrdDoSwitchRange(graphId, rangeId)
{
var link = jQuery("a#__L" + graphId);
var image = jQuery("img#__I" + graphId);
var loader = jQuery("div#__LD" + graphId);
var allTabs = jQuery("ul#__T" + graphId + " li");
var currentTab = jQuery("li#__TI" + graphId + "X" + rangeId);
var select = jQuery("select#__T" + graphId);
image.addClass("rrdLoading");
loader.addClass("rrdLoaderActive");
image.load(function() {
jQuery(this).removeClass("rrdLoading");
loader.removeClass("rrdLoaderActive");
});
var removeQueryRegex = new RegExp("\\?.*$");
var imageUri = image.attr("src");
imageUri = imageUri.replace(removeQueryRegex, '') + "?range=" + rangeId;
image.attr("src", imageUri);
link.attr("href", imageUri + "&mode=fs");
allTabs.removeClass("rrdActiveTab");
currentTab.addClass("rrdActiveTab");
select.val(rangeId);
}
function rrdSwitchRange(graphId, rangeId)
{
var gangedGraphs = jQuery("input:checked[name='rrdgraph_gang']");
if (gangedGraphs.filter("[value='" + graphId + "']").length > 0)
{
gangedGraphs.each(function() {
rrdDoSwitchRange(jQuery(this).attr("value"), rangeId);
});
}
else
{
rrdDoSwitchRange(graphId, rangeId);
}
}
function rrdSwitchRangeRelative(jRrdContainer, offset)
{
var graphId = jRrdContainer.attr("data-graphid");
var ranges = jRrdContainer.attr("data-ranges");
var range = jRrdContainer.find("li.rrdActiveTab").index();
range += offset;
if ((range >= 0) && (range < ranges)) rrdSwitchRange(graphId, range);
}
jQuery().ready(function() {
var rrdImages = jQuery("div.rrdImage img");
var downX = 0;
var downY = 0;
var clickAllowed = true;
rrdImages.bind("touchstart", function(e) {
if (e.originalEvent.changedTouches.length > 1) return true;
var me = jQuery(this);
downX = e.originalEvent.changedTouches[0].pageX;
downY = e.originalEvent.changedTouches[0].pageY;
clickAllowed = true;
return true;
});
rrdImages.bind("touchend", function(e) {
if (e.originalEvent.changedTouches.length > 1) return true;
var me = jQuery(this);
var upX = e.originalEvent.changedTouches[0].pageX;
var upY = e.originalEvent.changedTouches[0].pageY;
if ((Math.abs(downX - upX) > 100) && (Math.abs(downY - upY) < 50))
{
var event = jQuery.Event((upX > downX) ? "swiperight" : "swipeleft");
me.trigger(event);
clickAllowed = false;
return false;
}
else
{
return true;
}
});
rrdImages.bind("click", function(e) {
if (!clickAllowed)
{
e.preventDefault();
return false;
}
});
rrdImages.bind("swiperight", function() {
rrdSwitchRangeRelative(jQuery(this).closest("div.rrdImage"), -1);
});
rrdImages.bind("swipeleft", function() {
rrdSwitchRangeRelative(jQuery(this).closest("div.rrdImage"), +1);
});
});