# HG changeset patch # User Sylvain Thénault # Date 1246636807 -7200 # Node ID 79bc598c6411402aafa431e6075b9b9edb077845 # Parent 2c9eceeaae6a0b2c1227cbbfb978ff94f6e37985 when request is a json request, bind on 'ajax-loaded' instead of document.ready() diff -r 2c9eceeaae6a -r 79bc598c6411 utils.py --- a/utils.py Fri Jul 03 17:58:36 2009 +0200 +++ b/utils.py Fri Jul 03 18:00:07 2009 +0200 @@ -206,8 +206,13 @@ def add_post_inline_script(self, content): self.post_inlined_scripts.append(content) - def add_onload(self, jscode): - self.add_post_inline_script(u"""jQuery(document).ready(function () { + def add_onload(self, jscode, jsoncall=False): + if jsoncall: + self.add_post_inline_script(u"""jQuery(CubicWeb).bind('ajax-loaded', function(event) { +%s +});""" % jscode) + else: + self.add_post_inline_script(u"""jQuery(document).ready(function () { %s });""" % jscode) diff -r 2c9eceeaae6a -r 79bc598c6411 web/request.py --- a/web/request.py Fri Jul 03 17:58:36 2009 +0200 +++ b/web/request.py Fri Jul 03 18:00:07 2009 +0200 @@ -453,6 +453,9 @@ # high level methods for HTML headers management ########################## + def add_onload(self, jscode): + self.html_headers.add_onload(jscode, self.json_request) + def add_js(self, jsfiles, localfile=True): """specify a list of JS files to include in the HTML headers :param jsfiles: a JS filename or a list of JS filenames diff -r 2c9eceeaae6a -r 79bc598c6411 web/views/tabs.py --- a/web/views/tabs.py Fri Jul 03 17:58:36 2009 +0200 +++ b/web/views/tabs.py Fri Jul 03 18:00:07 2009 +0200 @@ -24,7 +24,7 @@ """ def _prepare_bindings(self, vid, reloadable): - self.req.html_headers.add_onload(u""" + self.req.add_onload(u""" jQuery('#lazy-%(vid)s').bind('%(event)s', function(event) { load_now('#lazy-%(vid)s', '#%(vid)s-hole', %(reloadable)s); });""" % {'event': 'load_%s' % vid, 'vid': vid, @@ -59,7 +59,7 @@ on dom readyness """ self.req.add_js('cubicweb.lazy.js') - self.req.html_headers.add_onload("trigger_load('%s');" % vid) + self.req.add_onload("trigger_load('%s');" % vid) class TabsMixin(LazyViewMixin): @@ -143,7 +143,7 @@ w(u'') # call the set_tab() JS function *after* each tab is generated # because the callback binding needs to be done before - self.req.html_headers.add_onload(u""" + self.req.add_onload(u""" jQuery('#entity-tabs-%(eeid)s > ul').tabs( { selected: %(tabindex)s }); set_tab('%(vid)s', '%(cookiename)s'); """ % {'tabindex' : tabs.index(active_tab),