java problems

Permalink
THIS POST OCCURRED BECAUSE I DIDN'T KNOW ABOUT [CDATA] tags. For anyone else who encounters the same problem, see:http://en.wikipedia.org/wiki/CDATA...

I freaked out when I saw that concrete had commented out stuff I didn't add, but it turns out it is not odd to encounter commented out [CDATA] tags within <script> tags in an html document.

ORIGINAL POST FOLLOWS

I am using the html helper in a block controller to put a script in the header, but instead of what I want:
<script type="text/javascript"> Recoverscroll.start(); </script>


I get this(!):
<script type="text/javascript">/*<![CDATA[*/RecoverScroll.start();/*]]>*/</script>


Clearly I am doing something wrong. But what?

I am using the following object to send the information to the header

The code in my block looks like this:
public function on_page_view() {
    $html=Loader::helper('html');
    $this->addHeaderItem($html>javascript('recoverscroll.js'));
    $script=<<<EOT
RecoverScroll.start();
EOT;
    $this->addHeaderItem($html->script($script));
}

 
JohntheFish replied on at Permalink Reply
JohntheFish
The line
$this->addHeaderItem($html>javascript('recoverscroll.js'));


Should be
$this->addHeaderItem($html->javascript('recoverscroll.js'));
wclark07 replied on at Permalink Reply
Oh, sorry, actually that's OK in the code in the block controller, when I copied it in, the line broke at the arrow and in correcting it I deleted that part. Here is the code pasted directly from the block controller unmodified

<?php defined('C5_EXECUTE') or die(_("Access Denied."));
class BasicTestBlockController extends BlockController {
        protected $btTable = 'btBasicTest';
   protected $btInterfaceWidth = "350";
   protected $btInterfaceHeight = "300";
        public function on_page_view() {
                 $html=Loader::helper('html');
                 $this->addHeaderItem($html->javascript('recoverscroll.js'));
                 $script=<<<EOT
RecoverScroll.start();
EOT;
                 $this->addHeaderItem($html->script($script));
        }



I have recoverscroll.js saved in /js
wclark07 replied on at Permalink Reply
Here is the relevant output in the header from the page source:

<script type="text/javascript" src="/concrete/js/recoverscroll.js?v=d16b78068fc05c90cfbc6e805a61c80d"></script>
<script type="text/javascript">/*<![CDATA[*/RecoverScroll.start();/*]]>*/</script>
JohntheFish replied on at Permalink Reply
JohntheFish
Try:
$script=<<<EOT
<script type="text/JavaScript">
RecoverScroll.start();
</script>
EOT;
$this->addHeaderItem($script);


You will also probably want to wrap the code in a jquery ready handler, or at least a closure.

Once you have it working, you should also swap it to use addFooterItem() for better overall page loading time.
JohntheFish replied on at Permalink Reply
JohntheFish
You have marked this as resolved. Can you post what the eventual solution was please.
wclark07 replied on at Permalink Reply
1. I have removed the RESOLVED. I added it because I didn't want to bother anyone else with my questions about CDATA tags.

2. Using HEREDOC and passing the script directly into the header(as you recommended), rather than using the script method (which I now realize is meant to include only the location of the script) and "" did indeed solve the character data issue.

3. However, I still haven't gotten the script working properly. It runs, records the current scroll position, and stores it as a cookie, but isn't performing its main function, which is to return the browser to its previous scroll position after a page refresh from a form submit.

4. I have to learn more about java and jquery in order to do all you have recommended, but as soon as I do all of that, (which may be a few days) I will post everything here and restore the RESOLVED.