Ankita-ks has submitted this change and it was merged. Change subject: Processing the response from LanguageTool server in a different function ......................................................................
Processing the response from LanguageTool server in a different function Change-Id: Ia4918e9097bf351c03fc6ce09505dd451ad923f8 --- M modules/ext.LanguageToolAction.js 1 file changed, 52 insertions(+), 1 deletion(-) Approvals: Ankita-ks: Verified; Looks good to me, approved diff --git a/modules/ext.LanguageToolAction.js b/modules/ext.LanguageToolAction.js index 00307ea..c781af8 100644 --- a/modules/ext.LanguageToolAction.js +++ b/modules/ext.LanguageToolAction.js @@ -95,13 +95,19 @@ data: { language: lang, text: text } } ).done( this.openDialog + //this.processXML ); return; }; mw.languageToolAction.prototype.openDialog = function ( responseXML ) { - var messageDialog, windowManager, errors, i, response; + var suggestions, messageDialog, windowManager, errors, i, response; + + //var processXML = this.processXML.bind( this ); + suggestions = this.processXML( responseXML ); + console.log('suggestions'); + console.log(suggestions); messageDialog = new OO.ui.MessageDialog(); @@ -132,6 +138,51 @@ } ); }; +mw.languageToolAction.prototype.processXML = function ( responseXML ) { + console.log('entered'); + this.suggestions = []; + var errors = responseXML.getElementsByTagName('error'); + for (var i = 0; i < errors.length; i++) { + var suggestion = {}; + // I didn't manage to make the CSS break the text, so we add breaks with Javascript: + suggestion["description"] = this._wordwrap(errors[i].getAttribute("msg"), 50, "<br/>"); + suggestion["suggestions"] = []; + var suggestionsStr = errors[i].getAttribute("replacements"); + if (suggestionsStr) { + suggestion["suggestions"] = suggestionsStr; + } + var errorOffset = parseInt(errors[i].getAttribute("offset")); + var errorLength = parseInt(errors[i].getAttribute("errorlength")); + suggestion["offset"] = errorOffset; + suggestion["errorlength"] = errorLength; + suggestion["type"] = errors[i].getAttribute("category"); + suggestion["ruleid"] = errors[i].getAttribute("ruleId"); + suggestion["subid"] = errors[i].getAttribute("subId"); + var url = errors[i].getAttribute("url"); + if (url) { + suggestion["moreinfo"] = url; + } + this.suggestions.push(suggestion); + } + console.log( this.suggestions ); + + return this.suggestions; +} + +// Wrapper code by James Padolsey +// Source: http://james.padolsey.com/javascript/wordwrap-for-javascript/ +// License: "This is free and unencumbered software released into the public domain.", +// see http://james.padolsey.com/terms-conditions/ +mw.languageToolAction.prototype._wordwrap = function(str, width, brk, cut) { + brk = brk || '\n'; + width = width || 75; + cut = cut || false; + if (!str) { return str; } + var regex = '.{1,' +width+ '}(\\s|$)' + (cut ? '|.{' +width+ '}|.+$' : '|\\S+?(\\s|$)'); + return str.match( new RegExp(regex, 'g') ).join( brk ); +}; +// End of wrapper code by James Padolsey + /* Registration */ ve.ui.actionFactory.register( mw.languageToolAction ); -- To view, visit https://gerrit.wikimedia.org/r/222131 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ia4918e9097bf351c03fc6ce09505dd451ad923f8 Gerrit-PatchSet: 8 Gerrit-Project: mediawiki/extensions/LanguageTool Gerrit-Branch: master Gerrit-Owner: Ankita-ks <kumariankita...@gmail.com> Gerrit-Reviewer: Amire80 <amir.ahar...@mail.huji.ac.il> Gerrit-Reviewer: Ankita-ks <kumariankita...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits