Converted cammie.coffee to cammie.js

This commit is contained in:
fklinck 2018-12-14 01:48:29 +01:00
parent f9a34b0bd7
commit 233477e937
2 changed files with 42 additions and 32 deletions

View file

@ -1,32 +0,0 @@
# Reworked version of the underscorejs debounce
debounce = (func, wait, initial = () -> ) ->
timeout = false
() ->
context = this
args = arguments
later = () ->
timeout = null
func.apply context, args
callNow = !timeout
clearTimeout timeout
timeout = setTimeout later, wait
initial.apply context, args if callNow
# Display controls when moving mouse
$ "#cammie-ctrls"
.mousemove debounce () ->
$ this
.removeClass 'display'
, 3000, () ->
$ this
.addClass 'display'
# Cammie controls
$ '.ctrl'
.click ->
$context = $ this
$.ajax "https://kelder.zeus.ugent.be/webcam/cgi/ptdc.cgi",
data:
command: $context.data 'command'
posX: $context.data 'x'
posY: $context.data 'y'

View file

@ -0,0 +1,42 @@
var debounce;
debounce = function(func, wait, initial) {
var timeout;
if (initial == null) {
initial = function() {};
}
timeout = false;
return function() {
var args, callNow, context, later;
context = this;
args = arguments;
later = function() {
timeout = null;
return func.apply(context, args);
};
callNow = !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) {
return initial.apply(context, args);
}
};
};
$("#cammie-ctrls").mousemove(debounce(function() {
return $(this).removeClass('display');
}, 3000, function() {
return $(this).addClass('display');
}));
$('.ctrl').click(function() {
var $context;
$context = $(this);
return $.ajax("https://kelder.zeus.ugent.be/webcam/cgi/ptdc.cgi", {
data: {
command: $context.data('command'),
posX: $context.data('x'),
posY: $context.data('y')
}
});
});