2018-03-05 03:21:11 +08:00
|
|
|
function Api() {
|
2018-02-15 12:31:20 +08:00
|
|
|
const $pluginButtons = $("#plugin-buttons");
|
2018-02-03 23:37:57 +08:00
|
|
|
|
|
|
|
async function activateNote(notePath) {
|
|
|
|
await noteTree.activateNode(notePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
function addButtonToToolbar(buttonId, button) {
|
|
|
|
$("#" + buttonId).remove();
|
|
|
|
|
|
|
|
button.attr('id', buttonId);
|
|
|
|
|
2018-02-15 12:31:20 +08:00
|
|
|
$pluginButtons.append(button);
|
2018-02-03 23:37:57 +08:00
|
|
|
}
|
|
|
|
|
2018-03-05 10:43:14 +08:00
|
|
|
function prepareParams(params) {
|
|
|
|
if (!params) {
|
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
|
|
|
return params.map(p => {
|
|
|
|
if (typeof p === "function") {
|
|
|
|
return "!@#Function: " + p.toString();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function runOnServer(script, params) {
|
|
|
|
if (typeof script === "function") {
|
|
|
|
script = script.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
const ret = await server.post('script/exec', { script: script, params: prepareParams(params) });
|
|
|
|
|
|
|
|
return ret.executionResult;
|
|
|
|
}
|
|
|
|
|
2018-02-03 23:37:57 +08:00
|
|
|
return {
|
2018-03-05 03:21:11 +08:00
|
|
|
__modules: {},
|
|
|
|
__notes: {},
|
2018-02-03 23:37:57 +08:00
|
|
|
addButtonToToolbar,
|
2018-02-25 10:23:04 +08:00
|
|
|
activateNote,
|
2018-03-05 10:43:14 +08:00
|
|
|
getInstanceName: noteTree.getInstanceName,
|
|
|
|
runOnServer
|
2018-02-03 23:37:57 +08:00
|
|
|
}
|
2018-03-05 03:21:11 +08:00
|
|
|
}
|