diff options
author | Alex Yatskov <alex@foosoft.net> | 2017-09-05 21:10:19 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2017-09-05 21:10:19 -0700 |
commit | 083999212e262c0a51b9401cb9666e6a49e35de9 (patch) | |
tree | 1af13ab06bea933038cfd1f17f15ae6c273a52ab /ext/bg/js/api.js | |
parent | 722ddf163818035d603ba8042e1e32ff7dcdfc84 (diff) |
work on sandbox
Diffstat (limited to 'ext/bg/js/api.js')
-rw-r--r-- | ext/bg/js/api.js | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js index aba1b722..0aad436a 100644 --- a/ext/bg/js/api.js +++ b/ext/bg/js/api.js @@ -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 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); - - const sandbox = utilBackend().sandbox(); - sandbox.postMessage({template, data, sequence, command: 'render'}, '*'); - }); +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); + } + }; + + window.addEventListener('message', handler); + + const sandbox = utilBackend().sandbox(); + sandbox.postMessage({template, data, sequence, command: 'render'}, '*'); + }); + } else { + return handlebarsRender(template, data); + } } async function apiCommandExec(command) { |