--- a/doc/book/en/development/devweb/js.rst Tue Mar 09 11:00:48 2010 +0100
+++ b/doc/book/en/development/devweb/js.rst Tue Mar 09 11:01:44 2010 +0100
@@ -40,6 +40,21 @@
snippet inline in the html headers. This is quite useful for setting
up early jQuery(document).ready(...) initialisations.
+CubicWeb javascript events
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+* ``server-response``: this event is triggered on HTTP responses (both
+ standard and ajax). The two following extra parameters are passed
+ to callbacks :
+
+ - ``ajax``: a boolean that says if the reponse was issued by an
+ ajax request
+
+ - ``node``: the DOM node returned by the server in case of an
+ ajax request, otherwise the document itself for standard HTTP
+ requests.
+
+
Overview of what's available
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--- a/utils.py Tue Mar 09 11:00:48 2010 +0100
+++ b/utils.py Tue Mar 09 11:01:44 2010 +0100
@@ -12,10 +12,13 @@
import datetime
import random
from uuid import uuid4
+from warnings import warn
from logilab.mtconverter import xml_escape
from logilab.common.deprecation import deprecated
+_MARKER = object()
+
# initialize random seed from current time
random.seed()
@@ -149,15 +152,13 @@
def add_post_inline_script(self, content):
self.post_inlined_scripts.append(content)
- def add_onload(self, jscode, jsoncall=False):
- if jsoncall:
- self.add_post_inline_script(u"""jQuery(CubicWeb).bind('ajax-loaded', function(event) {
+ def add_onload(self, jscode, jsoncall=_MARKER):
+ if jsoncall is not _MARKER:
+ warn('[3.7] specifying jsoncall is not needed anymore',
+ DeprecationWarning, stacklevel=2)
+ self.add_post_inline_script(u"""jQuery(CubicWeb).one('server-response', function(event) {
%s
});""" % jscode)
- else:
- self.add_post_inline_script(u"""jQuery(document).ready(function () {
- %s
- });""" % jscode)
def add_js(self, jsfile):
--- a/web/data/cubicweb.ajax.js Tue Mar 09 11:00:48 2010 +0100
+++ b/web/data/cubicweb.ajax.js Tue Mar 09 11:01:44 2010 +0100
@@ -92,12 +92,9 @@
setFormsTarget(node);
}
loadDynamicFragments(node);
- // XXX simulates document.ready, but the former
- // only runs once, this one potentially many times
- // we probably need to unbind the fired events
- // When this is done, jquery.treeview.js (for instance)
- // can be unpatched.
- jQuery(CubicWeb).trigger('ajax-loaded');
+ // XXX [3.7] jQuery.one is now used instead jQuery.bind,
+ // jquery.treeview.js can be unpatched accordingly.
+ jQuery(CubicWeb).trigger('server-response', [true, node]);
}
/* cubicweb loadxhtml plugin to make jquery handle xhtml response
--- a/web/data/cubicweb.python.js Tue Mar 09 11:00:48 2010 +0100
+++ b/web/data/cubicweb.python.js Tue Mar 09 11:01:44 2010 +0100
@@ -394,4 +394,13 @@
}
};
+jQuery(document).ready(function() {
+ jQuery(CubicWeb).trigger('server-response', [false, document]);
+});
+
+jQuery(CubicWeb).bind('ajax-loaded', function() {
+ log('[3.7] "ajax-loaded" event is deprecated, use "server-response" instead');
+ jQuery(CubicWeb).trigger('server-response', [false, document]);
+});
+
CubicWeb.provide('python.js');