Re: Re: T5.5.0-beta-3: document.observe is not a function

2020-02-14 Thread Cezary Biernacki
I am glad to help.

As I wrote, I didn't test codes, so there are some bugs in them. In case
somebody having a similar problem, there is an errata:

In Step 1, missing a line at the end of code block, like this:

})();


In Step 3. instead of "display-content.js" it should be without ".js",
javaScriptSupport.require("display-content");


Best regards,
Cezary

On Fri, Feb 14, 2020 at 10:19 AM Lothar Nieswandt 
wrote:

> Hi Cezary,
>
> thanks a lot for the quick reply. I didn't get the first solution to work,
> but never mind. Avoiding prototype in the first place (your offered second
> solution) did the trick, so thanks a lot.
>
> Lothar
>
>
> Gesendet: Mittwoch, 12. Februar 2020 um 19:13 Uhr
> Von: "Cezary Biernacki" 
> An: "Tapestry users" 
> Betreff: Re: T5.5.0-beta-3: document.observe is not a function
> Hi,
> I don't use T5.5, but probably your code would fail in T5.4 as well.
> Tapestry puts JavaScript loading at the end of , as it is a general
> best practice for improving page loading times.
>
> I would change this in the following way:
>
> ---
> 1. Move JS code to a separate file that works as a module. Put following
> code in META-INF/modules/display-content.js in your resources folder
> (normally src/main/resources)
>
> (function() {
> define(["t5/core/dom"], function() {
>
> document.observe("dom:loaded", function() {
>
> $("content").style.display = 'block';
>
> });
>
> }
> )
>
>
> 2. Remove the offending block "  ... " from your ".tml"
> file
>
> 3. In Java class that it is related to the .tml file from step 2, add
> inclusion of display-content.js
>
> @Inject
> private JavaScriptSupport javaScriptSupport;
>
> @BeginRender
> void addDisplayContent(final MarkupWriter writer) {
> javaScriptSupport.require("display-content.js");
> }
>
> ---
>
> As far as I can tell, these changes should work in Tapestry 5.4 and
> Tapestry 5.5. An alternative approach, is to rewrite JavaScript code in
> .tml to use plain DOM, instead of any external library, like:
>