0

I am creating a functionality where a user presses a button (Print Timetable) and then a popup window appears with a page showing their timetable and then the printing options automatically appear. However, when the popup is still loading the timetable I want to display an animated GIF. The timetable in the popup isn't fetched with AJAX so I can't use ajax start and stop so how would I do this then?

<input type="button" value="Print Timetable" class="printButton" onclick="window.open(url, ' _parent','height=550, width=800');"/>

This is what is happening so far in the timetable popup:

<div id="animated-logo" class="animated-logo">
    <a href="/" title="Print your timetable">Test</a>
</div>

<script  type="text/javascript">
        $('.animated-logo').addClass('logo');
        $('.animated-logo').removeClass('animated-logo');
    if (window.print){ self.print();}

</script>

Obviously, that animated gif isn't going to work but it's a start.

Any help would be great. Thanks!

Johnathan Au
  • 5,244
  • 18
  • 70
  • 128

1 Answers1

2

Have a look at jQuery's load() over here.

HTML

 <div id="" class="itm-animated-logo">
        <a href="/" title="Print your timetable">Test</a>
        <div id="time-table">...</div>
    </div>

jQuery

$("#time-table").load(function() {
  $(this).parent().removeClass("itm-animated-logo");
}

CSS

.itm-animated-logo {background-image: loading.gif;}

So when the pop-up is loaded (with class itm-animated-logo), its background will be the loading.gif file. As soon as your time table is loaded (#time-table) the class of the pop-up will be removed and the background, subsequently, as well.

The downside of this may be that parts of the time table will get loaded (so the time table gets loaded in chunks) in which case they will be 'on top of' the background-image. To fix this you can make an extra div. Maybe this solution is even better:

HTML

 <div id="" class="itm-animated-logo">
        <div id="loading"><img src="loading.gif" alt="Loading your time table" height="32" width="32" /></div>
        <a href="/" title="Print your timetable">Test</a>
        <div id="time-table">...</div>
    </div>

jQuery

$("#time-table").load(function() {
  $(this).parent().children("#loading").fadeOut("slow");
}

CSS

#loading {
   display: block;
   width: 32px;
   height: 32px;
   margin: 50px auto;
   padding: 0;
} 
Bram Vanroy
  • 27,032
  • 24
  • 137
  • 239
  • Hey thanks, I was trying document.readyState before, clearly not the way to go about it. This is perfect, thanks. – Johnathan Au May 22 '12 at 11:25
  • @Johnathan-au I have edited the answer. Maybe this is a better answer for your needs. Also, if this answer suits your needs, please mark it as such by clicking the green 'wink'! – Bram Vanroy May 22 '12 at 11:27
  • Ah yes sorry, it didn't let me accept it because I voted it up. – Johnathan Au May 22 '12 at 11:35