From db7e80dabfbaeec09c7cd30b4f36b3d68c6e52b6 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 4 Mar 2017 19:16:19 -0800 Subject: wip --- ext/bg/js/util.js | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'ext/bg/js/util.js') diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index c57f6ae1..d91415f7 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -23,7 +23,7 @@ function promiseCallback(promise, callback) { return promise.then(result => { - callback({result}); + callback({result}); }).catch(error => { /* eslint-disable */ console.log(error); @@ -50,6 +50,22 @@ function instAnki() { } +/* + * Foreground + */ + +function fgBroadcast(action, params) { + chrome.tabs.query({}, tabs => { + for (const tab of tabs) { + chrome.tabs.sendMessage(tab.id, {action, params}, () => null); + } + }); +} + +function fgOptionsSet(options) { + fgBroadcast('optionsSet', options); +} + /* * Options @@ -188,6 +204,9 @@ function optionsSave(options) { return new Promise((resolve, reject) => { chrome.storage.sync.set(options, resolve); + }).then(() => { + instYomi().optionsSet(options); + fgOptionsSet(options); }); } @@ -468,7 +487,7 @@ function jsonLoadDb(indexUrl, indexLoaded, termsLoaded, kanjiLoaded) { * Helpers */ -function helperKanjiLinks(options) { +function handlebarsKanjiLinks(options) { const isKanji = c => { const code = c.charCodeAt(0); return code >= 0x4e00 && code < 0x9fb0 || code >= 0x3400 && code < 0x4dc0; @@ -486,6 +505,16 @@ function helperKanjiLinks(options) { return result; } -function helperMultiLine(options) { +function handlebarsMultiLine(options) { return options.fn(this).split('\n').join('
'); } + +function handlebarsRegister() { + Handlebars.partials = Handlebars.templates; + Handlebars.registerHelper('kanjiLinks', handlebarsKanjiLinks); + Handlebars.registerHelper('multiLine', handlebarsMultiLine); +} + +function handlebarsRender(template, data) { + return Handlebars.templates[template](data); +} -- cgit v1.2.3