author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Mon, 08 Mar 2010 19:11:47 +0100 | |
changeset 4830 | 10e8bc190695 |
parent 4437 | 21f2e01fdd6a |
child 5151 | 2f70fa8b6854 |
permissions | -rw-r--r-- |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
1 |
.. -*- coding: utf-8 -*- |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
2 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
3 |
Javascript |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
4 |
---------- |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
5 |
|
3283 | 6 |
*CubicWeb* uses quite a bit of javascript in its user interface and |
7 |
ships with jquery (1.3.x) and parts of the jquery UI |
|
8 |
library, plus a number of homegrown files and also other thirparty |
|
9 |
libraries. |
|
10 |
||
11 |
All javascript files are stored in cubicweb/web/data/. There are |
|
12 |
around thirty js files there. In a cube it goes to data/. |
|
13 |
||
14 |
Obviously one does not want javascript pieces to be loaded all at |
|
15 |
once, hence the framework provides a number of mechanisms and |
|
16 |
conventions to deal with javascript resources. |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
17 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
18 |
Conventions |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
19 |
~~~~~~~~~~~ |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
20 |
|
3283 | 21 |
It is good practice to name cube specific js files after the name of |
22 |
the cube, like this : 'cube.mycube.js', so as to avoid name clashes. |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
23 |
|
3283 | 24 |
XXX external_resources variable (which needs love) |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
25 |
|
3441 | 26 |
CubicWeb javascript api |
3581
669854258b90
[doc] various fixes
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3441
diff
changeset
|
27 |
~~~~~~~~~~~~~~~~~~~~~~~ |
3283 | 28 |
|
29 |
Javascript resources are typically loaded on demand, from views. The |
|
4437
21f2e01fdd6a
update exemples using the 3.6 api and add/fix some sections (schema, vreg, talk about CW_MODE in concepts...). So much to do :'(
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3581
diff
changeset
|
30 |
request object (available as self._cw from most application objects, |
3283 | 31 |
for instance views and entities objects) has a few methods to do that: |
32 |
||
33 |
* `add_js(self, jsfiles, localfile=True)` which takes a sequence of |
|
34 |
javascript files and writes proper entries into the HTML header |
|
35 |
section. The localfile parameter allows to declare resources which |
|
36 |
are not from web/data (for instance, residing on a content delivery |
|
37 |
network). |
|
38 |
||
39 |
* `add_onload(self, jscode)` which adds one raw javascript code |
|
40 |
snippet inline in the html headers. This is quite useful for setting |
|
41 |
up early jQuery(document).ready(...) initialisations. |
|
42 |
||
4830
10e8bc190695
[javascript] fix #736185: add_onload / jQuery.bind() vs. jQuery.one()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4437
diff
changeset
|
43 |
CubicWeb javascript events |
10e8bc190695
[javascript] fix #736185: add_onload / jQuery.bind() vs. jQuery.one()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4437
diff
changeset
|
44 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
10e8bc190695
[javascript] fix #736185: add_onload / jQuery.bind() vs. jQuery.one()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4437
diff
changeset
|
45 |
|
10e8bc190695
[javascript] fix #736185: add_onload / jQuery.bind() vs. jQuery.one()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4437
diff
changeset
|
46 |
* ``server-response``: this event is triggered on HTTP responses (both |
10e8bc190695
[javascript] fix #736185: add_onload / jQuery.bind() vs. jQuery.one()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4437
diff
changeset
|
47 |
standard and ajax). The two following extra parameters are passed |
10e8bc190695
[javascript] fix #736185: add_onload / jQuery.bind() vs. jQuery.one()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4437
diff
changeset
|
48 |
to callbacks : |
10e8bc190695
[javascript] fix #736185: add_onload / jQuery.bind() vs. jQuery.one()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4437
diff
changeset
|
49 |
|
10e8bc190695
[javascript] fix #736185: add_onload / jQuery.bind() vs. jQuery.one()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4437
diff
changeset
|
50 |
- ``ajax``: a boolean that says if the reponse was issued by an |
10e8bc190695
[javascript] fix #736185: add_onload / jQuery.bind() vs. jQuery.one()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4437
diff
changeset
|
51 |
ajax request |
10e8bc190695
[javascript] fix #736185: add_onload / jQuery.bind() vs. jQuery.one()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4437
diff
changeset
|
52 |
|
10e8bc190695
[javascript] fix #736185: add_onload / jQuery.bind() vs. jQuery.one()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4437
diff
changeset
|
53 |
- ``node``: the DOM node returned by the server in case of an |
10e8bc190695
[javascript] fix #736185: add_onload / jQuery.bind() vs. jQuery.one()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4437
diff
changeset
|
54 |
ajax request, otherwise the document itself for standard HTTP |
10e8bc190695
[javascript] fix #736185: add_onload / jQuery.bind() vs. jQuery.one()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4437
diff
changeset
|
55 |
requests. |
10e8bc190695
[javascript] fix #736185: add_onload / jQuery.bind() vs. jQuery.one()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4437
diff
changeset
|
56 |
|
10e8bc190695
[javascript] fix #736185: add_onload / jQuery.bind() vs. jQuery.one()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4437
diff
changeset
|
57 |
|
3283 | 58 |
Overview of what's available |
59 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
60 |
||
61 |
* jquery.* : jquery and jquery UI library |
|
62 |
||
63 |
* cubicweb.python.js : adds a number of practical extension to stdanrd |
|
64 |
javascript objects (on Date, Array, String, some list and dictionary |
|
65 |
operations), and a pythonesque way to build classes. Defines a |
|
66 |
CubicWeb namespace. |
|
67 |
||
68 |
* cubicweb.htmlhelpers.js : a small bag of convenience functions used |
|
69 |
in various other cubicweb javascript resources (baseuri, progress |
|
70 |
cursor handling, popup login box, html2dom function, etc.) |
|
71 |
||
72 |
* cubicweb.ajax.js : concentrates all ajax related facilities (it |
|
73 |
extends jQuery with the loahxhtml function, provides a handfull of |
|
74 |
high-level ajaxy operations like asyncRemoteExec, reloadComponent, |
|
75 |
replacePageChunk, getDomFromResponse) |
|
76 |
||
77 |
* cubicweb.widgets.js : provides a widget namespace and constructors |
|
78 |
and helpers for various widgets (mainly facets and timeline) |
|
79 |
||
80 |
* cubicweb.edition.js : used by edition forms |
|
81 |
||
82 |
* cubicweb.preferences.js : used by the preference form |
|
83 |
||
84 |
* cubicweb.facets.js : used by the facets mechanism |
|
85 |
||
86 |
xxx massmailing, gmap, fckcwconfig, timeline-bundle, timeline-ext, |
|
87 |
calendar, goa, flotn tazy, tabs, bookmarks |