Issue #1211Opened June 17, 2018by ivanezeigbo2 reactions

Adding a working Import Panel Button without the presets

Question

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?

Answers (2)

ivanezeigboJune 17, 20182 reactions

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'
							            }
							        }
							    ]
							);
lock[bot]September 17, 20190 reactions

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.

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.