/* * CleanPaste for YUI Rich Text Editor * http://richtextcleanpaste.codeplex.com * * Copyright (c) 2009 Anthony Super * http://antscode.blogspot.com * * v 1.1 */ function CleanPaste(editor) { this.Editor = editor; this.Editor.on('editorContentLoaded', this.init, this, true); this.OnBeforePaste = null; this.OnAfterPaste = null; } CleanPaste.prototype.init = function() { var doc = this.Editor._getDoc(); if (document.all) { // IE events YAHOO.util.Event.on(doc.body, 'beforepaste', this.handleBeforePaste, this, true); YAHOO.util.Event.on(doc.body, 'paste', this.handlePaste, this, true); YAHOO.util.Event.on(doc, 'dragstart', this.handleDragDrop, this, true); YAHOO.util.Event.on(doc, 'dragend', this.handleDragDrop, this, true); } else { // Mozilla events this.Editor.on('editorKeyDown', this.handleKeyDown, this, true); YAHOO.util.Event.on(doc, 'contextmenu', this.handleContextMenu, this, true); } } CleanPaste.prototype.handleKeyDown = function(e) { var vkey = 86 var vInsertKey = 45 var isMac = (navigator ? navigator.appVersion.indexOf('Mac') != -1 : false); var _this = this; // Check to see if CTRL + V is pressed if ((!isMac && e.ev.keyCode == vkey && e.ev.ctrlKey) || (!isMac && e.ev.keyCode == vInsertKey && e.ev.shiftKey) || (isMac && e.ev.keyCode == vkey && e.ev.metaKey)) { this.InsertContainer() setTimeout(function() { _this.CleanPaste() }, 10); } } CleanPaste.prototype.handleBeforePaste = function(e) { var container = this.Editor._getDoc().getElementById('Cleaner'); // Remove any existing container if (container) container.parentNode.removeChild(container); // Insert a container for placing the cleaned text this.InsertContainer(); // Cancel the event bubble YAHOO.util.Event.stopEvent(e); } CleanPaste.prototype.handlePaste = function() { var _this = this; setTimeout(function() { _this.CleanPaste() }, 10); } CleanPaste.prototype.handleDragDrop = function(e) { YAHOO.util.Event.stopEvent(e); } CleanPaste.prototype.handleContextMenu = function(e) { YAHOO.util.Event.stopEvent(e); } CleanPaste.prototype.InsertContainer = function() { this.Editor.execCommand('inserthtml', "