jheid
27 May 2010, 3:25 PM
I needed a spell checker for the HTML editor component (for IE 6 indeed). So I used JSpell (look here to get an idea: http://www.jspell.com/tinymcespellchecker.html) and wrote a plugin for it. Here it is:
Ext.namespace ('Ext.ux.form.HtmlEditor');
Ext.ux.form.HtmlEditor.JSpell = function (config) {
Ext.apply(this, config);
Ext.ux.form.HtmlEditor.JSpell.superclass.constructor.call (this);
};
Ext.extend (Ext.ux.form.HtmlEditor.JSpell, Ext.util.Observable, {
jspellServerPath: '/abc',
jspellImagePath: 'images/jspell/',
scriptPath: 'js/jspellEvolution.js',
// additional config elements
jspellConfig: {},
init: function (cmp) {
for (var x in this.jspellConfig)
window[x] = this.jspellConfig[x];
window.jspellServerPath = this.jspellServerPath;
window.jspellImagePath = this.jspellImagePath;
var head = document.getElementsByTagName ('head')[0];
var script = document.createElement ('script');
script.type = 'text/javascript';
script.src = this.scriptPath;
head.appendChild (script);
cmp.on ('afterrender', function () {
cmp.on ('sync', function (cmp, html) {
this.el.dom.value = html.replace (/<span[^>]+class="?j3"?[^>]*>(.*?)<\/span>/gi, '$1');
});
var initSpellchecker = function () {
if (typeof jspellInit == 'undefined' || !cmp.iframe.contentWindow.document.body) {
initSpellchecker.defer (100);
} else {
setTimeout (function () {
cmp.iframe.id = cmp.iframe.id || Ext.id ();
window.getSpellCheckArray = function () {
return [[ document, cmp.iframe.id ]];
};
jspellInit ();
}, 10);
}
};
initSpellchecker ();
}, this);
}
});
You can use it wth a HTMLEditorField like this:
new Ext.form.HtmlEditor ({
plugins: [
new Ext.ux.form.HtmlEditor.JSpell ({
jspellConfig: {
jspellRightClick: true
}
})
});
Currently it checks it as you type (like Firefox or Word does). It would be easy to add a button for manual spell checking.
Ext.namespace ('Ext.ux.form.HtmlEditor');
Ext.ux.form.HtmlEditor.JSpell = function (config) {
Ext.apply(this, config);
Ext.ux.form.HtmlEditor.JSpell.superclass.constructor.call (this);
};
Ext.extend (Ext.ux.form.HtmlEditor.JSpell, Ext.util.Observable, {
jspellServerPath: '/abc',
jspellImagePath: 'images/jspell/',
scriptPath: 'js/jspellEvolution.js',
// additional config elements
jspellConfig: {},
init: function (cmp) {
for (var x in this.jspellConfig)
window[x] = this.jspellConfig[x];
window.jspellServerPath = this.jspellServerPath;
window.jspellImagePath = this.jspellImagePath;
var head = document.getElementsByTagName ('head')[0];
var script = document.createElement ('script');
script.type = 'text/javascript';
script.src = this.scriptPath;
head.appendChild (script);
cmp.on ('afterrender', function () {
cmp.on ('sync', function (cmp, html) {
this.el.dom.value = html.replace (/<span[^>]+class="?j3"?[^>]*>(.*?)<\/span>/gi, '$1');
});
var initSpellchecker = function () {
if (typeof jspellInit == 'undefined' || !cmp.iframe.contentWindow.document.body) {
initSpellchecker.defer (100);
} else {
setTimeout (function () {
cmp.iframe.id = cmp.iframe.id || Ext.id ();
window.getSpellCheckArray = function () {
return [[ document, cmp.iframe.id ]];
};
jspellInit ();
}, 10);
}
};
initSpellchecker ();
}, this);
}
});
You can use it wth a HTMLEditorField like this:
new Ext.form.HtmlEditor ({
plugins: [
new Ext.ux.form.HtmlEditor.JSpell ({
jspellConfig: {
jspellRightClick: true
}
})
});
Currently it checks it as you type (like Firefox or Word does). It would be easy to add a button for manual spell checking.