Skip to content

Commit

Permalink
3.50 Stable version
Browse files Browse the repository at this point in the history
  • Loading branch information
mcagigas-at-wiris authored Jul 10, 2017
1 parent 86a8684 commit 8dc0f88
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 32 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.4.1.1368
4.5.0.1372
138 changes: 114 additions & 24 deletions core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ function wrs_fireEvent(element, event) {
}

wrs_addEvent(window, 'mouseup', function (e) {

if (typeof(_wrs_modalWindow) !== 'undefined' && _wrs_modalWindow != null) {
if (_wrs_modalWindow.properties.state != "maximized") {
_wrs_modalWindow.overlayDiv.style.display = 'none';
}
wrs_fireEvent(_wrs_modalWindow.iframe.contentDocument, 'mouseup');
_wrs_modalWindow.fireEditorEvent('mouseup');
}
});

Expand Down Expand Up @@ -2576,7 +2577,7 @@ function wrs_urldecode(input) {
function wrs_urlencode(clearString) {
var output = '';
// Method encodeURIComponent doesn't encode !'()*~ .
output = encodeURIComponent(clearString).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/~/g, '%7E');
output = encodeURIComponent(clearString);
return output;
}

Expand Down Expand Up @@ -3405,6 +3406,7 @@ if (!Object.keys) {
/**
* Add a new callback to a WIRIS plugins listener.
* @param {object} listener an Object containing listener name and a callback.
* @ignore
*/
function wrs_addPluginListener(listener) {
wrs_pluginListeners.push(listener);
Expand All @@ -3414,13 +3416,47 @@ function wrs_addPluginListener(listener) {
* For now its not possible comunicate directly between editor.js and ModalWindow object.
* We need to use this method to call ModalWindow prototype from editor.js
* @param {object} editor WIRIS Editor
* @ignore
*/
function wrs_setModalWindowEditor(editor) {
if (_wrs_conf_modalWindow) {
_wrs_modalWindow.setEditor(editor);
}
}

/**
* Get the base URL (i.e the URL on core.js lives).
*/
function wrs_getServerPath() {
url = wrs_getCorePath();
var hostNameIndex = url.indexOf("/", url.indexOf("/") + 2);
return url.substr(0, hostNameIndex);
}

/**
* This method updates all services paths if there are relative with the absolute
* URL path.
* @ignore
*/
function wrs_updateContextPath() {
if (typeof _wrs_conf_plugin_loaded == 'undefined') {
setTimeout(wrs_updateContextPath, 100);
} else {
if (_wrs_conf_showimagePath.indexOf("/") == 0) {
serverPath = wrs_getServerPath()
_wrs_conf_showimagePath = serverPath + _wrs_conf_showimagePath;
_wrs_conf_editorPath = serverPath + _wrs_conf_editorPath;
_wrs_conf_CASPath = serverPath + _wrs_conf_CASPath;
_wrs_conf_createimagePath = serverPath + _wrs_conf_createimagePath;
_wrs_conf_createcasimagePath = serverPath + _wrs_conf_createcasimagePath;
_wrs_conf_getmathmlPath = serverPath + _wrs_conf_getmathmlPath;
_wrs_conf_servicePath = serverPath + _wrs_conf_servicePath;
}
}
}

wrs_updateContextPath();

// Production steps of ECMA-262, Edition 5, 15.4.4.18
// Reference: http://es5.github.io/#x15.4.4.18.
if (!Array.prototype.forEach) {
Expand Down Expand Up @@ -4128,7 +4164,12 @@ function ModalWindow(path, editorAttributes) {
var iframeModalContainer = wrs_createElement('div', attributes);
this.iframeContainer = iframeModalContainer;

// We create iframe inside _wrs_conf_path origin.
this.iframeOrigin = this.getOriginFromUrl(_wrs_conf_path);

this.lastImageWasNew = true;

this.toolbar = null;
}

ModalWindow.prototype.create = function() {
Expand All @@ -4140,7 +4181,7 @@ ModalWindow.prototype.create = function() {

wrs_addEvent(this.overlayDiv, 'mouseup', function (e) {
if (typeof(_wrs_modalWindow) !== 'undefined' && _wrs_modalWindow != null) {
wrs_fireEvent(_wrs_modalWindow.iframe.contentDocument, 'mouseup');
_wrs_modalWindow.fireEditorEvent('mouseup');
}
});

Expand Down Expand Up @@ -4183,18 +4224,20 @@ ModalWindow.prototype.open = function() {
if (this.properties.open == true || this.properties.created) {

var editor = this.editor;
var updateToolbar = function() {

// TODO: Rewrite this method.
var updateToolbar = function(object) {
if (customEditor = wrs_int_getCustomEditorEnabled()) {
var toolbar = customEditor.toolbar ? customEditor.toolbar : _wrs_int_wirisProperties['toolbar'];
_wrs_modalWindow.setTitle(customEditor.title);
if (typeof editor.params.toolbar == 'undefined' || editor.params.toolbar != toolbar) {
editor.setParams({'toolbar' : toolbar});
if (object.toolbar == null || object.toolbar != toolbar) {
object.setToolbar(toolbar);
}
} else {
var toolbar = (typeof _wrs_int_wirisProperties == 'undefined' || typeof _wrs_int_wirisProperties['toolbar'] == 'undefined') ? 'general' : _wrs_int_wirisProperties['toolbar'];
_wrs_modalWindow.setTitle('WIRIS EDITOR math');
if (typeof editor.params.toolbar == 'undefined' || editor.params.toolbar != toolbar) {
editor.setParams({'toolbar' : toolbar});
if (object.toolbar == null || object.toolbar != toolbar) {
object.setToolbar(toolbar);
wrs_int_disableCustomEditors();
}
}
Expand All @@ -4206,21 +4249,21 @@ ModalWindow.prototype.open = function() {
var updateMathMLContent = function () {
if (!self.lastImageWasNew) {
if (self.properties.deviceProperties.isAndroid || self.properties.deviceProperties.isIOS) {
editor.setMathML('<math><semantics><annotation encoding="application/json">[]</annotation></semantics></math>"');
this.setMathML('<math><semantics><annotation encoding="application/json">[]</annotation></semantics></math>"');
} else {
editor.setMathML('<math/>');
this.setMathML('<math/>');
}
}
};

if (this.properties.open == true) {
updateToolbar();
updateToolbar(self);
if (_wrs_isNewElement) {
updateMathMLContent();
self.lastImageWasNew = true;
}
else {
editor.setMathML(wrs_mathmlDecode(_wrs_temporalImage.getAttribute('data-mathml')));
this.setMathML(wrs_mathmlDecode(_wrs_temporalImage.getAttribute('data-mathml')));
this.lastImageWasNew = false;
}
}
Expand All @@ -4232,17 +4275,17 @@ ModalWindow.prototype.open = function() {

this.properties.open = true;

updateToolbar();
updateToolbar(self);

if (_wrs_isNewElement) {
updateMathMLContent();
self.lastImageWasNew = true;
} else {
editor.setMathML(wrs_mathmlDecode(_wrs_temporalImage.getAttribute('data-mathml')));
this.setMathML(wrs_mathmlDecode(_wrs_temporalImage.getAttribute('data-mathml')));
this.lastImageWasNew = false;
}

editor.focus();
console.log("focusing");
this.focus();

if (!this.properties.deviceProperties.isAndroid && !this.properties.deviceProperties.isIOS) {
this.stackModalWindow();
Expand All @@ -4265,11 +4308,9 @@ ModalWindow.prototype.open = function() {
* @ignore
*/
ModalWindow.prototype.close = function() {
// Is mandatory make this BEFORE hide modalwindow.
this.editor.setMathML('<math/>');
this.setMathML('<math/>');
this.overlayDiv.style.visibility = 'hidden';
this.containerDiv.style.visibility = 'hidden';
this.containerDiv.style.display = 'none';
this.overlayDiv.style.display = 'none';
this.properties.open = false;
wrs_int_disableCustomEditors();
Expand Down Expand Up @@ -4443,8 +4484,6 @@ ModalWindow.prototype.addListeners = function() {
wrs_addEvent(document.body, 'mousedown', this.startDrag.bind(this));
wrs_addEvent(window, 'mouseup', this.stopDrag.bind(this));
wrs_addEvent(document, 'mouseup', this.stopDrag.bind(this));
wrs_addEvent(this.iframe.contentWindow, 'mouseup', this.stopDrag.bind(this));
wrs_addEvent(this.iframe.contentWindow, 'mousedown', this.setOverlayDiv.bind(this));
wrs_addEvent(document.body, 'mousemove', this.drag.bind(this));
}

Expand Down Expand Up @@ -4591,9 +4630,60 @@ ModalWindow.prototype.hideKeyboard = function() {
window.scrollTo(0, keepScroll);
}


/**
* Set WIRIS Editor as variable
* Returns the origin (i.e protocol + hostname + port) from an url string.
* This method is used to get the iframe window origin to allow postMessages.
* @param {string} url url string
* @return {string} origin string
* @ignore
*/
ModalWindow.prototype.getOriginFromUrl = function(url) {
var hostNameIndex = url.indexOf("/", url.indexOf("/") + 2);
return url.substr(0, hostNameIndex);
}

/**
* Enable safe cross-origin comunication betweenWIRIS Plugin and WIRIS Editor. We can't call directly
* WIRIS Editor methods because the content iframe could be in a different domain.
* We use postMessage method to create a wrapper between modal window and editor.
*
*/

/**
* Set a MathML into editor.
* @param {string} mathml MathML string.
* @ignore
*/
ModalWindow.prototype.setMathML = function(mathml) {
_wrs_popupWindow.postMessage({'objectName' : 'editor', 'methodName' : 'setMathML', 'arguments': [mathml]}, this.iframeOrigin);
this.focus();
}

/**
* Set a toolbar into editor.
* @param {string} toolbar toolbar name.
* @ignore
*/
ModalWindow.prototype.setToolbar = function(toolbar) {
this.toolbar = toolbar;
_wrs_popupWindow.postMessage({'objectName' : 'editor', 'methodName' : 'setParams', 'arguments': [{'toolbar' : toolbar}]}, this.iframeOrigin);
}

/**
* Set focus on editor.
* @ignore
*/
ModalWindow.prototype.focus = function() {
_wrs_popupWindow.postMessage({'objectName' : 'editor', 'methodName' : 'focus', 'arguments': null}, this.iframeOrigin);
}


/**
* Fires editor event
* @param {string} eventName event name
* @ignore
*/
ModalWindow.prototype.setEditor = function(editor) {
this.editor = editor;
ModalWindow.prototype.fireEditorEvent = function(eventName) {
_wrs_popupWindow.postMessage({'objectName' : 'editorEvent', 'eventName' : eventName, 'arguments': null}, this.iframeOrigin);
}
30 changes: 26 additions & 4 deletions core/editor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var _wrs_isNewElement; // Unfortunately we need this variabels as global variable for old I.E compatibility.

(function(){

var editor;
// Set wrs_int_opener variable and close method.
// For popup window opener is window.opener. For modal window window.parent.
var wrs_int_opener = window.opener ? window.opener : window.parent;
Expand Down Expand Up @@ -211,7 +213,6 @@ var _wrs_isNewElement; // Unfortunately we need this variabels as global variabl

var queryParams = wrs_getQueryParams(window);
var customEditor;
var editor;

wrs_attributes = _wrs_conf_editorParameters;
wrs_attributes.language = queryParams['lang'];
Expand Down Expand Up @@ -240,9 +241,6 @@ var _wrs_isNewElement; // Unfortunately we need this variabels as global variabl
}

// Set ModalWindow editor attribute.
getMethod(null, 'wrs_setModalWindowEditor', [editor], function(){
});
_wrs_modalWindowProperties.editor = editor;

var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1;
Expand Down Expand Up @@ -400,6 +398,29 @@ var _wrs_isNewElement; // Unfortunately we need this variabels as global variabl
controls.id = 'controls_rtl';
}

// At this point we listen to execute editor methods or fire editor events.
wrs_addEvent(window, 'message', function (e) {
if (e.data.objectName != 'undefined' && e.data.objectName == 'editor') {
editor[e.data.methodName].apply(editor, e.data.arguments);
}

if (e.data.objectName != 'undefined' && e.data.objectName == 'editorEvent') {
wrs_fireEvent(window.document, e.data.eventName);
}
});

wrs_addEvent(window, 'mouseup', function(e) {
if (_wrs_conf_modalWindow) {
getMethod('_wrs_modalWindow', 'stopDrag', [], null);
}
});

wrs_addEvent(window, 'mousedown', function(e) {
if (_wrs_conf_modalWindow) {
getMethod('_wrs_modalWindow', 'setOverlayDiv', [], null);
}
});

// Auto resizing.
setInterval(function () {
editorElement.style.height = (document.getElementById('container').offsetHeight - controls.offsetHeight - 10) + 'px';
Expand All @@ -411,6 +432,7 @@ var _wrs_isNewElement; // Unfortunately we need this variabels as global variabl
} else {
setTimeout(wrs_waitForEditor, 100);
}

}
wrs_waitForEditor();
});
Expand Down
6 changes: 3 additions & 3 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2017061800;
$plugin->release = '4.4.1.1368';
$plugin->version = 2017070900;
$plugin->release = '4.5.0.1372';
$plugin->requires = 2014050800;
$plugin->component = 'atto_wiris';
$plugin->dependencies = array ('filter_wiris' => 2017061800);
$plugin->dependencies = array ('filter_wiris' => 2017070900);
$plugin->maturity = MATURITY_STABLE;

0 comments on commit 8dc0f88

Please sign in to comment.