josephtklein / jwysiwyg

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

After destroying, focusing on original textarea causes error #227

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. set up jwysiwyg on a textarea
2. destroy that jwysiwyg
3. click in original textarea

What is the expected output? What do you see instead?
Just see an error.

In Chrome:Uncaught TypeError: Cannot call method 'focus' of null
ui.focusjquery.wysiwyg.js:1005
ui.initFrame.$.keydown.emptyContentRegexjquery.wysiwyg.js:1402
jQuery.event.dispatchjquery.js:3320
jQuery.event.add.elemData.handle.eventHandlejquery.js:2926

in FF: self.editor.get(0).contentWindow is null
self.editor.get(0).contentWindow.focus(); jquery...?body=1 (line 1005)

What version of the product are you using? On what operating system?
WYSIWYG - jQuery plugin 0.97
(0.97.2 - From infinity)

On Mac OSX 10.7.2,
Chrome 16.0.912.77
FF 9.0.1

Thanks!

Original issue reported on code.google.com by rider.sa...@gmail.com on 31 Jan 2012 at 3:24

GoogleCodeExporter commented 9 years ago
Any news regarding this issue?

Original comment by seba.d...@gmail.com on 17 Aug 2012 at 12:02

GoogleCodeExporter commented 9 years ago
Need suggestion for the above mentioned issue

Original comment by rev...@gmail.com on 23 Aug 2012 at 4:05

all2coolnick commented 8 years ago

2016 and having same issue. I wish to make jwysiwyg optional for the user so I am using a button to create & destroy it. After destroy, it disappears from the DOM (header and iframe no longer visible in Safari DOM inspector) but now clicking on the underlying textarea triggers a JS error as described above. Error does not occur until after the jwysiwyg instance has been created and destroyed once.

all2coolnick commented 8 years ago

I think I have fixed the problem though not being an expert as JS, I am not 100% sure how safe it is but the js error is cause by the following line in query.wysiwyg.js (line 1063 in my version)

self.editor.get(0).contentWindow.focus();

By debugging in Safari to inspect self.editor when the editor was active and after it had been destroyed, I found that the editor object still existed but by comparing it's attributes before and after destruction, I was able to confirm that the contentWindow attribute was normally set to "Window" but was null after the editor was destroyed so I added an IF statement that identified whether the editor had been destroyed. Changing the above line to the following solves the problem and I double checked to ensure that the focus() method was still executing when the editor instance was active,

if (self.editor.get(0).contentWindow) self.editor.get(0).contentWindow.focus();

Hope this helps someone else.