JavaScript How to create Undo-Redo in kineticjs? undo change redo

Is there any simple way how to create undo redo function in Kineticjs ? I have found a Undo Manager for HTML 5 in https://github.com/ArthurClemens/Javascript-Undo-Manager, but I don't know how to put in Kineticjs, please help me. thank you.

Answer:1

I was able to implement a simple solution based on a post by Chtiwi Malek at CodiCode. I also used some of the code from this problem as an example to draw rectangles, so credits go to them and Chtiwi.

The only difference in my solution is I used toJSON() to store each layer state in an array instead of toDataURL() on the canvas. I think toJSON() is needed over toDataURL() to be able to serialize all the data necessary to store each action on the canvas, but I'm not 100% on this so if someone else knows please leave a comment.

function makeHistory() {
    historyStep++;
    if (historyStep < history.length) {
        history.length = historyStep;
    }
    json = layer.toJSON();
    history.push(json);
}

Call this function everytime you want to save a step to undo or redo. In my case, I call this function on every mouseup event.

Bind these 2 functions to the Undo/Redo events.

function undoHistory() {
    if (historyStep > 0) {
        historyStep--;
        layer.destroy();
        layer = Kinetic.Node.create(history[historyStep], 'container')
        stage.add(layer);
    }
}

function redoHistory() {
    if (historyStep < history.length-1) {
        historyStep++;
        layer.destroy();
        layer = Kinetic.Node.create(history[historyStep], 'container')
        stage.add(layer);
    }
}

Here's the jsfiddle. Don't forget to initialize the array and step counter up top. Good luck!

Answer:2

I am not familiar with KineticJS, but the approach should be similar to the provided demo (that also uses a canvas).

Perhaps another example helps. Let's say I have an app to create/move/delete colored shapes that represent musical notes. I have a way to click-drag and highlight a selection of notes. Pressing Delete on the keyboard invokes the function onDeleteGroup:

onDeleteGroup: function(gridModel) {
    // collect all notes in an array
    // ...
    this._deleteGroup(notes);
    this.undoManager.register(
        this, this._createGroup, [notes], 'Undo delete',
        this, this._deleteGroup, [notes], 'Redo delete'
    );
}

All notes are deleted, and 2 methods are registered with the undo manager:

  1. The undo function (undo of delete will be create)
  2. The redo function (after undo/create will be delete again)

Both functions are straightforward:

_deleteGroup:function(notes) {
    // removes each note from the model
    // thereby removing them from the canvas
    // ...
}

_createGroup:function(notes) {
    // add each note to the model
    // thereby adding them to the canvas
    // ...
}

As you can see, the data object (array of notes) is passed around for creation and deleting. You can do the same for manipulating singular objects.

Answer:3

i have written a class for the functionality: http://www.sebastianviereck.de/en/redo-undo-class-kinetic-js/

Answer:4

I'm attempting to create a custom popup while using the angular-leaflet-directive. I'm opening the popup from the leaflet.draw on:create event. Here: map.on('draw:created', function(e) { layer =...

I'm attempting to create a custom popup while using the angular-leaflet-directive. I'm opening the popup from the leaflet.draw on:create event. Here: map.on('draw:created', function(e) { layer =...

  1. angular-leaflet-directive
  2. angular-leaflet-directive.min.js
  3. angular-leaflet-directive npm
  4. angular leaflet directive examples
  5. angular-leaflet-directive.min.js cdn
  6. angular-leaflet-directive search
  7. angular-leaflet-directive.min.js download
  8. angular-leaflet-directive markercluster
  9. angular-leaflet-directive custom controls
  10. angular-leaflet-directive multiple maps
  11. angular-leaflet-directive.js download
  12. angular-leaflet-directive _dev_ mapped.js
  13. angular-leaflet-directive marker icon
  14. angular-leaflet-directive multiple geojson
  15. angular-leaflet-directive install
  16. angular-leaflet-directive filter markers
  17. angular-leaflet-directive draw
  18. angular-leaflet-directive popup width
  19. angular-leaflet-directive latest version
  20. angular-leaflet-directive resize

I'm from a C# Class(), fields, properties, namespace...world. And I just launched myself into javascript. So far I've been doing great. However one of my friends was looking at my code and asked me ...

I'm from a C# Class(), fields, properties, namespace...world. And I just launched myself into javascript. So far I've been doing great. However one of my friends was looking at my code and asked me ...

  1. what global variable is
  2. what is global variable in c
  3. what is global variable in java
  4. what is global variable in python
  5. what is global variable in php
  6. what is global variable in javascript
  7. what is global variable in c with example
  8. what is global variable in oracle
  9. what is global variable in matlab
  10. what is global variable in postman
  11. what is global variable with example
  12. what is global variable in sql
  13. what is global variable in talend
  14. what is global variable in salesforce
  15. what is global variable in sql server
  16. what is global variable in vba
  17. what is global variable in pl sql
  18. what is global variable in java with example
  19. what is global variable in solidworks
  20. what is global variable in js

Here is html code <div style="float: left; padding-top: 8px; width: 340px; overflow: hidden;" id="about_me_text_contents"> <b><span class="notranslate">Name</span></...

Here is html code <div style="float: left; padding-top: 8px; width: 340px; overflow: hidden;" id="about_me_text_contents"> <b><span class="notranslate">Name</span></...

  1. change value from negative to positive in excel
  2. change value from row to column in excel
  3. change value from another component angular
  4. change value from array javascript
  5. change value from dictionary python
  6. change value from table sql
  7. change value from list c#
  8. change value from another script unity
  9. change value from input jquery
  10. change value from dictionary c#
  11. change value from map java
  12. change value from input javascript
  13. change value from css
  14. change value from js
  15. change value from jquery
  16. change value from input
  17. change value from dataframe
  18. change value from dropdown jquery
  19. change value from column sql
  20. change value from sql

I have 100,000 records in a mongoDB collection and trying to retrieve them in a node.js application using the native driver. I follow the example in MongoDB doc for CursorStream but get the error: ...

I have 100,000 records in a mongoDB collection and trying to retrieve them in a node.js application using the native driver. I follow the example in MongoDB doc for CursorStream but get the error: ...

  1. streaming query results
  2. mysql stream query results