Skip to content
This repository was archived by the owner on Aug 19, 2021. It is now read-only.

Commit 855febc

Browse files
committed
Update javascript to match vispy python implementation
1 parent 2859c4e commit 855febc

File tree

4 files changed

+32
-30
lines changed

4 files changed

+32
-30
lines changed

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"watchify": "^3.11.1",
3838
"jquery": "^3.3.1",
3939
"jquery-ui": "^1.12.1",
40-
"jquery-mousewheel": "^3.1.13",
4140
"screenfull": "^4.1.0"
4241
},
4342
"devDependencies": {

scripts/events.js

+28-27
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var VispyCanvas = require('./vispycanvas.js');
22
var screenfull = require("screenfull");
3-
var mousewheel = require("jquery-mousewheel");
3+
require('jquery');
4+
require('jquery-ui/ui/widgets/resizable');
45

56
/* Internal functions */
67
function get_pos(c, e) {
@@ -381,7 +382,7 @@ function init_app(c) {
381382

382383
// Generate a resize event when the user resizes the canvas with
383384
// jQuery resizable.
384-
c.$el.resize(function(e) {
385+
c.$el.on("resize", function(e) {
385386
c.resize([e.width(), e.height()]);
386387
}
387388
);
@@ -407,7 +408,7 @@ function init_app(c) {
407408
// button is pressed, or the left button is pressed.
408409
c._eventinfo.is_button_pressed = 0;
409410

410-
c.$el.mousemove(function(e) {
411+
c.$el.on("mousemove", function(e) {
411412
var event = gen_mouse_event(c, e, 'mouse_move');
412413

413414
// Vispy callbacks.
@@ -417,7 +418,7 @@ function init_app(c) {
417418
// c._eventinfo.last_event = event;
418419
c.event_queue.append(event);
419420
});
420-
c.$el.mousedown(function(e) {
421+
c.$el.on("mousedown", function(e) {
421422
++c._eventinfo.is_button_pressed;
422423
var event = gen_mouse_event(c, e, 'mouse_press');
423424

@@ -430,7 +431,7 @@ function init_app(c) {
430431
// c._eventinfo.last_event = event;
431432
c.event_queue.append(event);
432433
});
433-
c.$el.mouseup(function(e) {
434+
c.$el.on("mouseup", function(e) {
434435
--c._eventinfo.is_button_pressed;
435436
var event = gen_mouse_event(c, e, 'mouse_release');
436437

@@ -443,35 +444,35 @@ function init_app(c) {
443444
// c._eventinfo.last_event = event;
444445
c.event_queue.append(event);
445446
});
446-
c.$el.click(function(e) {
447+
c.$el.on("click", function(e) {
447448
// Reset the last press event.
448449
c._eventinfo.press_event = null;
449450
});
450-
c.$el.dblclick(function(e) {
451+
c.$el.on("dblclick", function(e) {
451452

452453
// Reset the last press event.
453454
c._eventinfo.press_event = null;
454455
});
455456
// This requires the mouse wheel jquery plugin.
456-
if (c.$el.mousewheel != undefined) {
457-
c.$el.mousewheel(function(e) {
458-
var event = gen_mouse_event(c, e, 'mouse_wheel');
459-
event.delta = [e.deltaX * e.deltaFactor * 0.01,
460-
e.deltaY * e.deltaFactor * 0.01];
461-
462-
// Vispy callbacks.
463-
c._mouse_wheel(event);
464-
465-
// Save the last event.
466-
// c._eventinfo.last_event = event;
467-
c.event_queue.append(event);
468-
469-
e.preventDefault();
470-
e.stopPropagation();
471-
});
472-
}
457+
c.$el.on("wheel", function(e) {
458+
var event = gen_mouse_event(c, e, 'mouse_wheel');
459+
// event.delta = [e.originalEvent.deltaX * e.deltaFactor * 0.01,
460+
// e.originalEvent.deltaY * e.deltaFactor * 0.01];
461+
event.delta = [e.originalEvent.deltaX * 0.01,
462+
e.originalEvent.deltaY * 0.01];
463+
464+
// Vispy callbacks.
465+
c._mouse_wheel(event);
466+
467+
// Save the last event.
468+
// c._eventinfo.last_event = event;
469+
c.event_queue.append(event);
470+
471+
e.preventDefault();
472+
e.stopPropagation();
473+
});
473474

474-
c.$el.keydown(function(e) {
475+
c.$el.on("keydown", function(e) {
475476
var event = gen_key_event(c, e, 'key_press');
476477

477478
// Vispy callbacks.
@@ -481,7 +482,7 @@ function init_app(c) {
481482
// c._eventinfo.last_event = event;
482483
c.event_queue.append(event);
483484
});
484-
c.$el.keyup(function(e) {
485+
c.$el.on("keyup", function(e) {
485486
var event = gen_key_event(c, e, 'key_release');
486487

487488
// Vispy callbacks.
@@ -492,7 +493,7 @@ function init_app(c) {
492493
c.event_queue.append(event);
493494
});
494495

495-
c.$el.mouseout(function(e) {
496+
c.$el.on("mouseout", function(e) {
496497
});
497498
}
498499

scripts/vispy.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var $ = require('jquery');
12
var VispyCanvas = require('./vispycanvas.js');
23
var gloo = require('./gloo.js');
34
var events = require('./events.js');

test.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
<!DOCTYPE html>
12
<html>
23
<head>
34
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
45
<!--
56
Vispy.js requires jQuery & jQueryUI.
67
-->
7-
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
8+
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
89
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
910
<script src="dist/vispy.min.js"></script>
1011
<script>
@@ -157,7 +158,7 @@
157158
initialize_canvas("#mycanvas2");
158159

159160
// Toggle fullscreen for the canvas when 'f' is pressed.
160-
$(window).keypress(function(e) {
161+
$(window).on("keypress", function(e) {
161162
if (String.fromCharCode(e.which) == 'f') {
162163
// c.$el.width("100%").height("100%");
163164
c.toggle_fullscreen();

0 commit comments

Comments
 (0)