Adding a working Import Panel Button without the presets
I want to add the Import button at the panel for importing templates, but I don't want to use the presets. I have already added the following code:
... { id: 'import', className: 'fa fa-download', attributes: {title: 'Import Your Template'}, command: function(editor, sender){ ???? } } ...
I don't know what should be in the command. Please, could you tell me the function to use for command?
Oh, I just figured it out. So, for those who might be curious about how to solve this, this is how I went about it (by the way, this is thanks to the answer in Issue #324 :
var pfx = editor.getConfig().stylePrefix;
var modal = editor.Modal;
var cmdm = editor.Commands;
var codeViewer = editor.CodeManager.getViewer('CodeMirror').clone();
var pnm = editor.Panels;
var container = document.createElement('div');
var btnEdit = document.createElement('button');
codeViewer.set({
codeName: 'htmlmixed',
readOnly: 0,
theme: 'hopscotch',
autoBeautify: true,
autoCloseTags: true,
autoCloseBrackets: true,
lineWrapping: true,
styleActiveLine: true,
smartIndent: true,
indentWithTabs: true
});
btnEdit.innerHTML = 'Import';
btnEdit.className = pfx + 'btn-prim ' + pfx + 'btn-import';
btnEdit.onclick = function() {
var code = codeViewer.editor.getValue();
editor.DomComponents.getWrapper().set('content', '');
editor.setComponents(code.trim());
modal.close();
};
cmdm.add('html-import', {
run: function(editor, sender) {
sender && sender.set('active', 0);
var viewer = codeViewer.editor;
modal.setTitle('Edit code');
if (!viewer) {
var txtarea = document.createElement('textarea');
container.appendChild(txtarea);
container.appendChild(btnEdit);
codeViewer.init(txtarea);
viewer = codeViewer.editor;
}
modal.setContent('');
modal.setContent(container);
codeViewer.setContent('');
modal.open();
viewer.refresh();
}
});
pnm.addButton('options',
[
{
id: 'import',
className: 'fa fa-download',
command: 'html-import',
attributes: {
title: 'Import Your Template'
}
}
]
);
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.