Best practice forum (Archived)

Javascript Syntax Error from ' '

 
? ?
Javascript Syntax Error from ' '
by ? ? - Thursday, 21 July 2011, 4:08 PM
 

On certain course topics I call an initialise script for a jQuery plugin (in the HTML source):

<script type="text/javascript">Shadowbox.init()</script>

Althought it seems that whenever I then edit this same topic content (through WSIWYG editor or HTML source) the editor adds in the // <![CDATA[ // ]]> XHTML parsers - which is fine.

It then adds another '&#010;' sourrounding my script each time I edit the content . This ends up as:

&#010;&#010;&#010;Shadowbox.init()&#010;&#010;&#010;

which then gives me a Syntax error, breaking the script and disabling the plugin from working.

Is there any way to stop the editor doing this?

Simon Coggins
Re: Javascript Syntax Error from ' '
by Simon Coggins - Friday, 22 July 2011, 4:45 AM
Group Totara

This is being caused by a bug in TinyMCE:

http://tinymce.moxiecode.com/develop/bugtracker_view.php?id=4370

There is a fix available so we'll merge it into the next release.

Simon

Simon Coggins
Re: Javascript Syntax Error from ' '
by Simon Coggins - Monday, 25 July 2011, 7:36 PM
Group Totara

Sorry we didn't get to including this in 1.0.19. I'll make sure it makes it into 1.0.20 (due out next week).

Simon

This forum post has been removed
Monday, 1 August 2011, 7:47 PM
The content of this forum post has been removed and can no longer be accessed.
This forum post has been removed
Wednesday, 3 August 2011, 3:52 AM
The content of this forum post has been removed and can no longer be accessed.
? ?
Re: Javascript Syntax Error from ' '
by ? ? - Monday, 15 August 2011, 10:47 PM
 
The upgrade doesn't seem to have fixed the issue. I'm still getting duplicate &#10%; added to start and end of scripts each time I make changes using the HTML editor to content sections...
This forum post has been removed
Thursday, 18 August 2011, 4:03 PM
The content of this forum post has been removed and can no longer be accessed.
Craig Eves
Re: Javascript Syntax Error from ' '
by Craig Eves (Totara Support) - Thursday, 18 August 2011, 5:25 PM
Group Totara

Hi Aaron

I tried adding in Firefox and IE9 in HTML view in demo which is v1.0.21

the code that was showing<script type="text/javascript">// <![CDATA[
&#010;Shadowbox.init()&#010;
// ]]></script>

Hopefully this helps narrow things down.

I have no idea if it will but the CDATA looks like it is something to do with a database so could be a database issue?

Craig

? ?
Re: Javascript Syntax Error from ' '
by ? ? - Monday, 22 August 2011, 11:20 PM
 

Hi,

I created a new course, added a label with the shadowbox init script and link,works fine.

When I go back and edit the same label and save changes it breaks script - Syntax error:


&#010;&#010;Shadowbox.init();&#010;&#010;

I get the same results in: IE6, Safari 5.1 and Firefox 6.

Simon Coggins
Re: Javascript Syntax Error from ' '
by Simon Coggins - Wednesday, 24 August 2011, 1:27 AM
Group Totara

Hi Ira,

Sorry about that, we'll take another look.

Simon

Simon Coggins
Re: Javascript Syntax Error from ' '
by Simon Coggins - Sunday, 4 September 2011, 4:35 PM
Group Totara

Hi Ira,

Thanks for your patience on this one - it proved to be a little tricky. It seems to be a long-standing moodle bug, and we think we've finally got a working fix. We'll do some testing and include it in tomorrow's release (1.0.23).

Simon

? ?
Re: Javascript Syntax Error from ' '
by ? ? - Wednesday, 7 September 2011, 12:59 AM
 

Hi,

after updating to version 1.0.23 and my initial testing it appears that this bug has been fixed. I still need to test with multiple browsers, but looking good so far :)

thanks

-Ira

? ?
Re: Javascript Syntax Error from ' '
by ? ? - Thursday, 15 September 2011, 8:42 PM
 

Hi,

just wondering what was used to fix this issue? We have another Moodle install in a different department which appears to be having a similar problem.

thanks,

-Ira

Simon Coggins
Re: Javascript Syntax Error from ' '
by Simon Coggins - Thursday, 15 September 2011, 9:29 PM
Group Totara

Here is the patch that fixed it:

diff --git a/lib/form/htmleditor.php b/lib/form/htmleditor.php
index a9c2a18..09dd230 100644
--- a/lib/form/htmleditor.php
+++ b/lib/form/htmleditor.php
@@ -75,7 +75,7 @@ class MoodleQuickForm_htmleditor extends MoodleQuickForm_textarea{
                                     $this->_options['width'],
                                     $this->_options['height'],
                                     $this->getName(),
-                                    preg_replace("/(\r\n|\n|\r)/", '
',$this->getValue()),
+                                    $this->getValue(),
                                     0, // unused anymore
                                     true,
                                     $this->getAttribute('id'));//.$script;
@@ -94,4 +94,4 @@ class MoodleQuickForm_htmleditor extends MoodleQuickForm_textarea{
         return $html . $this->_getPersistantData();
     } //end func getFrozenHtml
 }
-?>
\ No newline at end of file
+?>
diff --git a/lib/pear/HTML/QuickForm/textarea.php b/lib/pear/HTML/QuickForm/textarea.php
index 7aa0af2..358d870 100644
--- a/lib/pear/HTML/QuickForm/textarea.php
+++ b/lib/pear/HTML/QuickForm/textarea.php
@@ -190,7 +190,7 @@ class HTML_QuickForm_textarea extends HTML_QuickForm_element
             return $this->_getTabs() .
                    '_getAttrString($this->_attributes) . '>' .
                    // because we wrap the form later we don't want the text indented
-                   preg_replace("/(\r\n|\n|\r)/", '
', htmlspecialchars($this->_value)) .
+                   htmlspecialchars($this->_value) .
                    '';
         }
     } //end func toHtml

Moodle was inserting the extra characters, which was then confusing TinyMCE.

Simon