javascriptdom-eventskineticjskonvajs

KonvaJS: event.preventDefault is not a function


Nowadays I am playing with KonvaJS. I have set a click event listener on a shape. When I click on shape, the listener is invoked. In my listener I am invoking event.preventDefault() method to stop triggering of other events. But when I do so it says that:

Uncaught TypeError: event.preventDefault is not a function

I don't know what I am missing. Here is my code :

<!DOCTYPE html>
<html>

<head>
  <script src="https://cdn.rawgit.com/konvajs/konva/0.9.5/konva.min.js"></script>
  <meta charset="utf-8">
  <title>Konva Scale Animation Demo</title>
  <style>
    body {
      margin: 0;
      padding: 0;
      overflow: hidden;
      background-color: #F0F0F0;
    }
  </style>
</head>

<body>
  <div id="container"></div>
  <script>
    var width = window.innerWidth;
    var height = window.innerHeight;

    var stage = new Konva.Stage({
      container: 'container',
      width: width,
      height: height
    });

    var layer = new Konva.Layer();

    stage.add(layer);

    var gArrow2 = new Image();
     var circle2 = new Konva.Image({

        x: 60, //on canvas
        y: 60,
        image: gArrow2,
        name: 'abc',
        id: 'xyz',
        draggable:true
      });
      circle2.on('click',function(event){
        event.preventDefault()
        console.log(e.type);
      });
      circle2.on('mouseup',function(event){
         event.preventDefault()
        console.log(e.type);
      });
    gArrow2.onload = function() {
     
      layer.add(circle2);
      layer.draw();
    }
    gArrow2.src = 'http://konvajs.github.io/assets/snake.png';

    var period = 1500;
    var amplitude = 10;
    var centerX = stage.getWidth() / 2;
    var centerY = stage.getHeight() / 2;

    var anim = new Konva.Animation(function(frame) {
      circle2.setY(amplitude * Math.sin(frame.time * 2 * Math.PI / period) + centerY);
    }, layer);

    anim.start();
  </script>

</body>

</html> 

Solution

  • It seems that KonvaJS's on handler does not give you directly the browser events but an object that looks like: enter image description here.

    The browser's original event is stored in the evt property.

    In your code, try to replace event.preventDefault() by event.evt.preventDefault(): http://plnkr.co/edit/tCESd42r67TzeuLiISxU.