GetmeUK / ContentTools

A JS library for building WYSIWYG editors for HTML content.
http://getcontenttools.com
MIT License
3.95k stars 395 forks source link

Manually trigger start and save #553

Closed chud37 closed 4 years ago

chud37 commented 4 years ago

Hello,

I've modified the content tools to have a static toolbar and moved the edit / save / cancel buttons into the same row as the toolbar.

Really, what i'd like to do, is on page load have the editor ready to go straight away. I've read another thread here which seems to indicate that running:

editor._ignition.trigger("start")

will start the editor, howeer the _ignition function cannot be found now and the date of that post is rather old. Looking through the code I found I could do this:

editor.start();

Which works, but leaves the edit button still showing and when you click the edit button, the save / cancel buttons both appear only to hide again.

How can I correctly manually trigger the start event, and the save event?

cyclaero commented 4 years ago

I call editor.ignition().edit(); as the final step once everything else has been instantiated on page load. I found this by looking into the code and by trial and error, and I do not know if this is the recommended way.

This method comes with one minor annoyance. When saving the page the first time, it loads again as if it was never loaded and enters again into editing mode, and this might trigger issue #510.

chud37 commented 4 years ago

Thanks, I'll close this, but it would have been nice to have an official answer, as a lot of other people have asked this question and I've not seen any response from the dev.

anthonyjb commented 4 years ago

@chud37 @cyclaero I've reopened this as I would like to look into (will do so this weekend). I have a number of other small fixes/updates that people have kindly sent me (including #510 and a few additional language files) so I'll look to do a patch release with a recommendation for this question.

chud37 commented 4 years ago

@andyjbgm Thank you!

anthonyjb commented 4 years ago

@chud37 New release out, 1.6.11. With this version my recommendation would be either as per @cyclaero suggested:

editor.ignition().edit()

or

editor.start()
editor.ignition().state('editing')

Personally I'd use the second one just because it seems a little clearer that I'm starting the editor then setting the state of the ignition buttons (but it's longer so just a preference).

@cyclaero thank you again for your help with #510.

cyclaero commented 4 years ago

Hello @anthonyjb, thank you very much for the fixes. I just updated my https://github.com/cyclaero/ContentCGI for it uses the current release 1.6.11 of the ContentTools. I also switched the command for starting the editor to your recommendation:

editor.start();
editor.ignition().state('editing');

Like I told already in the past, I am not 100 % JavaScript save, and I like to stay on the narrow road which was build by the real masters.

As a side note, perhaps you remember us discussing #535. This is really working very well for me, and for this reason I like to suggest this tiny change which resolves a big issue for including it into one of your next releases.

Best regards

Rolf

anthonyjb commented 4 years ago

Hey @cyclaero closing this issue now, I've also included your code from #535 in the latest release which I'll push this weekend.