Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable localStorage persistence #141

Closed
levint opened this issue Jul 3, 2012 · 12 comments
Closed

Disable localStorage persistence #141

levint opened this issue Jul 3, 2012 · 12 comments
Milestone

Comments

@levint
Copy link

levint commented Jul 3, 2012

How to disable localStorage support? .. I only persist the markdown into a server-side database

@OscarGodson
Copy link
Owner

Why do you need to disable it? localStorage is in there so itll work offline or if saving to the DB fails. You could set autoSave to false tho if you wanted. I'm curious why you need to disable it tho so I can handle your use case.

@levint
Copy link
Author

levint commented Jul 3, 2012

It is because my app does and will not require it. I tried to set autoSave to false but I encounter the following problem:

-> http://jsbin.com/etudol/edit#javascript,html will not work anymore because file.content is empty

@levint
Copy link
Author

levint commented Jul 3, 2012

On a side note, regarding the jsbin code in the above comment, Is it possible to get the contents (on editor update) from the contenteditable iframe instead of file.content? ...

@OscarGodson
Copy link
Owner

You'd have to manually get the content out with like:

editor.getElement('editor').body.innerText

Or something.

But if it just that your app doesn't require it, not that it breaks anything, why can't you just ignore it? It should be all behind the scenes.

@levint
Copy link
Author

levint commented Jul 3, 2012

I changed it to
editor.on('update', function () {
textarea.val(editor.getElement('editor').body.innerText);
});

but it still does not work.

The problem also with autoSave not being false is that the file contents is loaded on load. I don't want that behavior.

with autoSave = false, the previewer does not work anymore and the (on update) event does not trigger anymore

@OscarGodson
Copy link
Owner

The update event only fires when a file is updated. If autoSave is off and you never call editor.save() manually it won't fire update, because, well, the file was never updated. This also reminds me that setting autoSave off wont really work actually, sorry. It just stops it from saving automatically, but for things like preview, CRUD events, etc it'll need to be saved and saving requires localStorage currently.

I need to fix #137 which will make it possible to not have localStorage for another reason entirely (because the editor needs to work via file:\\\ and IE9 doesn't allow localStorage over that protocol). Once I implement #137 i'll add an option which you can set false to not save to localStorage.

But, if you don't have any actual breaking problems with localStorage, just don't need it, I suggest just using it for now and ill add that option ASAP.

@levint
Copy link
Author

levint commented Jul 3, 2012

Ok I could live with it for now but how do I configure it in such a way that when everytime the page loads, the content area will be blank. ( I don't want it to be filled with the localStorage data when the page loads). Or, everytime the page loads, clear the localstorage data

P.S. im a backend dev.. not much skills on client side

@OscarGodson
Copy link
Owner

You could just do localStorage.clear() above EpicEditor. Or, you could do editor.importFile(null, '');. But realistically you should importFile your data from your DB and it shouldn't ever have to read from localStorage on load it should directly come from your DB.

OscarGodson added a commit that referenced this issue Jul 4, 2012
… also makes it so EE wont crash when localStorage is undefined (IE7 and also when IE9 is using the file protocol)
@OscarGodson
Copy link
Owner

@levint could you pull develop and let me know if this will work for you now? I added an option clientSideStorage and if you set that to false it shouldn't write OR read anything to localStorage, but all the API calls and events should fire like normal (like update).

I haven't added the docs or tests for it yet so hopefully it doesn't break anything, but if it does let me know! :)

@OscarGodson
Copy link
Owner

Added docs and tests, so closing, but feel free to reopen if you are still having problems.

@levint
Copy link
Author

levint commented Jul 5, 2012

Thank you! It's working great :)

@OscarGodson
Copy link
Owner

@levint Glad to hear it! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants