Best practice forum (Archived)

Javascript Syntax Error from ' '

 
? ?
Javascript Syntax Error from ' '
על ידי ? ? בתאריך 21/07/2011, 16:08
 

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 ' '
על ידי Simon Coggins בתאריך 22/07/2011, 04:45
קבוצה 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 ' '
על ידי Simon Coggins בתאריך 25/07/2011, 19:36
קבוצה 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

פרסום זה הוסר
1/08/2011, 19:47
פרסום זה הוסר ואינו זמין יותר.
פרסום זה הוסר
3/08/2011, 03:52
פרסום זה הוסר ואינו זמין יותר.
? ?
Re: Javascript Syntax Error from ' '
על ידי ? ? בתאריך 15/08/2011, 22:47
 
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...
פרסום זה הוסר
18/08/2011, 16:03
פרסום זה הוסר ואינו זמין יותר.
Craig Eves
Re: Javascript Syntax Error from ' '
על ידי Craig Eves (Totara Support) בתאריך 18/08/2011, 17:25
קבוצה 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 ' '
על ידי ? ? בתאריך 22/08/2011, 23:20
 

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 ' '
על ידי Simon Coggins בתאריך 24/08/2011, 01:27
קבוצה Totara

Hi Ira,

Sorry about that, we'll take another look.

Simon

Simon Coggins
Re: Javascript Syntax Error from ' '
על ידי Simon Coggins בתאריך 4/09/2011, 16:35
קבוצה 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 ' '
על ידי ? ? בתאריך 7/09/2011, 00:59
 

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 ' '
על ידי ? ? בתאריך 15/09/2011, 20:42
 

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 ' '
על ידי Simon Coggins בתאריך 15/09/2011, 21:29
קבוצה 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