Alterations to Javascript code in a block
Permalink
I load the following Javascript into a block:
[code]<script language="javascript">
arr17 = new Array(
["<p> "text text text text" Person Name. . . </p>"],
["<p>"text text text " Person Name. . .</p>"],
["<p>"text text text ". Person Name . . . </p>"]
);
</script>
<div id="arr17"><body onload="function()"></div> [code]
This works fine until I go to edit it when C5 converts the [code]"[code] into (") so that the script cease to work. Is there any way I can disable this function of C5 messing with my code?
Thanking you in advance.
[code]<script language="javascript">
arr17 = new Array(
["<p> "text text text text" Person Name. . . </p>"],
["<p>"text text text " Person Name. . .</p>"],
["<p>"text text text ". Person Name . . . </p>"]
);
</script>
<div id="arr17"><body onload="function()"></div> [code]
This works fine until I go to edit it when C5 converts the [code]"[code] into (") so that the script cease to work. Is there any way I can disable this function of C5 messing with my code?
Thanking you in advance.
so you're entering this directly into a block via the CMS? What block are you using? content or HTML? I'd recommend that if you're code is being changed and you're using the content block, you should try using the HTML block instead.
Thanks for the response. I have tried both the content and HTML blocks. Can't get either to work.
Brian
Brian
I think you may be mistaken about c5 converting " in ("). Firebug does this if you inspect an element, but if you view the real source, it should still be expressed as ". You're problems are probably elsewhere. For example, that whole <body onload="function()"> looks wrong in all sorts of ways. What function are you calling? Where's the closing body tag? And why is the body inside of a div? If you want something to fire on load, you can use the jquery $(function(){ alert('Do Stuff') })
(btw, this forum has a bad way of changing the code that some people paste. if that's what's happened here, then my-bad, and you should attach the code instead)
(btw, this forum has a bad way of changing the code that some people paste. if that's what's happened here, then my-bad, and you should attach the code instead)
Thank you for pointing out my mistake in adapting the piece of JavaScript. Unfortunately I have no JS writing skills and I buy in scripts. Having corrected the error I am still getting the same result. When I create a new area and add a new HTML block it works fine. As soon as I edit C5 converts into ("). I may have made an error but I have checked that I have followed the author's instructions. The full code I am using is as follows.
AAAAA
BBBB
//Extracts from default.php
CCCC
//Code pasted into C5 HTML Block added to "members-say" area
DDDD
//Code that is changed to when "Update button" is pressed
It is beginning to look as if there is no simple solution and, if so, that means I cannot use quotation marks. I would like to know, however, if I can disable C5's habit of deciding what the HTML should be as I would much prefer to make my own mistakes.
Thank you again.
Brian
"
AAAAA
//Contents of file testimonials.js //Do not take or copy this code it is illegal, delete it. If you need very low priced rotators //that rotate like this, go tohttp://www.mooonbaby.com/scripts/absoluterotators.html/... //Copyright Mooonbaby.com. All rights reserved. var lasturl="0"; function endorsements17(){ var randNum = getRand17(); document.getElementById("arr17").innerHTML = arr17[randNum]; setTimeout('endorsements17()',18000); } function getRand17 () { var rnum; var id=Math.round(Math.random()*(arr17.length-1)); rnum = id; if (rnum==lasturl) { rnum = getRand17(); } lasturl=rnum; return rnum; }
BBBB
//Extracts from default.php
<head> <script type="text/javascript" src="<?=$this->getThemePath()?>/scripts/endorsements.js"></script> </head> <body> <div id="endorsements"><? $a = new Area('members-say'); $a->display($c); ?> </div> </body>
CCCC
//Code pasted into C5 HTML Block added to "members-say" area
<h4>Whatour members say</h4> <script language="javascript"> arr17 = new Array( ["<p>"member testimonial text member testimonial text " Name Person. . . </p>"], ["<p>"member testimonial text member testimonial text " Name Person. . . </p>"], ["<p>"member testimonial text member testimonial text " Name Person. . . </p>"], ["<p>"member testimonial text member testimonial text " Name Person. . . </p>"], ["<p>"member testimonial text member testimonial text " Name Person. . .</p>"] ); </script> <div id="arr17"><script type="text/javascript">endorsements17()</script> </div>
DDDD
//Code that is changed to when "Update button" is pressed
<h4>Whatour members say</h4> <script language="javascript"> arr17 = new Array( ["<p>"member testimonial text member testimonial text" Name Person. . . </p>"], ["<p>"member testimonial text member testimonial text" Name Person. . . </p>"], ["<p>"member testimonial text member testimonial text" Name Person. . . </p>"], ["<p>"member testimonial text member testimonial text" Name Person. . . </p>"], ["<p>"member testimonial text member testimonial text" Name Person. . .</p>"] ); </script> <div id="arr17"><script type="text/javascript">endorsements17()</script> </div>
It is beginning to look as if there is no simple solution and, if so, that means I cannot use quotation marks. I would like to know, however, if I can disable C5's habit of deciding what the HTML should be as I would much prefer to make my own mistakes.
Thank you again.
Brian
while I don't really have time to give a lesson on javascript (there are tons of websites out there for that), can I suggest that you try to get this working in a basic HTML document first, and then try to import into concrete? That'll help you isolate where the problem is occurring.
Dear Tony,
You mistake my point.
I sent you the scripts to show you that I have isolated the problem. Frankly, I did so before I went on to this forum.
The scripts I am using have been up and running on my main site for some time. What I am trying to do is to duplicate my site so that other colleagues in different countries can set it up. I have spent about three days going through the process of (a) ensuring the script works perfectly in default.php then (b) transferring it to the HTML block. After repeated tries the reason why it works once but does not work after it is edited is the C5 changes ""e:" into ("), which of course invalidates the script. If you can't do anything about it so be it but my question remains is there any way I can stop C5 doing this?
Regards,
Brian
You mistake my point.
I sent you the scripts to show you that I have isolated the problem. Frankly, I did so before I went on to this forum.
The scripts I am using have been up and running on my main site for some time. What I am trying to do is to duplicate my site so that other colleagues in different countries can set it up. I have spent about three days going through the process of (a) ensuring the script works perfectly in default.php then (b) transferring it to the HTML block. After repeated tries the reason why it works once but does not work after it is edited is the C5 changes ""e:" into ("), which of course invalidates the script. If you can't do anything about it so be it but my question remains is there any way I can stop C5 doing this?
Regards,
Brian
is it possible you're using the content block in source mode? I know tinyMCE (that content block) does change stuff around. the HTML block should not..
There was an issue with the HTML block (the quote symbols were only converted back to the single character quote when you went back to edit a block again). I didn't think there was an issue before because it didn't convert until I edited it again after saving it for the first time.
Try opening up the /concrete/blocks/html/form_setup_html.php and making sure the textarea has htmlentities on it, like:
Try opening up the /concrete/blocks/html/form_setup_html.php and making sure the textarea has htmlentities on it, like:
<div style="text-align: center" > <textarea id="ccm-HtmlContent" name="content" style="width:98%; margin:auto; height:410px;"><?=htmlentities($controllerObj->content, ENT_COMPAT, APP_CHARSET) ?></textarea> </div>
Many thanks for your response. Going that deep into the code is a little advanced for me but I will have a go and see how I get on. Will inform results.
Brian
Brian
I changed /concrete/blocks/html/form_setup_html.php as follows and it works. Many thanks
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); ?> <h2><?php echo t('Add your HTML below:')?></h2> <!--<div style="text-align: center" > <textarea id="ccm-HtmlContent" name="content" style="width:98%; margin:auto; height:410px;"><?php echo $controllerObj->content ?></textarea> </div>--> <div style="text-align: center" > <textarea id="ccm-HtmlContent" name="content" style="width:98%; margin:auto; height:410px;"><?=htmlentities($controllerObj->content, ENT_COMPAT, APP_CHARSET) ?></textarea> </div>