You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by John <jo...@quivinco.com> on 2014/05/20 08:40:31 UTC

js executes before dom ready?

Hi,

I'm finding that a js component that manipulates the dom during initialisation behaves irratically. I'm wondering if the tapestry initiialising in the js executes before the dom is fully ready?

Are there any tips for making sure js executes when the page is ready?

John

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

Re: js executes before dom ready?

Posted by John <jo...@quivinco.com>.
No the markup is all in the component template, the js just needs to add a value to a div inside a table cell (see below). Sometimes I am not seeing this happen, mostly it does. I ask because I got the impression that adding a js alert to the piece of code to debug it seemed to make the code work consistently.

John



(function($) {

    T5.extendInitializers(function() {

        var times = null;
        var settime = null;
        var eventLink = null;

        function clickmin(event, ui) {
            if (settime) {
                var el = '#time_' + parseInt(settime.split(':')[0]);
                $(el).text('');
            }
            settime = event.data.time;
            el = '#time_' + parseInt(settime.split(':')[0]);
            $.ajax({url: eventLink,
                type: 'POST',
                data: {time: settime},
                dataType: 'html',
                success: function(data) {
                    $(el).text(settime);
                }
            });
        }

        function init(specs) {
            $links = $('minsel ul.minitems li a');
            times = specs.times;
            settime = specs.settime;
            eventLink = specs.eventLink;

            $('minsel').hide();
            $('minsel').bind('click', function(event, ui) {
                $('minsel').hide();
            });
            if (settime) {
                var el = '#time_' + parseInt(settime.split(':')[0]);
                $(el).text(settime);                                               // THIS SOMETIMES FAILS!!
            }

            for (var h = 0; h < 24; h++) {
                var el = '#hour_' + h;
                $(el).bind('click', {hour: h}, function(event, ui) {
                    var min = 0, show = false;
                    var hour = String('00000' + event.data.hour).slice(-2) + ":";
                    $('#timesel').text(hour + '??');
                    $links.each(function(index) {
                        $(this).attr('data-index', index);
                        var time = hour + String('00000' + min).slice(-2);
                        $(this).hide();
                        $(this).unbind('click');
                        if ($.inArray(time, times) !== -1) {
                            $(this).bind('click', {time: time}, clickmin);
                            $(this).show();
                            show = true;
                        }
                        if (time === settime) {
                            if (!show) {
                                $(this).show();
                                show = true;
                            }
                            $('#timesel').text(settime);
                        }
                        min = min + 5;
                    });
                    if (show) {
                        $('minsel').show();
                    }
                });
            }
        }

        return {
            diarytimepicker: init
        };
    });

})(jQuery);



  ----- Original Message ----- 
  From: Thiago H de Paula Figueiredo 
  To: Tapestry users 
  Sent: Tuesday, May 20, 2014 2:02 PM
  Subject: Re: js executes before dom ready?


  On Tue, 20 May 2014 03:40:31 -0300, John <jo...@quivinco.com> wrote:

  > Hi,

  Hi!

  > I'm finding that a js component that manipulates the dom during  
  > initialisation behaves irratically. I'm wondering if the tapestry  
  > initiialising in the js executes before the dom is fully ready?

  No, that's not correct. Is this erratic code dealing with HTML elements  
  created by other JS code?

  > Are there any tips for making sure js executes when the page is ready?

  Just call your JS code using JavaScriptSupport methods.

  -- 
  Thiago H. de Paula Figueiredo
  Tapestry, Java and Hibernate consultant and developer
  http://machina.com.br

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


---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

Re: js executes before dom ready?

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 20 May 2014 03:40:31 -0300, John <jo...@quivinco.com> wrote:

> Hi,

Hi!

> I'm finding that a js component that manipulates the dom during  
> initialisation behaves irratically. I'm wondering if the tapestry  
> initiialising in the js executes before the dom is fully ready?

No, that's not correct. Is this erratic code dealing with HTML elements  
created by other JS code?

> Are there any tips for making sure js executes when the page is ready?

Just call your JS code using JavaScriptSupport methods.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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