theozaurus / drawing-fabric.js

An expandable drawing editor based on fabric.js
MIT License
18 stars 2 forks source link

error when adding functionality #1

Closed abit closed 10 years ago

abit commented 10 years ago

When I create a drawing canvas:

var canvas = new DrawingFabric.Canvas('my_canvas');

and add a functionality to it:

canvas.addFunctionality(new DrawingFabric.Functionality.drawLineWithMouse());

and when I try to create a line, I get an error:

Uncaught TypeError: Object [object Object] has no method 'tool' 

in the line 670 in drawing_fabric.js:

      var isPath = function(){
        return 'line' == that.tool();  // <-- here is the error

Also the selection on the canvas is not going away when I click again and again on it. Each click propagate the error above.

What is that 'tool()' and how to solve the problem with error?

On the demo page the Line also doesn't work, though no errors are appearing in the console.

P.S. I build the drawing_fabric.js from the ruby project cloned from here, and included the built js file into my project

abit commented 10 years ago

I found out - something wrong with the Stroke Width, if I set it bigger than 1 it doesn't show the line, if the thickness is 1, everything is normal

abit commented 10 years ago

So, that was an old version of the fabric.js library. Also, the new version has a bug (when creating a line). There is a workaround/fix for that. All info look here:

https://github.com/kangax/fabric.js/issues/1014

theozaurus commented 10 years ago

Well sleuthed! Is there anything you want me to take a look at?

abit commented 10 years ago

everything is fine now. strange is that the version built and the version from the kitchensink are not the same. I have problems with the fabric.js build on my own, so I use now only from the kitchensink.


An offtopic question: how would you implement the deleteSelectedObject() Functionality?

abit commented 10 years ago

@theozaurus: I created this, but it doesn't work:

DrawingFabric.Functionality.destroy = (function(){

  return function(){

    this.initialize = function(){

      var that = this;

      //var obj;

      var handle = function(event){
        //obj = that.fabricCanvas.getActiveObject();
        //if(obj){
          destroy()
        //}
      };

      fabric.util.addListener(this.fabricCanvas.upperCanvasEl, 'destroy', handle);
    };

  };

}());

I also registered it in tools, but when I set a breakpoint on destroy() it never fires.

theozaurus commented 10 years ago

I've got some code that listens for the delete key to be pressed and deletes an object. That might help you get a bit further. Take a peek at the keyboard_commands.js: https://github.com/theozaurus/drawing-fabric.js/blob/master/src/functionality/keyboard_commands.js#L27