Skip to content

Commit

Permalink
7.9.0 stable version
Browse files Browse the repository at this point in the history
  • Loading branch information
mcagigas-at-wiris authored Dec 12, 2018
1 parent f01fe8d commit 87b4182
Show file tree
Hide file tree
Showing 17 changed files with 1,657 additions and 1,168 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.8.0.1397
7.9.0.1398
4 changes: 2 additions & 2 deletions core/core.js

Large diffs are not rendered by default.

1,166 changes: 690 additions & 476 deletions core/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"mini-css-extract-plugin": "^0.4.2",
"optimize-css-assets-webpack-plugin": "^5.0.1",
"style-loader": "^0.23.0",
"uglifyjs-webpack-plugin": "^1.2.8",
"url-loader": "^1.1.1",
"webpack": "^4.17.2",
"webpack-cli": "^3.1.0"
Expand Down
4 changes: 2 additions & 2 deletions core/src/contentmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,9 @@ export default class ContentManager {
// We need to set a empty annotation in order to maintain editor in Hand mode.
// Adding dir rtl in case of it's activated.
if (this.editor.getEditorModel().isRTL()) {
this.setMathML('<math dir="rtl"><semantics><annotation encoding="application/json">[]</annotation></semantics></math>"', true);
this.setMathML('<math dir="rtl"><semantics><annotation encoding="application/json">[]</annotation></semantics></math>', true);
} else {
this.setMathML('<math><semantics><annotation encoding="application/json">[]</annotation></semantics></math>"', true);
this.setMathML('<math><semantics><annotation encoding="application/json">[]</annotation></semantics></math>', true);
}
} else {
if (this.editor.getEditorModel().isRTL()) {
Expand Down
9 changes: 5 additions & 4 deletions core/src/latex.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ export default class Latex {
* @return {string} LaTeX string generated by the MathML argument.
*/
static getLatexFromMathML(mathml) {
const mathmlWithoutSemantics = MathML.removeSemantics(mathml);
/**
* @type {TextCache}
*/
let cache = Latex.cache;

var data = {
'service': 'mathml2latex',
'mml': mathml
'mml': mathmlWithoutSemantics
};

var jsonResponse = JSON.parse(ServiceProvider.getService('service', data));
Expand All @@ -35,8 +36,8 @@ export default class Latex {
latex = jsonResponse.result.text;
const latexHtmlEntitiesEncoded = Util.htmlEntities(latex);
// Inserting LaTeX semantics.
mathml = MathML.insertSemanticsMathml(mathml, latexHtmlEntitiesEncoded, 'LaTeX');
cache.populate(latex, mathml);
const mathmlWithSemantics = MathML.addAnnotation(mathml, latexHtmlEntitiesEncoded, 'LaTeX');
cache.populate(latex, mathmlWithSemantics);
}

return latex;
Expand Down Expand Up @@ -76,7 +77,7 @@ export default class Latex {

// Populate LatexCache.
if (mathml.indexOf('semantics') == -1 && mathml.indexOf('annotation') == -1 ) {
mathml = MathML.insertSemanticsMathml(mathml, latex, 'LaTeX');
mathml = MathML.addAnnotation(mathml, latex, 'LaTeX');
output = mathml;

} else {
Expand Down
112 changes: 66 additions & 46 deletions core/src/mathml.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,56 +191,79 @@ export default class MathML {
}

/**
* Add annotation tag to mathml without it (mathml comes from LaTeX string)
* @param {string} mathml - MathML code generated by a LaTeX string.
* @param {string} latex - original LaTeX string
* @param {string} withoutLatexTranslate - true if not exists latex translation from mathml. false otherwise.
* @param {string} encoding - encoding attribute.
* @returns {string} MathML containing LaTeX code on annotation tag.
* Adds annotation tag in MathML element.
* @param {String} mathml - valid MathML.
* @param {String} content - value to put inside annotation tag.
* @param {String} annotationEncoding - annotation encoding.
* @returns {String} - 'mathml' with an annotation that contains 'content' and encoding 'encoding'.
*/
static insertSemanticsMathml(mathml, latex, encoding) {

// If latex is empty, insert semantics doesn't provide information. We can avoid semantics insertion and return the mathml.
if (latex == "") {
return mathml;
static addAnnotation(mathml, content, annotationEncoding) {
// If contains annotation, also contains semantics tag.
const containsAnnotation = mathml.indexOf('<annotation');

let mathmlWithAnnotation = '';
if (containsAnnotation !== -1) {
const closeSemanticsIndex = mathml.indexOf('</semantics>');
mathmlWithAnnotation = mathml.substring(0, closeSemanticsIndex) + `<annotation encoding="${annotationEncoding}">${content}</annotation>` + mathml.substring(closeSemanticsIndex);
}
else if (MathML.isEmpty(mathml)) {
const endIndexInline = mathml.indexOf('/>');
const endIndexNonInline = mathml.indexOf('>');
const endIndex = endIndexNonInline === endIndexInline ? endIndexInline : endIndexNonInline;
mathmlWithAnnotation = mathml.substring(0, endIndex) + `><semantics><annotation encoding="${annotationEncoding}">${content}</annotation></semantics></math>`;
}
else {
const beginMathMLContent = mathml.indexOf('>') + 1;
const endMathmlContent = mathml.lastIndexOf('</math>');
const mathmlContent = mathml.substring(beginMathMLContent, endMathmlContent);
mathmlWithAnnotation = mathml.substring(0, beginMathMLContent) + `<semantics>${mathmlContent}<annotation encoding="${annotationEncoding}">${content}</annotation></semantics></math>`;
}

var firstEndTag = '>';
var mathTagEnd = '<' + '/math' + '>';
var openSemantics = '<' + 'semantics' + '>';
var closeSemantics = '<' + '/semantics' + '>';
var openTarget = '<annotation encoding="' + encoding +'">';
var closeTarget = '<' + '/annotation' + '>';
var mrowOpen = '<mrow>';
var mrowClose = '</mrow>';

var indexMathBegin = mathml.indexOf(firstEndTag);
var indexMathEnd = mathml.indexOf(mathTagEnd);
var mathBeginExists = mathml.substring(mathml.indexOf('<'), mathml.indexOf('>')).indexOf('math');

if (indexMathBegin != -1 && indexMathEnd != -1 && mathBeginExists) {
var mathmlContent = mathml.substring(indexMathBegin + 1, indexMathEnd);
if (mathmlContent.indexOf(mrowOpen) != 0) {
var mathmlContentSemantics = openSemantics + mrowOpen + mathmlContent + mrowClose + openTarget + latex + closeTarget + closeSemantics;
} else {
var mathmlContentSemantics = openSemantics + mathmlContent + openTarget + latex + closeTarget + closeSemantics;
return mathmlWithAnnotation;
}

/**
* Removes specific annotation tag in MathML element. In case of remove the unique annotation, also is removed semantics tag.
* @param {String} mathml - valid MathML.
* @param {String} annotationEncoding - annotation encoding to remove.
* @returns {String} - 'mathml' without the annotation encoding specified.
*/
static removeAnnotation(mathml, annotationEncoding) {
let mathmlWithoutAnnotation = mathml;
const openAnnotationTag = `<annotation encoding="${annotationEncoding}">`;
const closeAnnotationTag = '</annotation>';
const startAnnotationIndex = mathml.indexOf(openAnnotationTag);
if (startAnnotationIndex !== -1) {
let differentAnnotationFound = false;
let differentAnnotationIndex = mathml.indexOf('<annotation');
while(differentAnnotationIndex !== -1) {
if (differentAnnotationIndex !== startAnnotationIndex) {
differentAnnotationFound = true;
}
differentAnnotationIndex = mathml.indexOf('<annotation', differentAnnotationIndex + 1);
}

if (differentAnnotationFound) {
const endAnnotationIndex = mathml.indexOf(closeAnnotationTag, startAnnotationIndex) + closeAnnotationTag.length;
mathmlWithoutAnnotation = mathml.substring(0, startAnnotationIndex) + mathml.substring(endAnnotationIndex);
}
else {
mathmlWithoutAnnotation = MathML.removeSemantics(mathml);
}
return mathml.replace(mathmlContent, mathmlContentSemantics);
} else {
return mathml;
}

return mathmlWithoutAnnotation;
}

/**
* Removes annotation tag to mathml.
* @param {string} mathml - MathML string
* @param {string} encoding - string containing annotation encoding.
* @returns {string} MathML with an annotation tag.
* Removes semantics tag to mathml.
* @param {string} mathml - MathML string.
* @returns {string} - 'mathml' without semantics tag.
*/
static removeSemantics(mathml, encoding) {
var mathTagEnd = '<' + '/math' + '>';
var openSemantics = '<' + 'semantics' + '>';
var openAnnotation = '<annotation encoding="' + encoding + '">';
static removeSemantics(mathml) {
var mathTagEnd = '</math>';
var openSemantics = '<semantics>';
var openAnnotation = '<annotation';

var mathmlWithoutSemantics = mathml;
var startSemantics = mathml.indexOf(openSemantics);
Expand All @@ -258,20 +281,17 @@ export default class MathML {
* Transforms all xml mathml ocurrences that contain semantics to the same
* xml mathml ocurrences without semantics.
* @param {string} text - string that can contain xml mathml ocurrences.
* @param {string} [encoding] - encoding name that semantics need to have to be removed.
* 'application/json' by default. 'application/json' removes hand traces.
* @param {Constants} [characters] - Constant object containing xmlCharacters or safeXmlCharacters relation.
* xmlCharacters by default.
* @returns {string} - 'text' with all xml mathml ocurrences without annotation tag.
*/
static removeSemanticsOcurrences(text, characters = Constants.xmlCharacters, encoding = 'application/json') {
static removeSemanticsOcurrences(text, characters = Constants.xmlCharacters) {
const mathTagStart = characters.tagOpener + 'math';
const mathTagEnd = characters.tagOpener + '/math' + characters.tagCloser;
const mathTagEndline = '/' + characters.tagCloser;
const tagCloser = characters.tagCloser;
const semanticsTagStart = characters.tagOpener + 'semantics' + characters.tagCloser;
const annotationTagStart = characters.tagOpener + 'annotation encoding=' +
characters.doubleQuote + encoding + characters.doubleQuote + characters.tagCloser;
const annotationTagStart = characters.tagOpener + 'annotation encoding=';

let output = '';
let start = text.indexOf(mathTagStart);
Expand Down
56 changes: 39 additions & 17 deletions core/src/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ export default class ModalDialog {
size : {height: 338, width: 580}
};

/**
* Object to keep website's style before change it on lock scroll for mobile devices.
* @type {Object}
* @property {String} bodyStylePosition - previous body style postion.
* @property {String} bodyStyleOverflow - previous body style overflow.
* @property {String} htmlStyleOverflow - previous body style overflow.
* @property {String} windowScrollX - previous window's scroll Y.
* @property {String} windowScrollY - previous window's scroll X.
*/
this.websiteBeforeLockParameters = null;

var attributes = {};
attributes.class = 'wrs_modal_overlay';
attributes.id = this.getElementId(attributes.class);
Expand Down Expand Up @@ -413,7 +424,7 @@ export default class ModalDialog {
if (this.deviceProperties['isIOS'] || this.deviceProperties['isAndroid'] || this.deviceProperties['isMobile']) {
// Restore scale to 1
this.restoreWebsiteScale();
this.blockWebsiteScroll();
this.lockWebsiteScroll();
// Due to editor wait we need to wait until editor focus.
setTimeout(function() { this.hideKeyboard() }.bind(this), 400);
}
Expand Down Expand Up @@ -468,7 +479,7 @@ export default class ModalDialog {
this.removeClass('wrs_stack');
this.addClass('wrs_closed');
this.saveModalProperties();
this.unblockWebsiteScroll();
this.unlockWebsiteScroll();
this.properties.open = false;
}

Expand Down Expand Up @@ -511,8 +522,9 @@ export default class ModalDialog {
for (let i = 0; i < oldAttrs.length; i++) {
finalContentMeta += ',' + oldAttrs[i];
}

viewportelement.setAttribute('content', finalContentMeta);
// It needs to set to empty because setAttribute refresh only when attribute is different.
viewportelement.setAttribute('content', '');
viewportelement.setAttribute('content', contentAttr);
}
else {
Expand All @@ -533,25 +545,32 @@ export default class ModalDialog {
}

/**
* Adds an event to avoid touch scrolling.
* Locks website scroll for mobile devices.
*/
blockWebsiteScroll() {
document.body.addEventListener('touchmove', this.disableTouchMove, {passive: false});
}

/**
* Removes the event to avoid touch scrolling.
*/
unblockWebsiteScroll() {
document.body.removeEventListener('touchmove', this.disableTouchMove, {passive: false});
lockWebsiteScroll() {
this.websiteBeforeLockParameters = {
bodyStylePosition: document.body.style.position ? document.body.style.position : '',
bodyStyleOverflow: document.body.style.overflow ? document.body.style.overflow : '',
htmlStyleOverflow: document.documentElement.style.overflow ? document.documentElement.style.overflow : '',
windowScrollX: window.scrollX,
windowScrollY: window.scrollY
};
document.body.style.position = 'fixed';
document.body.style.overflow = 'hidden';
document.documentElement.style.overflow = 'hidden';
}

/**
* Prevents the default event behavior to a MouseEvent.
* @param {MouseEvent} mouseEvent - mouse event.
* Unlocks website scroll for mobile devices.
*/
disableTouchMove(mouseEvent) {
mouseEvent.preventDefault();
unlockWebsiteScroll() {
if (this.websiteBeforeLockParameters) {
document.body.style.position = this.websiteBeforeLockParameters.bodyStylePosition;
document.body.style.overflow = this.websiteBeforeLockParameters.bodyStyleOverflow;
document.documentElement.style.overflow = this.websiteBeforeLockParameters.htmlStyleOverflow;
window.scrollTo(this.websiteBeforeLockParameters.windowScrollX, this.websiteBeforeLockParameters.windowScrollY);
this.websiteBeforeLockParameters = null;
}
}

/**
Expand Down Expand Up @@ -835,6 +854,9 @@ export default class ModalDialog {
this.minimizeDiv.addEventListener('click', this.minimize.bind(this), true);
this.closeDiv.addEventListener('click', this.cancelAction.bind(this));

// Overlay events (close).
this.overlay.addEventListener('click', this.cancelAction.bind(this));

// Mouse events.
Util.addEvent(window, 'mousedown', this.startDrag.bind(this));
Util.addEvent(window, 'mouseup', this.stopDrag.bind(this));
Expand Down
16 changes: 10 additions & 6 deletions core/src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,19 +286,23 @@ export default class Parser {
static endParseEditMode(code) {
// Converting LaTeX to images.
if (Configuration.get('parseModes').indexOf('latex') != -1) {
var output = '';
var endPosition = 0;
var startPosition = code.indexOf('$$');
let output = '';
let endPosition = 0;
let startPosition = code.indexOf('$$');
while (startPosition != -1) {
output += code.substring(endPosition, startPosition);
endPosition = code.indexOf('$$', startPosition + 2);

if (endPosition != -1) {
// Before, it was a condition here to execute the next codelines 'latex.indexOf('<') == -1'.
// We don't know why it was used, but seems to have a conflict with latex formulas that contains '<'.
var latex = code.substring(startPosition + 2, endPosition);
latex = Util.htmlEntitiesDecode(latex);
var mathml = Latex.getMathMLFromLatex(latex, true);
const latex = code.substring(startPosition + 2, endPosition);
const decodedLatex = Util.htmlEntitiesDecode(latex);
let mathml = Latex.getMathMLFromLatex(decodedLatex, true);
if (!Configuration.get('saveHandTraces')) {
// Remove hand traces.
mathml = MathML.removeAnnotation(mathml, 'application/json');
}
output += mathml;
endPosition += 2;
}
Expand Down
Loading

0 comments on commit 87b4182

Please sign in to comment.