# all files / diagram-js/lib/features/mouse/ Mouse.js

90% Statements 18/20
25% Branches 1/4
66.67% Functions 4/6
90% Lines 18/20

    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
    1189×

    1189×

    1189×
    1189×

    1189×

    1189×
    1159×

    1159×

    1×

    1×

    2×

    2×
    2×
    2×
    2×

    2×
    2×

    2×
     export default function Mouse(eventBus) {
      var self = this;

      this._lastMoveEvent = null;

      function setLastMoveEvent(mousemoveEvent) {
        self._lastMoveEvent = mousemoveEvent;
      }

      eventBus.on('canvas.init', function(context) {
        var svg = self._svg = context.svg;

        svg.addEventListener('mousemove', setLastMoveEvent);
      });

      eventBus.on('canvas.destroy', function() {
        self._lastMouseEvent = null;

        self._svg.removeEventListener('mousemove', setLastMoveEvent);
      });
    }

    Mouse.$inject = [ 'eventBus' ];

    Mouse.prototype.getLastMoveEvent = function() {
      return this._lastMoveEvent || createMoveEvent(0, 0);
    };

    // helpers //////////

    export function createMoveEvent(x, y) {
      var event = document.createEvent('MouseEvent');

      var screenX = x,
          screenY = y,
          clientX = x,
          clientY = y;

      Eif (event.initMouseEvent) {
        event.initMouseEvent(
          'mousemove',
          true,
          true,
          window,
          0,
          screenX,
          screenY,
          clientX,
          clientY,
          false,
          false,
          false,
          false,
          0,
          null
        );
      }

      return event;
    }