Edit mode right after loading
I need to start editor on the page as soon as it will be loaded. So I've added Editor start method in load event listener:
editor = ContentTools.EditorApp.get();
editor.init('[data-editable], [data-fixture]', 'data-name');
editor.start();
Edit mode is turned on, editor.getState() has been changed from ready to editing, but start editor button one the top-left corner is not changed to save\cancel buttons. And clicking on it just hides it and displays save\cancel buttons which work as expected then.
Hi @a-komarev,
From your description it sounds like the problem your trying to solve is that the ignition (edit buttons top-left) isn't changing state to reflect the state of the editor when you manually start the editor. This is because the ignition is set up to drive the state of the editor not the other way around, so you will need to either trigger an start with the ignition or manually change the state of the editor, for example:
editor = ContentTools.EditorApp.get()
// Option 1 -Trigger start with the ignition
editor.ignition().start();
// Option 2 -Manually change the state of the editor and ignition
editor.start();
editor.ignition().state('editing');
@anthonyjb is there any reason why ingnition not listening for editor states being changed? And thanks for solution :}
@a-komarev there's no specific reason other than this keeps things loosely-coupled, at the moment the editor binds to the ignition events and reacts to those by starting and stopping/saving but the ignition switch itself knows nothing about the editor. Does that help?
Yes, thank you. It will be good to write about it in documentation if it's not illuminated there.
@anthonyjb Is there a way to disable the ignition UI ?
@afzaalace Do you want it to appear disabled or to be hidden?
@anthonyjb I am looking for the API to "destroy" it. Ideally to not generate it in the first place.
OK to not generate it in the first place you need to modify the EditorApp class and remove the ignition, it's not difficult to do this but might be a step further than you want to go.
The simplest option is to hide it with CSS, e.g .ct-ignition { display: none !important; }, feels a little hacky but it wont do any harm if hidden.
A number of people have asked about hiding/removing the ignition switch now so I think I'll post an enhancement request for this feature, just a flag you can set against the EditorApp class before/when you initialize it.
@anthonyjb Thanks. I am totally comfortable with that. Was just wondering if there was a flag or API to do so.
@afzaalace cool :+1: I think a flag is the way to go, even on our own projects we quite often modify the ignition or hide it to integrate more consistently with another tool.
@a-komarev, @afzaalace you can now initialize the EditorApp class without the ignition component using the withIgnition flag, e.g:
var editor = ContentTools.EditorApp.get();
editor.init('[data-editable], [data-fixture]', 'data-name', null, withIgnition=false);
editor.ignition().state('editing'); is useless if withIgnition=false, isn't it?
var FIXTURE_TOOLS, editor;
var withIgnition = false;
editor = ContentTools.EditorApp.get();
editor.init('[data-editable], [data-fixture]', 'data-name', null, withIgnition);
editor.start();
editor.ignition().state('editing');
Output:
Uncaught TypeError: Cannot read property 'state' of null
@a-komarev if you don't create the ignition component then the ignition() method will return null. Without the ignition component you must start/stop the editor manually.
Note: Made some edits to code snippets.
I found this issue trying to resolve an exception that was being thrown by Content Tools History. I'm not using the ignition, so we had removed it. This exception started at some point:
content-tools.min.js:6 Uncaught TypeError: Cannot read property 'stopWatching' of null at c.stop (content-tools.min.js:6) at Vue$3.stop_editing (field_config_editor.js:212) at Vue$3.boundFn [as stop_editing] (vue.js:171) at HTMLDocument.
(field_config_editor.js:27) at HTMLDocument.dispatch (jquery-2.2.4.min.js:3) at HTMLDocument.r.handle (jquery-2.2.4.min.js:3)
This is because editor.history is also null. When I looked into it, I notice that the History is initialized as part of the Ignition call. So, I ended up with this and the exception went away; let me know if this is what I should be doing or not:
function init_content_editor() {
var FIXTURE_TOOLS, req, editor;
window.editor = editor = ContentTools.EditorApp.get();
// Because we aren't initilizing with Ignition(), we need to start
// the history manually, otherwise it throws an exception later
// because this.history.stopWatching() is null, which means the
// this.history reference is null too.
editor.history = new ContentTools.History(window.editor._regions);
// The fourth argument means don't include the Ignition() component
editor.init('[data-editable], [data-fixture]', 'data-name', null, false);
editor.addEventListener('saved', function (ev) {
...
Then, elsewhere (it's a Vue.js app too), we have:
start_editing: function() {
if (window.editor.isReady()) {
$('.blocklet')
.draggable({disabled: true,})
//.resizable({disabled: true,})
;
window.editor.start();
return true;
}
return false;
},
stop_editing: function() {
$('.blocklet')
.draggable({disabled: false,})
//.resizable({disabled: false,})
;
window.editor.stop(true);
},
Nevermind, turns out I had states of the editable block being selected and THEN editable, and I wasn't adding the History object at the right time (which it was selected). Ignore the previous comment (which I deleted).