Jaromi / jwysiwyg

Automatically exported from code.google.com/p/jwysiwyg
GNU General Public License v2.0
0 stars 0 forks source link

Problem when using jWysiwyg in a JS modal box (blockUI, thickbox, or other ...) [Solution inside] #100

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I'm using jwysiwyg 0.5 with jquery 1.3.2.

To reproduce the problem :
1. Open a js modal box (blockUI, thickbox, or other ...) with a form that
contains a textarea and call .wysiwyg() on the concerned textearea. (I get
the form from an AJAX request but this is not the point, it should be the
same without AJAX)
2. It works very so far !
3. Close the modal box
4. Do a .submit() on an other form in the page.

You get the following error : 'element.contentWindow is null' 

This is because the 'init' function is using 'form' selector and bind
events on all forms of the page  :
I replace the follwing code :
            if (this.options.autoSave) 
                $('form').submit(function(){  // <--- 'form' selector here
                    self.saveContent();
                });

            $('form').bind('reset', function(){ // <-- 'form' selector here
                self.setContent(self.initialContent);
                self.saveContent();
            });
with this code that binds the event only on the parent form that contains
the textarea on which I call .wysiwyg() :

            var form = $(this).parents('form:first');
            if (this.options.autoSave) 
                $(form).submit(function(){
                    self.saveContent();
                });

            $(form).bind('reset', function(){
                self.setContent(self.initialContent);
                self.saveContent();
            });

And it works fine !

Original issue reported on code.google.com by Mickael....@gmail.com on 8 Apr 2009 at 5:00

GoogleCodeExporter commented 8 years ago
And please, forgive me for my horrible english (I'm french)

Original comment by Mickael....@gmail.com on 8 Apr 2009 at 5:02

GoogleCodeExporter commented 8 years ago
An error in my text :
"2. It works very so far !"

I mean :
"2. It works fine so far !"

Original comment by Mickael....@gmail.com on 8 Apr 2009 at 5:05

GoogleCodeExporter commented 8 years ago
Hey! Thanks for the fix. I update it at r32.

Original comment by joksnet on 21 Apr 2009 at 11:08

GoogleCodeExporter commented 8 years ago
This is more robust to write

var form = $(this).closest('form');

Original comment by akzhan.a...@gmail.com on 4 Dec 2009 at 2:54

GoogleCodeExporter commented 8 years ago
More clear:

        var form = $(this).closest('form');
            if ( this.options.autoSave )
                form.submit(function() { self.saveContent(); });

            form.bind('reset', function()
            {
                self.setContent( self.initialContent );
                self.saveContent();
            });

Original comment by akzhan.a...@gmail.com on 4 Dec 2009 at 2:55