/** * @author Shea Frederick - http://www.vinylfox.com * @class Ext.ux.form.HtmlEditor.Word * @extends Ext.util.Observable *
A plugin that creates a button on the HtmlEditor for pasting text from Word without all the jibberish html.
*/ Ext.ux.form.HtmlEditor.Word = Ext.extend(Ext.util.Observable, { // Word language text langTitle: 'Word Paste', langToolTip: 'Cleanse text pasted from Word or other Rich Text applications', wordPasteEnabled: true, // private curLength: 0, lastLength: 0, lastValue: '', // private init: function(cmp){ this.cmp = cmp; this.cmp.on('render', this.onRender, this); this.cmp.on('initialize', this.onInit, this, {delay:100, single: true}); }, // private onInit: function(){ Ext.EventManager.on(this.cmp.getDoc(), { 'keyup': this.checkIfPaste, scope: this }); this.lastValue = this.cmp.getValue(); this.curLength = this.lastValue.length; this.lastLength = this.lastValue.length; }, // private checkIfPaste: function(e){ var diffAt = 0; this.curLength = this.cmp.getValue().length; if (e.V == e.getKey() && e.ctrlKey && this.wordPasteEnabled){ this.cmp.suspendEvents(); diffAt = this.findValueDiffAt(this.cmp.getValue()); var parts = [ this.cmp.getValue().substr(0, diffAt), this.fixWordPaste(this.cmp.getValue().substr(diffAt, (this.curLength - this.lastLength))), this.cmp.getValue().substr((this.curLength - this.lastLength)+diffAt, this.curLength) ]; this.cmp.setValue(parts.join('')); this.cmp.resumeEvents(); } this.lastLength = this.cmp.getValue().length; this.lastValue = this.cmp.getValue(); }, // private findValueDiffAt: function(val){ for (i=0;i