Skip to content

Commit

Permalink
Merge branch 'MDL-45867-master' of https://github.com/dthies/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Nov 24, 2014
2 parents 8030d84 + 3086c8c commit 1d9eb92
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ Y.namespace('M.atto_equation').Button = Y.Base.create('button', Y.M.editor_atto.
var textarea = this._content.one(SELECTORS.EQUATION_TEXT),
equation = textarea.get('value'),
url,
preview,
currentPos = textarea.get('selectionStart'),
prefix = '',
cursorLatex = '\\Downarrow ',
Expand Down Expand Up @@ -455,7 +454,6 @@ Y.namespace('M.atto_equation').Button = Y.Base.create('button', Y.M.editor_atto.
this._lastCursorPos = currentPos;
equation = prefix + equation.substring(0, currentPos) + cursorLatex + equation.substring(currentPos);

var previewNode = this._content.one(SELECTORS.EQUATION_PREVIEW);
equation = DELIMITERS.START + ' ' + equation + ' ' + DELIMITERS.END;
// Make an ajax request to the filter.
url = M.cfg.wwwroot + '/lib/editor/atto/plugins/equation/ajax.php';
Expand All @@ -466,13 +464,30 @@ Y.namespace('M.atto_equation').Button = Y.Base.create('button', Y.M.editor_atto.
text: equation
};

preview = Y.io(url, {
sync: true,
data: params
Y.io(url, {
context: this,
data: params,
timeout: 500,
on: {
complete: this._loadPreview
}
});
},

/**
* Load returned preview text into preview
*
* @param {String} id
* @param {EventFacade} e
* @method _loadPreview
* @private
*/
_loadPreview: function(id, preview) {
var previewNode = this._content.one(SELECTORS.EQUATION_PREVIEW);

if (preview.status === 200) {
previewNode.setHTML(preview.responseText);

Y.fire(M.core.event.FILTER_CONTENT_UPDATED, {nodes: (new Y.NodeList(previewNode))});
}
},
Expand All @@ -487,6 +502,7 @@ Y.namespace('M.atto_equation').Button = Y.Base.create('button', Y.M.editor_atto.
*/
_getDialogueContent: function() {
var library = this._getLibraryContent(),
throttledUpdate = this._throttle(this._updatePreview, 500),
template = Y.Handlebars.compile(TEMPLATES.FORM);

this._content = Y.Node.create(template({
Expand All @@ -509,9 +525,9 @@ Y.namespace('M.atto_equation').Button = Y.Base.create('button', Y.M.editor_atto.
this._content.delegate('key', this._groupNavigation, 'down:37,39', SELECTORS.LIBRARY_BUTTON, this);

this._content.one(SELECTORS.SUBMIT).on('click', this._setEquation, this);
this._content.one(SELECTORS.EQUATION_TEXT).on('valuechange', this._throttle(this._updatePreview, 500), this);
this._content.one(SELECTORS.EQUATION_TEXT).on('mouseup', this._throttle(this._updatePreview, 500), this);
this._content.one(SELECTORS.EQUATION_TEXT).on('keyup', this._throttle(this._updatePreview, 500), this);
this._content.one(SELECTORS.EQUATION_TEXT).on('valuechange', throttledUpdate, this);
this._content.one(SELECTORS.EQUATION_TEXT).on('mouseup', throttledUpdate, this);
this._content.one(SELECTORS.EQUATION_TEXT).on('keyup', throttledUpdate, this);
this._content.delegate('click', this._selectLibraryItem, SELECTORS.LIBRARY_BUTTON, this);

return this._content;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1d9eb92

Please sign in to comment.