JavaScript FabricJs Custom Attribute SVG strange behaviour fabricjs custom attributes,fabricjs add custom attributes

I want to add a custom attribute for each object in my canvas. I did that using:

fabric.Object.prototype.toObject = (function (toObject) {
    return function () {
        return fabric.util.object.extend(toObject.call(this), {
            zzz: this.zzz
        });
    };
})(fabric.Object.prototype.toObject);

After that I set my zzz property to 100 for each object:

fabric.Object.prototype.zzz = 100;

After this I put inside the canvas a text:

var text = new fabric.Text("time", {fill: '#999', zzz: 85, top: 50});
canvas.add(text);

And then I put inside a SVG (The svg is added by clicking a button [probably not important]):

fabric.loadSVGFromURL(link, function (objects, options) {
    var group = fabric.util.groupSVGElements(objects, options);
    group.set({
        ...,
        zzz: 88
    });
    canvas.add(group);
    canvas.renderAll();
});

Now If I do a console.log(selectedObject.zzz); I get 85 for text and 88 for SVG. Everything great. But ... If I do:

myjson = JSON.stringify(canvas);
console.log(myjson);

And load this Json and then console.log(selectedObject.zzz); I get the 85 for text and 100 for SVG. But the SVG doesn't have the zzz property in it (it has 100 because of fabric.Object.prototype.zzz = 100) but instead every path has the zzz property with value 100; (at first when the SVG had 88 the paths didn't have the zzz property inside).

Image with the SVG after json: (no zzz property) Pic 1

Image with the SVG's paths after json: (zzz property for each path)

Pic 2

My question is how can I have property zzz in SVG after the Json and get after console.log(selectedObject.zzz); the 88 value? The property is lost somehow but I don't know why.

Thank you

Answer:1

I want to delete * characters if it is present in a string. This is my code but it's not working. String.replace(/*/g '')

I want to delete * characters if it is present in a string. This is my code but it's not working. String.replace(/*/g '')

  1. replace characters string python
  2. replace characters string javascript
  3. replace characters string c#
  4. replace characters string java
  5. replace characters string matlab
  6. replace characters string powershell
  7. replace characters string vba
  8. replace characters string array java
  9. replace string characters
  10. replace string characters in r
  11. replace string characters php
  12. replace string characters swift
  13. replace string characters in stata
  14. replace string characters ruby
  15. replace string characters sed
  16. replace characters in string bash
  17. replace characters in string sql
  18. replace characters in string js
  19. replace characters in string online
  20. replace all characters string javascript

I want to prevent input focus onclick and focus inputs on double click. Something like.... $('input').click(function) { $(this)preventFocus(); }); $('input').dblclick(function) { $(this)...

I want to prevent input focus onclick and focus inputs on double click. Something like.... $('input').click(function) { $(this)preventFocus(); }); $('input').dblclick(function) { $(this)...

  1. input focus double click

I have an animation when my checkboxes are checked, but I want to reverse the animation when they are unchecked. I tried the pseudo class :unchecked, which I found did not work. Is there a CSS3 ...

I have an animation when my checkboxes are checked, but I want to reverse the animation when they are unchecked. I tried the pseudo class :unchecked, which I found did not work. Is there a CSS3 ...

  1. uncheck checkbox css

To keep it simple, sat at my desk wondering if there is a difference in efficiency between (in JavaScript): var i = 0; for(i=0; i<Something.length; i++) foo(); for(i=0; i<Something.length; i++...

To keep it simple, sat at my desk wondering if there is a difference in efficiency between (in JavaScript): var i = 0; for(i=0; i<Something.length; i++) foo(); for(i=0; i<Something.length; i++...

  1. what more efficient ac or dc
  2. what's more efficient than led
  3. what more efficient
  4. which is more efficient in converting biomass
  5. which is more efficient recursion or iteration
  6. which is more efficient otto or diesel