You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Todd O'Bryan <to...@mac.com> on 2005/04/06 05:53:19 UTC

How do I reference Tapestry assets in JavaScript?

I'm trying to convert HtmlArea so that it works with 3.0.3.

For those who don't know, HtmlArea is a great big collection of 
JavaScripts and other crapola that changes a TextArea into a WYSIWYG 
editor. Problem is, there's a main script which tries to load the other 
scripts, images, etc., and has trouble now because it tries to create 
its own URLs on the fly, and these no longer match what Tapestry wants.

I'm more than willing to code assets for all the images, other scripts, 
etc., but how do I reference those assets from inside the JavaScript 
components?

Thanks,
Todd


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


Re: How do I reference Tapestry assets in JavaScript?

Posted by enrico <en...@enricod.it>.
Todd O'Bryan wrote:

> I'm trying to convert HtmlArea so that it works with 3.0.3.
>
> For those who don't know, HtmlArea is a great big collection of 
> JavaScripts and other crapola that changes a TextArea into a WYSIWYG 
> editor. Problem is, there's a main script which tries to load the 
> other scripts, images, etc., and has trouble now because it tries to 
> create its own URLs on the fly, and these no longer match what 
> Tapestry wants.
>
> I'm more than willing to code assets for all the images, other 
> scripts, etc., but how do I reference those assets from inside the 
> JavaScript components?
>
> Thanks,
> Todd
>
Hi Todd,
yesterday I spent a few minutes on HtmlArea component.
I suppose that one possible solution is:

* define every asset in HtmlArea.jwc file (for example:

[...]
    <component id="definitions" type="Script">
        <static-binding 
name="script">HtmlAreaDefinitions.script</static-binding>
         <binding name="url" expression="generatePath(assets.htmlareajs, 
'htmlarea.js')"/>
        
         <binding name="htmlareajs" 
expression="assets.htmlareajs.buildURL(page.requestCycle)"/>
         <binding name="dialogjs" 
expression="assets.dialogjs.buildURL(page.requestCycle)"/>
         <binding name="popupwinjs" 
expression="assets.popupwinjs.buildURL(page.requestCycle)"/>
         <binding name="langjs" 
expression="assets.langjs.buildURL(page.requestCycle)"/>
    </component>

    <private-asset name="htmlareajs" 
resource-path="/org/rz/htmlarea/htmlarea.js"/>
    <private-asset name="dialogjs" 
resource-path="/org/rz/htmlarea/dialog.js"/>
    <private-asset name="popupwinjs" 
resource-path="/org/rz/htmlarea/popupwin.js"/>
    <private-asset name="langjs" 
resource-path="/org/rz/htmlarea/lang/en.js"/>

[...]

* define a variable in HtmlAreaDefinitions.script for each asset,

<![CDATA[
_editor_url="${url}";//how are we gonna work this??? ;)
_editor_lang="en";//note, need fix this later for i18n before uploading 
component to Tassel...

_htmlareajs= "${htmlareajs}";
_dialogjs= "${dialogjs}";
_popupwinjs = ${popupwinjs};
_langjs = ${langjs};

]]>

* modify htmlarea.js so that it uses the variables defined in 
HtmlAreaDefinitions

The problem is that I think that the assets are really a lot!
I still looking for an easier solution ... any idea?

Thanks
Enrico


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


Re: How do I reference Tapestry assets in JavaScript?

Posted by Kent Tong <ke...@cpttm.org.mo>.
Todd O'Bryan <toddobryan <at> mac.com> writes:

> I gather the way to deal with this is to rewrite the script so that all 
> the assets are Tapestry-friendly and include ${ant-like-properties} in 
> the JavaScript files. Unfortunately, the JavaScript file itself is 
> quite a bit beyond me.

Pass an asset URL builder object to the script component. Suppose 
that you have an asset named "foo", to get to its URL in the script:

<input-symbol key="builder">
<body>
var fooURL=${builder.URL['foo']};
var barURL=${builder.URL['bar']};
...
</body>

Of course, you need to create such a builder class:

class AssetURLBuilder {
  private RequestCycle cycle;
  private IComponent assetContainer;

  String getURL(String assetName) {
    return assetContainer.getAsset(assetName).buildURL(cycle);
  }
}




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


Re: How do I reference Tapestry assets in JavaScript?

Posted by Andreas Andreou <an...@di.uoa.gr>.
You can always disable, or override the MD5 checksums (and allow 
everything to pass)
during development,
and during deployment use the auto-deploy of assets feature of Tapestry
(use the org.apache.tapestry.asset.dir property in the .application file)

Todd O'Bryan wrote:

> The component actually has tens of assets (maybe over a hundred), 
> that, in a vanilla HTML page get loaded from the JavaScript by 
> creating a URL. When it was turned into a Tapestry page, the person 
> doing the porting figured out a kludge so that the JavaScript could 
> use the Tapestry URLs to get to the assets. The problem is 3.0.3 needs 
> MD5 checksums to get at assets, so the kludge now fails.
>
> I gather the way to deal with this is to rewrite the script so that 
> all the assets are Tapestry-friendly and include 
> ${ant-like-properties} in the JavaScript files. Unfortunately, the 
> JavaScript file itself is quite a bit beyond me.
>
> Thanks for the suggestions!
> Todd
>
> On Apr 8, 2005, at 6:50 AM, Andreas Andreou wrote:
>
>> In order to get the valid URL for an asset, one has to call
>> String imageURL = getMyAsset().buildURL(cycle);
>> so, he would need to pass the cycle object to the script as well.
>> Or, he could do all this in java code, then set the url string in a 
>> field of his page class and then (in the .html):
>>
>> <span jwcid="@Script" script="..." asset1Url="ognl: asset1Url" 
>> asset2="ognl: asset2Url"/>
>>
>>
>> Kent Tong wrote:
>>
>>> Todd O'Bryan <toddobryan <at> mac.com> writes:
>>>
>>>
>>>> I'm more than willing to code assets for all the images, other 
>>>> scripts, etc., but how do I reference those assets from inside the 
>>>> JavaScript components?
>>>>
>>>
>>> I may not be understanding your question, why not pass
>>> the assets as symbols to the Script component like:
>>>
>>> <span jwcid="@Script" script="..." asset1="ognl: assets.foo" 
>>> asset2="ognl: assets.bar"/>
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>

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


Re: How do I reference Tapestry assets in JavaScript?

Posted by Todd O'Bryan <to...@mac.com>.
The component actually has tens of assets (maybe over a hundred), that, 
in a vanilla HTML page get loaded from the JavaScript by creating a 
URL. When it was turned into a Tapestry page, the person doing the 
porting figured out a kludge so that the JavaScript could use the 
Tapestry URLs to get to the assets. The problem is 3.0.3 needs MD5 
checksums to get at assets, so the kludge now fails.

I gather the way to deal with this is to rewrite the script so that all 
the assets are Tapestry-friendly and include ${ant-like-properties} in 
the JavaScript files. Unfortunately, the JavaScript file itself is 
quite a bit beyond me.

Thanks for the suggestions!
Todd

On Apr 8, 2005, at 6:50 AM, Andreas Andreou wrote:

> In order to get the valid URL for an asset, one has to call
> String imageURL = getMyAsset().buildURL(cycle);
> so, he would need to pass the cycle object to the script as well.
> Or, he could do all this in java code, then set the url string in a 
> field of his page class and then (in the .html):
>
> <span jwcid="@Script" script="..." asset1Url="ognl: asset1Url" 
> asset2="ognl: asset2Url"/>
>
>
> Kent Tong wrote:
>
>> Todd O'Bryan <toddobryan <at> mac.com> writes:
>>
>>
>>> I'm more than willing to code assets for all the images, other 
>>> scripts, etc., but how do I reference those assets from inside the 
>>> JavaScript components?
>>>
>>
>> I may not be understanding your question, why not pass
>> the assets as symbols to the Script component like:
>>
>> <span jwcid="@Script" script="..." asset1="ognl: assets.foo" 
>> asset2="ognl: assets.bar"/>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


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


Re: How do I reference Tapestry assets in JavaScript?

Posted by Andreas Andreou <an...@di.uoa.gr>.
In order to get the valid URL for an asset, one has to call
String imageURL = getMyAsset().buildURL(cycle);
so, he would need to pass the cycle object to the script as well.
Or, he could do all this in java code, then set the url string in a 
field of his page class and then (in the .html):

<span jwcid="@Script" script="..." 
asset1Url="ognl: asset1Url" asset2="ognl: asset2Url"/>


Kent Tong wrote:

>Todd O'Bryan <toddobryan <at> mac.com> writes:
>
>  
>
>>I'm more than willing to code assets for all the images, other scripts, 
>>etc., but how do I reference those assets from inside the JavaScript 
>>components?
>>    
>>
>
>I may not be understanding your question, why not pass
>the assets as symbols to the Script component like:
>
><span jwcid="@Script" script="..." 
>asset1="ognl: assets.foo" asset2="ognl: assets.bar"/>
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>  
>

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


Re: How do I reference Tapestry assets in JavaScript?

Posted by Kent Tong <ke...@cpttm.org.mo>.
Todd O'Bryan <toddobryan <at> mac.com> writes:

> I'm more than willing to code assets for all the images, other scripts, 
> etc., but how do I reference those assets from inside the JavaScript 
> components?

I may not be understanding your question, why not pass
the assets as symbols to the Script component like:

<span jwcid="@Script" script="..." 
asset1="ognl: assets.foo" asset2="ognl: assets.bar"/>




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