node-red-contrib-context-editor
Version:
Context Editor
66 lines (59 loc) • 1.82 kB
HTML
<style>
.toolbar-button {
border: none;
color: #eee;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: auto 0 auto 12pt;
padding: 3.5pt;
}
.context-editor-button {
background-color: #5a662f ;;
}
</style>
<script type="text/javascript">
(function initContextEditor() {
function openContextEditor() {
try {
try {
const activeWorkspace = RED.workspaces.active();
const parentNode = RED.nodes.workspace(activeWorkspace);
const isAflowAndNotSubflow = parentNode != null;
if(!isAflowAndNotSubflow) {
throw 'Cannot edit flow context for subflows';
}
window.open('context-editor/static/editor.html#'+parentNode.id, '_blank')
} catch(e) {
alert(e);
}
} catch(e) {
alert(e);
}
}
const _nr1Header = $('ul.red-ui-header-toolbar');
if(_nr1Header.length) {
_nr1Header.prepend(`
<li>
<button class="button-group red-ui-deploy-button toolbar-button context-editor-button" href="#">
<i class="fa fa-database" /> Context Editor</button>
</button>
</li>
`);
} else {
// Add "context editor" button
$('.header-toolbar').prepend(`
<span>
<span>
<button class="toolbar-button context-editor-button"><i class="fa fa-database" /> Context Editor</button>
</span>
</span>
`);
}
const button = document.querySelector('.toolbar-button.context-editor-button');
button.addEventListener('click', function() {
openContextEditor();
});
})();
</script>