If this is your first visit, check our documentation. To post, register or login.
Forums / Community Contributed Add-Ons / Addon Sideboxes / Adding JavaScript to Blank Sidebox module

Adding JavaScript to Blank Sidebox module

Started by commdiver on 2 Feb 2011, 2:51 PM · Views: 4,747

Results 1 to 20 of 20
2 Feb 2011, 2:51 PM
#1
commdiver avatar

commdiver

Zen Follower

Join Date:
May 2010
Posts:
222
Plugin Contributions:
0

Post #1 by commdiver

Is there a way to add JavaScript to the Blank Sidebox module? If not, is there any other way to add JavaScript to a sidebox?

2 Feb 2011, 9:23 PM
#3
commdiver avatar

commdiver

Zen Follower

Join Date:
May 2010
Posts:
222
Plugin Contributions:
0

Post #3 by commdiver

Thank you! That worked.

14 May 2014, 3:42 PM
#4
plc613 avatar

plc613

Zen Follower

Join Date:
Apr 2014
Location:
Canada
Posts:
249
Plugin Contributions:
0

Post #4 by plc613

Hi.

I'm resurrecting this because I'm trying to accomplish the same or at least similar goal.

As soon as I start adding php and java to tpl_blank_sidebox.php OR blank_sidebox_defines.php my site goes blank(ah! I guess it's going it's job ;))

So my questions are:

-All the posts I've found imply the solution is to escape single quotes. I've tried that. Perhaps some need escaping and others don't...I really don't know. But I know if I escape them all the site still goes blank.

-I've read to avoid putting java in the defines so how do I add it properly?

Here's the codes I'm trying to insert:

<div id="footer-payments">
<center>
  <img src="<?php  echo $template->get_template_dir('',DIR_WS_TEMPLATE, $current_page_base,'images').'/'.FOOTER_PAYMENT_ICON ?>"   alt="payments we accept" class="payments-image" /> 
</center>
</div>
<script type="text/javascript">
    (function() {
        var ss = document.createElement('script'); ss.type = 'text/javascript'; ss.async = true;
        ss.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'seal.ssls.com/script.js?cn=' + window.location.host;
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ss, s);
    })();
    </script>
    <!-- Do not alter for the seal to work properly -->
    <div id="sslsSiteSeal">
        seal by <a href="http://ssls.com/">SSLs.com</a>
    </div>

I've returned both my defines and tpl files to stock at this point.

My dev site is:

dev DOT littlecloset DOT ca

14 May 2014, 4:07 PM
#5
stevesh avatar

stevesh

Black Belt

Join Date:
Feb 2005
Location:
Lansing, Michigan USA
Posts:
19,793
Plugin Contributions:
2

Post #5 by stevesh

Blank pages generally result from PHP errors and create error log files in your /logs folder. Post the contents of the most recent one here.

14 May 2014, 6:09 PM
#6
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Post #6 by gjh42

In general, you would put the script (without <script type="text/javascript"> </script> tags) in a new file named like jscript_siteseal.js, saved in /includes/templates/your_template/jscript/. You can name it as you like as long as it starts with jscript_. ```
(function() {
var ss = document.createElement('script'); ss.type = 'text/javascript'; ss.async = true;
ss.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'seal.ssls.com/script.js?cn=' + window.location.host;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ss, s);
})();

I'm not sure if the ( before function and the )() at the end are good to have there. Someone proficient in javascript would know.


The rest of the code you show would go into either the sidebox define file or tpl_ file. In the tpl_ file, you would assign it to $content like
```php
$content .= '<div id="footer-payments">
<center>
  <img src="' . $template->get_template_dir('',DIR_WS_TEMPLATE, $current_page_base,\'images\') . '/' . FOOTER_PAYMENT_ICON"   alt="payments we accept" class="payments-image" /> 
</center>
</div>';

$content .= '   <!-- Do not alter for the seal to work properly -->
    <div id="sslsSiteSeal">
        seal by <a href="http://ssls.com/">SSLs.com</a>
    </div>';

I have edited the coding format to function correctly in the particular context.

14 May 2014, 6:19 PM
#7
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Post #7 by gjh42

Missed one :)
This bit
$template->get_template_dir('',DIR_WS_TEMPLATE, $current_page_base,'images')
needs either the first '' (two single quotes) escaped (''), or the second set 'images' not escaped ('images'); I forget which at the moment... think the escapes are not needed here. Try it both ways.

15 May 2014, 2:31 PM
#8
plc613 avatar

plc613

Zen Follower

Join Date:
Apr 2014
Location:
Canada
Posts:
249
Plugin Contributions:
0

Post #8 by plc613

Try it both ways.
Didn't help.

Question; is the code suppose to be a continuous line?

15 May 2014, 2:37 PM
#9
plc613 avatar

plc613

Zen Follower

Join Date:
Apr 2014
Location:
Canada
Posts:
249
Plugin Contributions:
0

Post #9 by plc613

In case this will help, here's an entry in the logs I suspect is related to the code:

[15-May-2014 10:09:01 America/New_York] PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/littlecl/HIDDEN/dev/includes/templates/piccadilly_posh/sideboxes/tpl_blank_sidebox.php on line 19

Line 19 is:
$content .= '<div id="footer-payments">

15 May 2014, 2:41 PM
#10
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Post #10 by gjh42

If you use line breaks in the define, they will show in the "view source" of your output. They will not break a define unless you are doing something else wrong.

One of the escaping options will work while the other won't. This means you have some other error in your code. Post your tpl_blank_sidebox.php so we can see exactly how you are adding the content. Also, exactly what you did with the javascript and where.

15 May 2014, 2:49 PM
#11
plc613 avatar

plc613

Zen Follower

Join Date:
Apr 2014
Location:
Canada
Posts:
249
Plugin Contributions:
0

Post #11 by plc613

Thanks for your help.

Here my whole tpl_blank_sidebox.php @ my_template/sideboxes/

<?php
/**
 * blank sidebox - allows a blank sidebox to be added to your site
 *
 * @package templateSystem
 * @copyright 2007 Kuroi Web Design
  * @copyright Portions Copyright 2003-2007 Zen Cart Development Team
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: blank_sidebox.php 2007-05-26 kuroi $
 */

  $content = '';
  $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">';

  // Replace the text and HTML tags between the apostophes on lines 19 and 20.
  // Use as many or as few lines using this model as you need for your custom content.
  // If you have a multilingual site define your text in the languages/YOUR_LANGUAGE/extra_definitions/blank_sidebox_defines.php and include it as shown in line 19.
  // If your site is monolingual, you can put the text right here as shown on line 20 (and nobody will know!)
$content .= '<div id="footer-payments">
<center>
  <img src="' . $template->get_template_dir(\'\',DIR_WS_TEMPLATE, $current_page_base,'images') . '/' . FOOTER_PAYMENT_ICON"   alt="payments we accept" class="payments-image" /> 
</center>
</div>';

$content .= '   <!-- Do not alter for the seal to work properly -->
    <div id="sslsSiteSeal">
        seal by <a href="http://ssls.com/">SSLs.com</a>
    </div>';
?>

And here's my jscript_sslseal.js @ my_template/jscript/

 (function() {
        var ss = document.createElement('script'); ss.type = 'text/javascript'; ss.async = true;
        ss.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'seal.ssls.com/script.js?cn=' + window.location.host;
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ss, s);
    })();
15 May 2014, 6:48 PM
#12
plc613 avatar

plc613

Zen Follower

Join Date:
Apr 2014
Location:
Canada
Posts:
249
Plugin Contributions:
0

Post #12 by plc613

Just for kicks I commented out the payments icons to focus merely on the site seal and the site seal actually works. The positioning is way off but I'm confident I can figure that out on my own. Then I tried the same with the payment icons and even alone, that code breaks the site. One thing I noticed, which is odd to me because that same code worked when it was in the footer, the path is actually images/icons/ not just images. Is it just that perhaps?

16 May 2014, 1:56 AM
#13
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Post #13 by gjh42

You have php <img src="' . $template->get_template_dir(\'\',DIR_WS_TEMPLATE, $current_page_base,'images') . '/' . FOOTER_PAYMENT_ICON" with one escaped set of quotes '' and one unescaped set 'images'. This is guaranteed to fail. Try ```php
<img src="' . $template->get_template_dir('',DIR_WS_TEMPLATE, $current_page_base,'images') . '/' . FOOTER_PAYMENT_ICON"

16 May 2014, 1:10 PM
#14
plc613 avatar

plc613

Zen Follower

Join Date:
Apr 2014
Location:
Canada
Posts:
249
Plugin Contributions:
0

Post #14 by plc613

Well, that was just leftovers from your suggestion in post #7. As was already suggested, I tried with both single quotes & either escaped. None of those options have worked. I also just tried the latest suggest method:

<img src="' . $template->get_template_dir('',DIR_WS_TEMPLATE, $current_page_base,'images') . '/' . FOOTER_PAYMENT_ICON"

to no avail.

16 May 2014, 1:13 PM
#15
plc613 avatar

plc613

Zen Follower

Join Date:
Apr 2014
Location:
Canada
Posts:
249
Plugin Contributions:
0

Post #15 by plc613

Although I've been copying/pasting perhaps there must be a mistake somewhere!? Here are the contents as is directly from my tpl_blank_sidebox.php:

<img src="' . $template->get_template_dir(''',DIR_WS_TEMPLATE, $current_page_base,'images') . '/' . FOOTER_PAYMENT_ICON"   alt="payments we accept" class="payments-image" />
16 May 2014, 1:15 PM
#16
plc613 avatar

plc613

Zen Follower

Join Date:
Apr 2014
Location:
Canada
Posts:
249
Plugin Contributions:
0

Post #16 by plc613

I think I mentioned this already but...Seems to me the images couldn't show up because they're actually in a subfolder of images ie images/icons. Seems to me like that code is only looking for the image files in 'images' no? What contradicts that is that this exact code was functioning in the footer...I just don't understand php enough yet so....

Sorry, I don't know what lead me to think the images were in a subfolder but they are not.

16 May 2014, 2:09 PM
#17
plc613 avatar

plc613

Zen Follower

Join Date:
Apr 2014
Location:
Canada
Posts:
249
Plugin Contributions:
0

Post #17 by plc613

Before anyone wastes more energy on this...

I gave up on the blank_sidebox in lieu of PayPal CreditCards Accepted. I simply split the siteseal snippet between the tpl_paypal_creditcards_sidebox.php and jscript as suggested earlier in this thread.

  $content = '';
  $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">';    
  $content .= '   <!-- Do not alter for the seal to work properly -->
    <div id="sslsSiteSeal">
        seal by <a href="http://ssls.com/">SSLs.com</a>
    </div>';
  $content .= '<p>' . TEXT_PAYPAL_CREDITCARDS_SIDEBOX . '</p>';
  $content .= '</div>';

Don't know why we couldn't get things going with the previous add-on but perhaps by posting this code it may be obvious to someone.

Thank you to everyone who tried so hard to get this working. Much appreciated.

16 May 2014, 4:08 PM
#18
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Post #18 by gjh42

$template->get_template_dir(''',DIR_WS_TEMPLATE,
``` You have three single quotes here instead of two. If this is what was actually in your live file, it would cause an error due to the extra quote.
16 May 2014, 6:23 PM
#19
plc613 avatar

plc613

Zen Follower

Join Date:
Apr 2014
Location:
Canada
Posts:
249
Plugin Contributions:
0

Post #19 by plc613

For what it's worth I had caught that to and removing the third single quote didn't fix the code. I suspect there is something outside the snippets I've shown that was effecting things.