work on sandbox
This commit is contained in:
parent
722ddf1638
commit
083999212e
@ -96,25 +96,25 @@ async function apiNoteView(noteId) {
|
||||
return utilBackend().anki.guiBrowse(`nid:${noteId}`);
|
||||
}
|
||||
|
||||
async function apiTemplateRender(template, data) {
|
||||
return handlebarsRender(template, data);
|
||||
}
|
||||
async function apiTemplateRender(template, data, dynamic) {
|
||||
if (dynamic) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const sequence = utilBackend().sequenceNew();
|
||||
const handler = event => {
|
||||
if (event.data.sequence === sequence) {
|
||||
resolve(event.data.result);
|
||||
window.removeEventListener('message', handler);
|
||||
}
|
||||
};
|
||||
|
||||
async function apiTemplateRenderDynamic(template, data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const sequence = utilBackend().sequenceNew();
|
||||
const handler = event => {
|
||||
if (event.data.sequence === sequence) {
|
||||
resolve(event.data.result);
|
||||
window.removeEventListener('message', handler);
|
||||
}
|
||||
};
|
||||
window.addEventListener('message', handler);
|
||||
|
||||
window.addEventListener('message', handler);
|
||||
|
||||
const sandbox = utilBackend().sandbox();
|
||||
sandbox.postMessage({template, data, sequence, command: 'render'}, '*');
|
||||
});
|
||||
const sandbox = utilBackend().sandbox();
|
||||
sandbox.postMessage({template, data, sequence, command: 'render'}, '*');
|
||||
});
|
||||
} else {
|
||||
return handlebarsRender(template, data);
|
||||
}
|
||||
}
|
||||
|
||||
async function apiCommandExec(command) {
|
||||
|
@ -113,8 +113,8 @@ class Backend {
|
||||
forward(apiNoteView(noteId), callback);
|
||||
},
|
||||
|
||||
templateRender: ({template, data, callback}) => {
|
||||
forward(apiTemplateRender(template, data), callback);
|
||||
templateRender: ({template, data, dynamic, callback}) => {
|
||||
forward(apiTemplateRender(template, data, dynamic), callback);
|
||||
},
|
||||
|
||||
commandExec: ({command, callback}) => {
|
||||
|
@ -45,8 +45,8 @@ function apiNoteView(noteId) {
|
||||
return utilInvoke('noteView', {noteId});
|
||||
}
|
||||
|
||||
function apiTemplateRender(template, data) {
|
||||
return utilInvoke('templateRender', {data, template});
|
||||
function apiTemplateRender(template, data, dynamic) {
|
||||
return utilInvoke('templateRender', {data, template, dynamic});
|
||||
}
|
||||
|
||||
function apiCommandExec(command) {
|
||||
|
Loading…
Reference in New Issue
Block a user