MCPcopy
hub / github.com/DHTMLX/gantt / registerEventHandlers

Function registerEventHandlers

samples/common/codehighlight/codemirror.js:7918–8026  ·  view source on GitHub ↗
(cm)

Source from the content-addressed store, hash-verified

7916
7917 // Attach the necessary event handlers when initializing the editor
7918 function registerEventHandlers(cm) {
7919 var d = cm.display;
7920 on(d.scroller, "mousedown", operation(cm, onMouseDown));
7921 // Older IE's will not fire a second mousedown for a double click
7922 if (ie && ie_version < 11)
7923 { on(d.scroller, "dblclick", operation(cm, function (e) {
7924 if (signalDOMEvent(cm, e)) { return }
7925 var pos = posFromMouse(cm, e);
7926 if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) { return }
7927 e_preventDefault(e);
7928 var word = cm.findWordAt(pos);
7929 extendSelection(cm.doc, word.anchor, word.head);
7930 })); }
7931 else
7932 { on(d.scroller, "dblclick", function (e) { return signalDOMEvent(cm, e) || e_preventDefault(e); }); }
7933 // Some browsers fire contextmenu *after* opening the menu, at
7934 // which point we can't mess with it anymore. Context menu is
7935 // handled in onMouseDown for these browsers.
7936 on(d.scroller, "contextmenu", function (e) { return onContextMenu(cm, e); });
7937 on(d.input.getField(), "contextmenu", function (e) {
7938 if (!d.scroller.contains(e.target)) { onContextMenu(cm, e); }
7939 });
7940
7941 // Used to suppress mouse event handling when a touch happens
7942 var touchFinished, prevTouch = {end: 0};
7943 function finishTouch() {
7944 if (d.activeTouch) {
7945 touchFinished = setTimeout(function () { return d.activeTouch = null; }, 1000);
7946 prevTouch = d.activeTouch;
7947 prevTouch.end = +new Date;
7948 }
7949 }
7950 function isMouseLikeTouchEvent(e) {
7951 if (e.touches.length != 1) { return false }
7952 var touch = e.touches[0];
7953 return touch.radiusX <= 1 && touch.radiusY <= 1
7954 }
7955 function farAway(touch, other) {
7956 if (other.left == null) { return true }
7957 var dx = other.left - touch.left, dy = other.top - touch.top;
7958 return dx * dx + dy * dy > 20 * 20
7959 }
7960 on(d.scroller, "touchstart", function (e) {
7961 if (!signalDOMEvent(cm, e) && !isMouseLikeTouchEvent(e) && !clickInGutter(cm, e)) {
7962 d.input.ensurePolled();
7963 clearTimeout(touchFinished);
7964 var now = +new Date;
7965 d.activeTouch = {start: now, moved: false,
7966 prev: now - prevTouch.end <= 300 ? prevTouch : null};
7967 if (e.touches.length == 1) {
7968 d.activeTouch.left = e.touches[0].pageX;
7969 d.activeTouch.top = e.touches[0].pageY;
7970 }
7971 }
7972 });
7973 on(d.scroller, "touchmove", function () {
7974 if (d.activeTouch) { d.activeTouch.moved = true; }
7975 });

Callers 1

CodeMirrorFunction · 0.85

Calls 15

operationFunction · 0.85
signalDOMEventFunction · 0.85
posFromMouseFunction · 0.85
clickInGutterFunction · 0.85
eventInWidgetFunction · 0.85
e_preventDefaultFunction · 0.85
extendSelectionFunction · 0.85
isMouseLikeTouchEventFunction · 0.85
farAwayFunction · 0.85
PosFunction · 0.85
clipPosFunction · 0.85
finishTouchFunction · 0.85

Tested by

no test coverage detected