If you have the javascript in your php file you can interject php syntax
just like html

ie. $.preloadImages("<?php echo $image_src; ?>", "img/

if your javascript is in a separate .js file you have two options

1. Change the javascript function to allow you to specify anything dynamic
(ie. the images that will need to be preloaded) in a parameter which you can
pass from your php file when you call the function using the method above

or

2. (Not Recommended) Set up your web server to run .js files through the PHP
parser.  Then you can use php syntax in the .js files



On Mon, Nov 23, 2009 at 6:31 AM, thomaus <[email protected]> wrote:

> Hi there,
>
> I've been using CakePHP since 6 months and never had a single problem
> BUT now I have one issue I can't solve. Here it is:
>
> I need to Preload some images for my website. I did it using JQuery
> and it perfectly works:
>
> CODE
> $(document).ready(function(){
>
> // Preload
> $.preloadImages("img/button_home_en_over.gif", "img/
> button_portfolio_en_over.gif", "img/button_about_en_over.gif", "img/
> button_contact_en_over.gif",
> "img/button_portfolio_en_select_over.gif", "img/
> button_about_en_select_over.gif", "img/
> button_contact_en_select_over.gif",
> "img/button_home_es_over.gif", "img/button_portfolio_es_over.gif",
> "img/button_about_es_over.gif", "img/button_contact_es_over.gif",
> "img/button_portfolio_es_select_over.gif", "img/
> button_about_es_select_over.gif", "img/
> button_contact_es_select_over.gif",
> "img/button_home_ca_over.gif", "img/button_portfolio_ca_over.gif",
> "img/button_about_ca_over.gif", "img/button_contact_ca_over.gif",
> "img/button_portfolio_ca_select_over.gif", "img/
> button_about_ca_select_over.gif", "img/
> button_contact_ca_select_over.gif",
> "img/button_home_fr_over.gif", "img/button_portfolio_fr_over.gif",
> "img/button_about_fr_over.gif", "img/button_contact_fr_over.gif",
> "img/button_portfolio_fr_select_over.gif", "img/
> button_about_fr_select_over.gif", "img/
> button_contact_fr_select_over.gif"
> );
>
> // hover
> $("#menu_buttons a img").hover(function() {
>    $(this).attr("src", $(this).attr("src").split(".").join
> ("_over."));
>  }, function() {
>    $(this).attr("src", $(this).attr("src").split("_over.").join
> ("."));
>  });
> });
>
> // Preload function
> jQuery.preloadImages = function()
> {
> for(var i = 0; i<arguments.length; i++)
> {
>  //alert(arguments[i]);
>  jQuery("<img>").attr("src", arguments[i]);
> }
> }
>
>
> Now I would like to preload some of the images and not all of them
> cause 1) it's taking ages 2) I just need some them depending of the
> language I use. But in order to do so, I should be able to access some
> PHP variables from my JQuery script.
>
> So my question is: is there a way in CakePHP to pass variables to
> Javascript / JQuery???
>
> Thanks in advance.
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<cake-php%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/cake-php?hl=.
>
>
>

--

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=.


Reply via email to