Skip to content

Commit

Permalink
Enable passing through mathquill configuration (#38)
Browse files Browse the repository at this point in the history
* Added in mathquill config option

* Added in support for user-defined handlers

* Fixed code formatting and added rule to eslint for object spreading

* Changed chromedriver version
  • Loading branch information
boomanaiden154 committed Feb 27, 2020
1 parent de48508 commit 573636f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module.exports = {
parserOptions: {
ecmaVersion: 6
ecmaVersion: 2018
},
rules: {
"no-var": "error"
Expand Down
29 changes: 18 additions & 11 deletions mathquill4quill.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ window.mathquill4quill = function(dependencies) {

function newMathquillInput() {
const autofocus = options.autofocus == null ? true : options.autofocus;
const mathQuillConfig =
options.mathQuillConfig != null ? options.mathQuillConfig : {};
const cacheKey = options.cacheKey || "__mathquill4quill_cache__";
let mqInput = null;
let mqField = null;
Expand All @@ -98,18 +100,23 @@ window.mathquill4quill = function(dependencies) {
}

function syncMathquillToQuill(latexInput, saveButton) {
const mqField = MathQuill.getInterface(2).MathField(mqInput, {
handlers: {
edit() {
const latex = mqField.latex();
latexInput.value = latex;
setCacheItem(cacheKey, latex);
},
enter() {
saveButton.click();
}
const handlers =
mathQuillConfig.handlers == null ? {} : mathQuillConfig.handlers;
mathQuillConfig.handlers = {
...handlers,
edit() {
const latex = mqField.latex();
latexInput.value = latex;
setCacheItem(cacheKey, latex);
},
enter() {
saveButton.click();
}
});
};
const mqField = MathQuill.getInterface(2).MathField(
mqInput,
mathQuillConfig
);

const cachedLatex = getCacheItem(cacheKey);
if (cachedLatex) {
Expand Down

0 comments on commit 573636f

Please sign in to comment.