tlva1 / jwysiwyg

Automatically exported from code.google.com/p/jwysiwyg
0 stars 0 forks source link

.bind('paste') & SetTimeout #210

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi, I'm tryin' to modify the wysiwyg editor to autoclean pasted text doing 
something like this:

if ( this.options.autoSave )
{
    $(this.editorDoc)
      .bind('paste', setTimeout(function()
                                {//cleaning code},500)
           )
}

but I can't retrieve the content inside of setTimeout(), what is the contest 
when I fire this function ?
Functions like self.getContent() don't seems to exist...

Original issue reported on code.google.com by richi.ra...@gmail.com on 1 Oct 2010 at 8:36

GoogleCodeExporter commented 8 years ago
Based on Issue 129 and modified a bit, you can add the code above after block 

if ( this.options.css ){...} 

on the jquery.wysiwyg.js file.

Note: setTimeout should be called inside the bind..

$(this.editorDoc).bind('paste', function(e){ 

                setTimeout(function() {

                    //ms word clean-up  
                    var html = self.getContent();
                    function CleanWord(html)
                    {
                    html = html.replace(/<(\/)*(\\?xml:|a|span|p|button|style|font|del|ins|st1:|[ovwxp]:)(.*?)>/gi, '');
                    html = html.replace(/(class|style|type|start|href)="(.*?)"/gi, ''); 
                    html = html.replace( /\s*mso-[^:]+:[^;"]+;?/gi, '' ) ;
                    html = html.replace(/<\s*(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3");
                    html = html.replace( /<(\w[^>]*) onmouseover="([^\"]*)"([^>]*)/gi, "<$1$3") ;
                    html = html.replace( /<(\w[^>]*) onmouseout="([^\"]*)"([^>]*)/gi, "<$1$3") ;
                    html = html.replace(/<script(.*?)script>/gi, '');
                    html = html.replace(/<!--(.*?)-->/gi, '');      
                    html = html.replace(/<\/?(span)[^>]*>/gi, '');       
                    html = html.replace(/<\/?(span)[^>]*>/gi, '');     
                    html = html.replace( /<\/?(img|font|style|p|div|v:\w+)[^>]*>/gi, '');            
                    html = html.replace( /\s*style="\s*"/gi, '' ) ;
                    html = html.replace( /<SPAN\s*[^>]*>\s* \s*<\/SPAN>/gi, ' ' ) ;
                    html = html.replace( /<SPAN\s*[^>]*><\/SPAN>/gi, '' ) ;
                    return html;
                    }                       
                    //call the function and replace the current content with the clean one
                    self.setContent(CleanWord(html));
                    self.saveContent();

                    // alert(self.getContent());

                }, 100);

Original comment by andrea.d...@gmail.com on 9 Mar 2011 at 1:21