You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Ray <fo...@gmail.com> on 2011/10/20 10:51:18 UTC

Javascript access to Tapestry Image Asset

Hi all,

I need to be able to access an image from javascript using the following
call:

jQuery(button).attr("style", "background-image : url(images/button.png);");

The problem is that this will not work for me in the future as I have a
requirement to change the URL based on locale.

So what I was hoping that perhaps I could use a Tapestry Asset with a fixed
path and access it from javacript.

Is this possible? Any assistance would be greatly appreciated.


Cheers,

Ray.

Re: Javascript access to Tapestry Image Asset

Posted by Muhammad Gelbana <m....@gmail.com>.
I don't think my solution is the best, I wasn't like...thinking out of the
box ! I went straight to solving the probelm while not thinking much about
the awesome framework we are discussing here.

I believe derkoe's solutions is much more better and scalable. Also derkoe's
link says that tapestry will support assets localization.

I say give derkoe's solution a try and in the end, you know best about what
you really need.

On Thu, Oct 20, 2011 at 1:23 PM, Ray <fo...@gmail.com> wrote:

> Hi,
>
> Thanks for the great responses Muhammad and derkoe.
>
> Setting the variable through JavascriptSupport was just the ticket.
>
> Again, thanks for your assistance.
>
>
>
>
> On Thu, Oct 20, 2011 at 10:43 AM, derkoe <
> tapestry.christian.koeberl@gmail.com> wrote:
>
> >
> > Ray Fortycoats wrote:
> > >
> > > Hi all,
> > >
> >
> > Hi Ray!
> >
> >
> > Ray Fortycoats wrote:
> > >
> > > I need to be able to access an image from javascript using the
> following
> > > call:
> > >
> > > jQuery(button).attr("style", "background-image :
> > > url(images/button.png);");
> > >
> > > The problem is that this will not work for me in the future as I have a
> > > requirement to change the URL based on locale.
> > >
> > > So what I was hoping that perhaps I could use a Tapestry Asset with a
> > > fixed
> > > path and access it from javacript.
> > >
> > > Is this possible? Any assistance would be greatly appreciated.
> > >
> > >
> >
> > Yes, it is :)
> >
> > Just inject the asset and use it in your script - see
> > http://tapestry.apache.org/assets.html
> >
> > Code should look something like this:
> >  @Inject
> >  @Path("context:images/button.png")
> >  private Asset button;
> > ...
> >  javaScriptSupport.addScript("jQuery(button).attr('style',
> > 'background-image : url(%s);');", button.toClientURL());
> >
> > --
> > Chris
> >
> > --
> > View this message in context:
> >
> http://tapestry.1045711.n5.nabble.com/Javascript-access-to-Tapestry-Image-Asset-tp4920809p4920940.html
> > Sent from the Tapestry - User mailing list archive at Nabble.com.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>



-- 
*Regards,*
*Muhammad Gelbana
Java Developer*

Re: Javascript access to Tapestry Image Asset

Posted by Ray <fo...@gmail.com>.
Hi,

Thanks for the great responses Muhammad and derkoe.

Setting the variable through JavascriptSupport was just the ticket.

Again, thanks for your assistance.




On Thu, Oct 20, 2011 at 10:43 AM, derkoe <
tapestry.christian.koeberl@gmail.com> wrote:

>
> Ray Fortycoats wrote:
> >
> > Hi all,
> >
>
> Hi Ray!
>
>
> Ray Fortycoats wrote:
> >
> > I need to be able to access an image from javascript using the following
> > call:
> >
> > jQuery(button).attr("style", "background-image :
> > url(images/button.png);");
> >
> > The problem is that this will not work for me in the future as I have a
> > requirement to change the URL based on locale.
> >
> > So what I was hoping that perhaps I could use a Tapestry Asset with a
> > fixed
> > path and access it from javacript.
> >
> > Is this possible? Any assistance would be greatly appreciated.
> >
> >
>
> Yes, it is :)
>
> Just inject the asset and use it in your script - see
> http://tapestry.apache.org/assets.html
>
> Code should look something like this:
>  @Inject
>  @Path("context:images/button.png")
>  private Asset button;
> ...
>  javaScriptSupport.addScript("jQuery(button).attr('style',
> 'background-image : url(%s);');", button.toClientURL());
>
> --
> Chris
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Javascript-access-to-Tapestry-Image-Asset-tp4920809p4920940.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Javascript access to Tapestry Image Asset

Posted by derkoe <ta...@gmail.com>.
Ray Fortycoats wrote:
> 
> Hi all,
> 

Hi Ray!


Ray Fortycoats wrote:
> 
> I need to be able to access an image from javascript using the following
> call:
> 
> jQuery(button).attr("style", "background-image :
> url(images/button.png);");
> 
> The problem is that this will not work for me in the future as I have a
> requirement to change the URL based on locale.
> 
> So what I was hoping that perhaps I could use a Tapestry Asset with a
> fixed
> path and access it from javacript.
> 
> Is this possible? Any assistance would be greatly appreciated.
> 
> 

Yes, it is :)

Just inject the asset and use it in your script - see
http://tapestry.apache.org/assets.html

Code should look something like this:
  @Inject
  @Path("context:images/button.png")
  private Asset button;
...
  javaScriptSupport.addScript("jQuery(button).attr('style',
'background-image : url(%s);');", button.toClientURL());

-- 
Chris

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Javascript-access-to-Tapestry-Image-Asset-tp4920809p4920940.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Javascript access to Tapestry Image Asset

Posted by Muhammad Gelbana <m....@gmail.com>.
Is it possible to find out that path, set it to a JS variable using
JavascriptSupport, and use that variable in ur js files ?

On Thu, Oct 20, 2011 at 10:51 AM, Ray <fo...@gmail.com> wrote:

> Hi all,
>
> I need to be able to access an image from javascript using the following
> call:
>
> jQuery(button).attr("style", "background-image : url(images/button.png);");
>
> The problem is that this will not work for me in the future as I have a
> requirement to change the URL based on locale.
>
> So what I was hoping that perhaps I could use a Tapestry Asset with a fixed
> path and access it from javacript.
>
> Is this possible? Any assistance would be greatly appreciated.
>
>
> Cheers,
>
> Ray.
>



-- 
*Regards,*
*Muhammad Gelbana
Java Developer*