1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2005, 2006, 2007, 2009, 2010, 2013, 2014, 2016 Synacor, Inc. 5 * 6 * The contents of this file are subject to the Common Public Attribution License Version 1.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at: https://www.zimbra.com/license 9 * The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15 10 * have been added to cover use of software over a computer network and provide for limited attribution 11 * for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B. 12 * 13 * Software distributed under the License is distributed on an "AS IS" basis, 14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. 15 * See the License for the specific language governing rights and limitations under the License. 16 * The Original Code is Zimbra Open Source Web Client. 17 * The Initial Developer of the Original Code is Zimbra, Inc. All rights to the Original Code were 18 * transferred by Zimbra, Inc. to Synacor, Inc. on September 14, 2015. 19 * 20 * All portions of the code are Copyright (C) 2005, 2006, 2007, 2009, 2010, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * Makes server request to check spelling of given text. 26 * Use this class to check spelling of any text via {@link check} method. 27 * 28 * @author Mihai Bazon 29 * 30 * @param {ZmHtmlEditor} parent the parent needing spell checking 31 * 32 * @class 33 * @constructor 34 */ 35 ZmSpellChecker = function(parent) { 36 this._parent = parent; 37 }; 38 39 /** 40 * Returns a string representation of the object. 41 * 42 * @return {String} a string representation of the object 43 */ 44 ZmSpellChecker.prototype.toString = 45 function() { 46 return "ZmSpellChecker"; 47 }; 48 49 /** 50 * Checks the spelling. 51 * 52 * @param {Object|String} textOrParams the text to check or an object with "text" and "ignore" properties 53 * @param {AjxCallback} callback the callback for success 54 * @param {AjxCallback} errCallback the error callback 55 */ 56 ZmSpellChecker.prototype.check = 57 function(textOrParams, callback, errCallback) { 58 var params = typeof textOrParams == "string" ? { text: textOrParams } : textOrParams; 59 var soapDoc = AjxSoapDoc.create("CheckSpellingRequest", "urn:zimbraMail"); 60 soapDoc.getMethod().appendChild(soapDoc.getDoc().createTextNode(params.text)); 61 if (params.ignore) { 62 soapDoc.getMethod().setAttribute("ignore", params.ignore); 63 } 64 var callback = new AjxCallback(this, this._checkCallback, callback); 65 appCtxt.getAppController().sendRequest({soapDoc: soapDoc, asyncMode: true, callback: callback, errorCallback: errCallback}); 66 }; 67 68 ZmSpellChecker.prototype._checkCallback = 69 function(callback, result) { 70 var words = result._isException ? null : result.getResponse().CheckSpellingResponse; 71 72 if (callback) 73 callback.run(words); 74 }; 75