You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I haven't programmed before, but I tried make a plugin to generate links by selected cells and place the links in the text. I figured out a bit about link generation, but I didn't understand how to get the page id via JS.
Tell me, please:
how can I get the page id by JS (now I manually find out the page id and create a block with the id "id_page" and write the page id into the content and read it by JS, but this is clumsy)?;
how to insert a link into the text by JS?
The plugin code:
Draw.loadPlugin(function (ui) {
mxResources.parse('generate_link=generate link');
var graph = ui.editor.graph;
var cell_id;
var page_id;
ui.actions.addAction('generate_link', function () {
graph.getModel().beginUpdate();
try {
var my_cells = graph.getSelectionCells();
cell_id = my_cells[0].getId();
for (let i = 1; i < my_cells.length; i++) {
cell_id = cell_id + '","' + my_cells[i].getId();
}
page_id = graph.getModel().getCell('id_page').getAttribute('label');
var my_link = 'data:action/json,{"actions":[{"open":"data:page/id,' + page_id + '"},{"select":{"cells":["' + cell_id + '"]}},{"highlight":{"cells":["' + cell_id + '"],"opacity":100,"color":"red"}}]}';
navigator.clipboard.writeText(my_link);
} finally {
graph.getModel().endUpdate();
}
}, null, null, 'F1');
ui.keyHandler.bindAction(112, false, 'generate_link');
ui.menubar.addMenu('My Menu', function(menu, parent) {
ui.menus.addMenuItem(menu, 'generate_link');
});
ui.menubar.container.insertBefore(ui.menubar.container.LastChild, ui.menubar.container.lastChild.previousSibling);
});
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello, I haven't programmed before, but I tried make a plugin to generate links by selected cells and place the links in the text. I figured out a bit about link generation, but I didn't understand how to get the page id via JS.
Tell me, please:
The plugin code:
Beta Was this translation helpful? Give feedback.
All reactions