Display loading image before sending asynchronous requests

15 views
Skip to first unread message

Amine Salmen Rekik

unread,
Jun 5, 2014, 7:41:58 AM6/5/14
to nagare...@googlegroups.com

Hello,

I need to display a loading image when the browser sends an asynchronous request to the server.

When using the jQuery plugin, we can handle .ajaxStart() and .ajaxStop() events to display and hide the image.

So I want to know if We can configure nagare to use jQuery when sending asynchronous request?

Thanks

Alain Poirier

unread,
Jun 5, 2014, 11:08:38 AM6/5/14
to nagare...@googlegroups.com
Hi Amine,
The YUI Connection Manager also fires events: http://yui.github.io/yui2/docs/yui_2.9.0_full/connection/index.html#customevents

Here is a little example:

import time
from nagare import component, presentation

class Counter(object):
def __init__(self):
self.v = 0

def increase(self):
time.sleep(3) # Take some times to complete

self.v += 1

@presentation.render_for(Counter)
def render(self, h, *args):
h << h.div(self.v)
h << h.a('++').action(self.increase)

return h.root

# ---

class App(object):
def __init__(self):
self.counter = component.Component(Counter())

@presentation.render_for(App)
def render(self, h, *args):
h << h.script('''
var YUC = YAHOO.util.Connect;

YUC.startEvent.subscribe(function(e) {
document.body.setAttribute("style", "background-color: #5C5C5C");
});

YUC.completeEvent.subscribe(function(e) {
document.body.removeAttribute("style");
});
''')

h << self.counter.render(h.AsyncRenderer())

return h.root

Best regards,
Alain

> Thanks

Amine Salmen Rekik

unread,
Jun 5, 2014, 11:24:39 AM6/5/14
to nagare...@googlegroups.com
That's great ! Thank you
Reply all
Reply to author
Forward
0 new messages