forked from alexbain/lirc_web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.js
More file actions
116 lines (97 loc) · 3.5 KB
/
core.js
File metadata and controls
116 lines (97 loc) · 3.5 KB
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
var OSUR = {
util: {}
};
// From Modernizr
// https://github.com/Modernizr/Modernizr/blob/master/feature-detects/touchevents.js
OSUR.util.hasTouchEvents = function() {
var bool;
if(('ontouchstart' in window) ||
window.DocumentTouch &&
document instanceof DocumentTouch) {
bool = true;
}
return bool;
};
$(function() {
// command-once buttons send a single command when clicked
$('.command-once').on('click', function(evt) {
$.ajax({
type: "POST",
url: $(this).attr('href'),
success: function(data) {},
error: function(xhr, type) {}
});
});
// command-repeater buttons repeatedly send the command while being clicked
// (uses send_start and send_stop behind the scenes)
$('.command-repeater').on('mousedown touchstart', function(evt) {
$.ajax({
type: "POST",
url: $(this).attr('href') + '/send_start',
success: function(data) {},
error: function(xhr, type) {}
});
$(this).attr('data-active', true);
});
// Capture any kind of mouse or touch "out" event
$('.command-repeater').on('mouseup touchend touchleave touchcancel', function(evt) {
$.ajax({
type: "POST",
url: $(this).attr('href') + '/send_stop',
success: function(data) {},
error: function(xhr, type) {}
});
$(this).attr('data-active', false);
});
// If the user clicks, holds, and drags mouse outside of window - handle that too
$(window).on('mouseup touchend touchleave touchcancel', function(evt) {
$('.command-repeater[data-active=true]').trigger('mouseup');
});
// macro-link buttons send a command to execute the macro when clicked
$('.macro-link').on('click', function(evt) {
evt.preventDefault();
$.ajax({
type: "POST",
url: $(this).attr('href'),
success: function(data) {},
error: function(xhr, type) {}
});
});
// Different visual behavior for touch devices
if (OSUR.util.hasTouchEvents()) {
$('body').addClass('has-touch');
$('.command-link, .remote-link').on('touchstart', function(evt) {
$(this).addClass('active');
});
$('.command-link, .remote-link').on('touchend touchleave touchcancel', function(evt) {
$(this).removeClass('active');
});
$('body').on('touchcancel', function(evt) {
$('.command-link').removeClass('active');
});
} else {
$('body').addClass('no-touch');
}
// Back button shown on remote pages
$('.back').on('click', function(evt) {
$('.remote.active').removeClass('active');
$('.remotes-nav').removeClass('hidden');
$('.macros-nav').removeClass('hidden');
$('.back').addClass('hidden');
$('#title').html($('#title').attr('data-text'));
$('#titlebar').removeClass('is-remote');
});
// Navigate to remote pages
$('.remotes-nav a').on('click', function(evt) {
evt.preventDefault();
var href = $(this).attr('href');
$('.remotes-nav').addClass('hidden');
$('.macros-nav').addClass('hidden');
$(href).addClass('active');
$('.back').removeClass('hidden');
$('#title').html($(this).html());
$('#titlebar').addClass('is-remote');
});
// Remove 300ms delay after tapping
OSUR.fastClick = new FastClick(document.body);
});