How to use Studio History - Studio182/Studio-History GitHub Wiki

In this entry we will teach you how to use Studio History.

The basics

Init Studio History

To initialize Studio History you need to create a new StudioHistory() object. To do this, use something like this

var history = new StudioHistory();

Setting a History Item

Studio History is just a revisions manager. Because of this the script must tell StudioHistory when and what it wants to set as a history item. To do this, use this

history.setHistoryItem(valueOfNewHistoryItem);

Undoing

Studio History has a built in undo and redo manager. The undo function will return a string with the history item how it was one revision back. If there is nothing left to undo this function will return false.

var undoText = history.getUndoItem();

Redoing

Redoing works similar to undo, only it will move you one revision forward. If there is nothing left to redo this function will return false

var redoText = history.getRedoItem();

Importing / Exporting History

Studio History gives the added ability to Import and Export revision data. This can be useful if you want to let the end user restore their history session after they have closed the browser window. The import/export data is in JSON.

Exporting

Exporting data is pretty straight forward.

var exportedData = history.exportData();

Importing

Importing is just as easy.

history.importData(data);

Notes


Note: When importing data, to make sure the end user has the most user friendly interface its a good idea to set the information the user is manipulating to the last known StudioHistory revision. If you don't... StudioHistory may have unintended results.

To get the last known revision data you can access it at the object variable

history.history_val

Need more help? Contact Hunter Dolan (@hunterhdolan) – GMT +6 or Pablo Merino (@zad0xsis) – GMT -1