Created
November 18, 2015 05:02
-
-
Save laughinghan/4d2ba82d4d49b1833929 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/commands/math.js b/src/commands/math.js | |
index 197507c..50a768b 100644 | |
--- a/src/commands/math.js | |
+++ b/src/commands/math.js | |
@@ -431,11 +431,10 @@ var MathBlock = P(MathElement, function(_, super_) { | |
API.StaticMath = function(APIClasses) { | |
return P(APIClasses.AbstractMathQuill, function(_, super_) { | |
this.RootBlock = MathBlock; | |
+ this.rootClassNames = 'mq-math-mode'; | |
_.__mathquillify = function() { | |
- super_.__mathquillify.call(this, 'mq-math-mode'); | |
this.__controller.delegateMouseEvents(); | |
this.__controller.staticMathTextareaEvents(); | |
- return this; | |
}; | |
_.latex = function() { | |
var returned = super_.latex.apply(this, arguments); | |
@@ -458,9 +457,6 @@ var RootMathBlock = P(MathBlock, RootBlockMixin); | |
API.MathField = function(APIClasses) { | |
return P(APIClasses.EditableField, function(_, super_) { | |
this.RootBlock = RootMathBlock; | |
- _.__mathquillify = function(opts) { | |
- this.config(opts); | |
- return super_.__mathquillify.call(this, 'mq-editable-field mq-math-mode'); | |
- }; | |
+ this.rootClassNames = 'mq-editable-field mq-math-mode'; | |
}); | |
}; | |
diff --git a/src/commands/text.js b/src/commands/text.js | |
index e30b2f2..17d66ba 100644 | |
--- a/src/commands/text.js | |
+++ b/src/commands/text.js | |
@@ -365,9 +365,7 @@ var RootTextBlock = P(RootMathBlock, function(_, super_) { | |
API.TextField = function(APIClasses) { | |
return P(APIClasses.EditableField, function(_, super_) { | |
this.RootBlock = RootTextBlock; | |
- _.__mathquillify = function() { | |
- return super_.__mathquillify.call(this, 'mq-editable-field mq-text-mode'); | |
- }; | |
+ this.rootClassNames = 'mq-editable-field mq-text-mode'; | |
_.latex = function(latex) { | |
if (arguments.length > 0) { | |
this.__controller.renderLatexText(latex); | |
diff --git a/src/css/math.less b/src/css/math.less | |
index 954d27c..9388bfe 100644 | |
--- a/src/css/math.less | |
+++ b/src/css/math.less | |
@@ -267,6 +267,7 @@ | |
margin-top: 1px; | |
padding-left: .15em; | |
padding-right: .2em; | |
+ padding-top: 1px; | |
margin-right: .1em; | |
padding-top: 1px; | |
} | |
diff --git a/src/publicapi.js b/src/publicapi.js | |
index 3ec41d0..472073c 100644 | |
--- a/src/publicapi.js | |
+++ b/src/publicapi.js | |
@@ -5,7 +5,7 @@ | |
var API = {}, Options = P(), optionProcessors = {}; | |
function config(currentOptions, newOptions, v) { | |
for (var name in newOptions) if (newOptions.hasOwnProperty(name)) { | |
- var value = newOption[name], processor = optionProcessors[name]; | |
+ var value = newOptions[name], processor = optionProcessors[name]; | |
currentOptions[name] = (processor ? processor(value, v) : value); | |
} | |
} | |
@@ -69,21 +69,6 @@ var AbstractMathQuill = APIClasses.AbstractMathQuill = P(function(_) { | |
this.id = ctrlr.id; | |
this.data = ctrlr.data; | |
}; | |
- _.__mathquillify = function(classNames) { | |
- var ctrlr = this.__controller, root = ctrlr.root, el = ctrlr.container; | |
- ctrlr.createTextarea(); | |
- | |
- var contents = el.addClass(classNames).contents().detach(); | |
- root.jQ = | |
- $('<span class="mq-root-block"/>').attr(mqBlockId, root.id).appendTo(el); | |
- this.latex(contents.text()); | |
- | |
- this.revert = function() { | |
- return el.empty().unbind('.mathquill') | |
- .removeClass('mq-editable-field mq-math-mode mq-text-mode') | |
- .append(contents); | |
- }; | |
- }; | |
_.config = function(opts) { | |
var self = this; | |
config(self.__options, opts, v); | |
@@ -122,11 +107,9 @@ MQ.prototype = AbstractMathQuill.prototype; | |
APIClasses.EditableField = P(AbstractMathQuill, function(_, super_) { | |
_.__mathquillify = function() { | |
- super_.__mathquillify.apply(this, arguments); | |
this.__controller.editable = true; | |
this.__controller.delegateMouseEvents(); | |
this.__controller.editablesTextareaEvents(); | |
- return this; | |
}; | |
_.focus = function() { this.__controller.textarea.focus(); return this; }; | |
_.blur = function() { this.__controller.textarea.blur(); return this; }; | |
@@ -195,9 +178,28 @@ for (var kind in API) (function(kind, defAPIClass) { | |
var APIFn = MQ[kind] = function(el, opts) { | |
var mq = MQ(el); | |
if (mq instanceof APIClass || !el || !el.nodeType) return mq; | |
- var ctrlr = Controller(APIClass.RootBlock(), $(el), Options()); | |
+ | |
+ var root = APIClass.RootBlock(); | |
+ el = $(el).addClass(APIClass.rootClassNames); | |
+ | |
+ var ctrlr = Controller(root, el, Options()); | |
ctrlr.KIND_OF_MQ = kind; | |
- return APIClass(ctrlr).__mathquillify(opts); | |
+ ctrlr.createTextarea(); | |
+ | |
+ var contents = el.contents().detach(); | |
+ root.jQ = | |
+ $('<span class="mq-root-block"/>').attr(mqBlockId, root.id).appendTo(el); | |
+ | |
+ mq = APIClass(ctrlr).config(opts).latex(contents.text()); | |
+ | |
+ mq.revert = function() { | |
+ return el.empty().unbind('.mathquill') | |
+ .removeClass('mq-editable-field mq-math-mode mq-text-mode') | |
+ .append(contents); | |
+ }; | |
+ | |
+ mq.__mathquillify(); | |
+ return mq; | |
}; | |
APIFn.prototype = APIClass.prototype; | |
}(kind, API[kind])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment