
Summary: Added stacked delimiter support for more delimiters. Split out delimiter functions into its own file, and split out some tree building functions into a common file. Supports the empty `.` delimiter with \left and \right, and doesn't try to produce huge /, \backslash, <, or > delimiters. Depends on D7844 Test input: \left( \left) \left[ \left\lbrack \left] \left\rbrack \left\{ \left\lbrace \left\} \left\rbrace \left\lfloor \left\rfloor \left\lceil \left\rceil \left\langle \left\rangle \left/ \left\backslash \left| \left\vert \left\| \left\Vert \left\uparrow \left\Uparrow \left\downarrow \left\Downarrow \left\updownarrow \left\Updownarrow {x^{x^{x^{x^{x^{x^{x^{x^{x^{x^x}}}}}}}}}} \right.\right.\right.\right.\right.\right.\right.\right.\right.\right. \right.\right.\right.\right.\right.\right.\right.\right.\right.\right. \right.\right.\right.\right.\right.\right.\right.\right. Test Plan: - Run the test input, see that it works - Run the tests, see that they work - Look at huxley screenshots (not here yet :( ) and make sure they look good Reviewers: alpert Reviewed By: alpert Differential Revision: http://phabricator.khanacademy.org/D11602
72 lines
1.9 KiB
JavaScript
72 lines
1.9 KiB
JavaScript
// These objects store the data about the DOM nodes we create, as well as some
|
|
// extra data. They can then be transformed into real DOM nodes with the toDOM
|
|
// function. They are useful for both storing extra properties on the nodes, as
|
|
// well as providing a way to easily work with the DOM.
|
|
|
|
function span(classes, children, height, depth, maxFontSize, style) {
|
|
this.classes = classes || [];
|
|
this.children = children || [];
|
|
this.height = height || 0;
|
|
this.depth = depth || 0;
|
|
this.maxFontSize = maxFontSize || 0;
|
|
this.style = style || {};
|
|
}
|
|
|
|
span.prototype.toDOM = function() {
|
|
var span = document.createElement("span");
|
|
|
|
var classes = this.classes.slice();
|
|
for (var i = classes.length - 1; i >= 0; i--) {
|
|
if (!classes[i]) {
|
|
classes.splice(i, 1);
|
|
}
|
|
}
|
|
|
|
span.className = classes.join(" ");
|
|
|
|
for (var style in this.style) {
|
|
if (this.style.hasOwnProperty(style)) {
|
|
span.style[style] = this.style[style];
|
|
}
|
|
}
|
|
|
|
for (var i = 0; i < this.children.length; i++) {
|
|
span.appendChild(this.children[i].toDOM());
|
|
}
|
|
|
|
return span;
|
|
};
|
|
|
|
function documentFragment(children, height, depth, maxFontSize) {
|
|
this.children = children || [];
|
|
this.height = height || 0;
|
|
this.depth = depth || 0;
|
|
this.maxFontSize = maxFontSize || 0;
|
|
}
|
|
|
|
documentFragment.prototype.toDOM = function() {
|
|
var frag = document.createDocumentFragment();
|
|
|
|
for (var i = 0; i < this.children.length; i++) {
|
|
frag.appendChild(this.children[i].toDOM());
|
|
}
|
|
|
|
return frag;
|
|
};
|
|
|
|
function textNode(value, height, depth) {
|
|
this.value = value || "";
|
|
this.height = height || 0;
|
|
this.depth = depth || 0;
|
|
}
|
|
|
|
textNode.prototype.toDOM = function() {
|
|
return document.createTextNode(this.value);
|
|
};
|
|
|
|
module.exports = {
|
|
span: span,
|
|
documentFragment: documentFragment,
|
|
textNode: textNode
|
|
};
|