Changes for page XWiki JavaScript API

Last modified by Simon Urli on 2022/09/14

<
From version < 9.1 >
edited by Sergiu Dumitriu
on 2010/11/06
To version < 8.1 >
edited by Ecaterina Moraru (Valica)
on 2010/11/05
>
Change comment: Added AjaxSuggest xwiki:suggest:selected event

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.Sergiu
1 +XWiki.evalica
Syntax
... ... @@ -1,1 +1,1 @@
1 -XWiki 2.0
1 +XWiki 1.0
Content
... ... @@ -1,22 +3,16 @@
1 -{{velocity filter="none"}}
2 -{{html clean="false" wiki="true"}}
3 3  #startfloatingbox()
4 -**Contents:**
5 -
6 -{{toc start="" depth="" numbered=""/}}
2 +*Contents:*
3 +#toc("" "" "")
7 7  #endfloatingbox()
8 -{{/html}}
9 -{{/velocity}}
5 +1 XWiki JavaScript API
10 10  
11 -= XWiki JavaScript API =
7 +1.1 Observable XWiki Events
12 12  
13 -== Observable XWiki Events ==
14 -
15 15  Stay in touch with what happens in the wiki! XWiki will fire custom javascript events on certain moment and upon certain actions that occur in the navigation flow.
16 16  
17 -Event names are build on the following model: ##xwiki:modulename:eventname##. Your JavaScript script or extension can get notified of such an event the following way:
11 +Event names are build on the following model: <tt>xwiki:modulename:eventname</tt>. Your JavaScript script or extension can get notified of such an event the following way:
18 18  
19 -{{code}}
13 +{code}
20 20  document.observe("xwiki:modulename:eventname", function(event){
21 21   // Here, do something that will be executed at the moment the event is fired
22 22   doSomething();
... ... @@ -23,51 +23,51 @@
23 23  
24 24   // The event can have an option memo object to pass to its observers some information:
25 25   console.log(event.memo.somethingINeedToKnow);
26 -});
27 -{{/code}}
20 +});
21 +{code}
28 28  
29 -Check out the real examples below, or [[read more>>http://prototypejs.org/api/element/fire]] about Prototype.js's event system
23 +Check out the real examples below, or [read more>http://prototypejs.org/api/element/fire] about Prototype.js's event system
30 30  
31 -=== DOM Events (xwiki.js) ===
25 +1.1.1 DOM Events (xwiki.js)
32 32  
33 -* **##xwiki:dom:loading##**
34 -* **##xwiki:dom:loaded##**
27 +* *<tt>xwiki:dom:loading</tt>*
28 +* *<tt>xwiki:dom:loaded</tt>*
35 35  
36 -These events are similar to [[prototype's dom:loaded event>>http://www.prototypejs.org/api/document/observe]], with the difference that in the time-lapse between ##dom:loaded## and ##xwiki:dom:loaded##, XWiki may have transformed the DOM. Example of DOM transformations operated by XWiki is setting the right target of links that have rel="external" attribute so that the document can be XHTML valid and still have the desired effect. In the future there might be more transformations operated by XWiki upon DOM initialization. This event is meant for code to be notified of loading of the XWiki-transformed version of the initial DOM. As ##dom:loaded##, it can be used as follow:
30 +These events are similar to [prototype's dom:loaded event>http://www.prototypejs.org/api/document/observe], with the difference that in the time-lapse between <tt>dom:loaded</tt> and <tt>xwiki:dom:loaded</tt>, XWiki may have transformed the DOM. Example of DOM transformations operated by XWiki is setting the right target of links that have rel="external" attribute so that the document can be XHTML valid and still have the desired effect. In the future there might be more transformations operated by XWiki upon DOM initialization. This event is meant for code to be notified of loading of the XWiki-transformed version of the initial DOM. As <tt>dom:loaded</tt>, it can be used as follow:
37 37  
38 -{{code}}
32 +{code}
39 39  document.observe("xwiki:dom:loaded", function(){
40 40   // Initialization that can rely on the fact the DOM is XWiki-tranformed goes here.
41 41  });
42 -{{/code}}
36 +{code}
43 43  
44 -**It is recommended to bind startup scripts to this event** instead of ##window.load## or ##document.dom:loaded##.
38 +*It is recommended to bind startup scripts to this event* instead of <tt>window.load</tt> or <tt>document.dom:loaded</tt>.
45 45  
46 -##xwiki:dom:loading## is sent between ##dom:loaded## and ##xwiki:dom:loaded##, before XWiki changes the DOM. This is the event that should start all scripts making important DOM changes that other scripts should see.
40 +<tt>xwiki:dom:loading</tt> is sent between <tt>dom:loaded</tt> and <tt>xwiki:dom:loaded</tt>, before XWiki changes the DOM. This is the event that should start all scripts making important DOM changes that other scripts should see.
47 47  
48 -=== Document content events (actionButtons.js) ===
42 +1.1.1 Document content events (actionButtons.js)
49 49  
50 -* **##xwiki:document:saved##**
44 +* *<tt>xwiki:document:saved</tt>*
51 51  
52 -This is event is sent after the document has been successfully saved in an asynchronous request (i.e. after clicking the //Save and Continue// button).
46 +This is event is sent after the document has been successfully saved in an asynchronous request (i.e. after clicking the ~~Save and Continue~~ button).
53 53  
54 -* **##xwiki:document:saveFailed##**
48 +* *<tt>xwiki:document:saveFailed</tt>*
55 55  
56 -=== Action events (actionButtons.js) ===
50 +1.1.1 Action events (actionButtons.js)
57 57  
58 -* **##xwiki:actions:cancel##**
52 +* *<tt>xwiki:actions:cancel</tt>*
59 59  
60 60  This event is sent after the user clicks the "Cancel" button of an editor (Wiki, WYSIWYG, object, rights, etc.), but before actually cancelling the edit.
61 61  
62 -* **##xwiki:actions:preview##**
56 +* *<tt>xwiki:actions:preview</tt>*
63 63  
64 64  This event is sent after ther use clicks the "Preview" button of an editor (Wiki, WYSIWYG, object, rights, etc.), but before actually leaving the edit mode.
65 65  
66 -* **##xwiki:actions:save##**
60 +* *<tt>xwiki:actions:save</tt>*
67 67  
68 -This event is sent after the user clicks the "Save" or "Save & Continue" button of an editor (Wiki, WYSIWYG, object, rights, etc.), but before actually submitting the form. A memo is available if you need to know if the intend is to continue after the save, in ##event.memo.continue##. You can use it as follows:
62 +This event is sent after the user clicks the "Save" or "Save & Continue" button of an editor (Wiki, WYSIWYG, object, rights, etc.), but before actually submitting the form. A memo is available if you need to know if the intend is to continue after the save, in <tt>event.memo.continue</tt>. You can use it as follows:
69 69  
70 -{{code}}
64 +{code}
71 71  document.observe("xwiki:dom:loaded", function(event){
72 72   var doContinue = event.memo.continue;
73 73   if (doContinue) {
... ... @@ -74,17 +74,17 @@
74 74   // do something specific
75 75   }
76 76  });
77 -{{/code}}
71 +{code}
78 78  
79 79  All these events contain as extra information, in the second parameter sent to event listeners (the memo), the original click event (if any, and which can be stopped to prevent the action from completing), and the form being submitted.
80 80  
81 -=== Document extra events (xwiki.js) ===
75 +1.1.1 Document extra events (xwiki.js)
82 82  
83 -* **##xwiki:docextra:loaded##**
77 +* *<tt>xwiki:docextra:loaded</tt>*
84 84  
85 85  This event is fired upon reception of the content of a document footer tab by AJAX. This event is useful if you need to operate transformations of the received content. You can filter on which tab content to operate (comments or attachment or information or ...) using the event memo. The DOM element in which the retrieved content has been injected is also passed to facilitate transformations.
86 86  
87 -{{code}}
81 +{code}
88 88  document.observe("xwiki:docextra:loaded", function(event){
89 89   var tabID = event.memo.id;
90 90   if (tabID == "attachments") {
... ... @@ -92,38 +92,39 @@
92 92   doSomething(event.memo.element);
93 93   }
94 94  });
95 -{{/code}}
89 +{code}
96 96  
97 -* **##xwiki:docextra:activated##**
91 +* *<tt>xwiki:docextra:activated</tt>*
98 98  
99 -This event is fired upon activation of a tab. It differs from the loaded event since tabs are loaded only once if the user clicks going back and forth between tabs. This event will notify of each tab activation, just after the tab content is actually made visible. The tab ID is passed in the memo as for ##xwiki:docextra:loaded##
93 +This event is fired upon activation of a tab. It differs from the loaded event since tabs are loaded only once if the user clicks going back and forth between tabs. This event will notify of each tab activation, just after the tab content is actually made visible. The tab ID is passed in the memo as for <tt>xwiki:docextra:loaded</tt>
100 100  
101 -=== WYSIWYG events (XWikiWysiwyg.js) ===
95 +1.1.1 WYSIWYG events (XWikiWysiwyg.js)
102 102  
103 -WYSIWYG has it's own custom [[events list>>http://code.xwiki.org/xwiki/bin/view/Modules/WysiwygEditorModule#HCustomevents]].
97 +WYSIWYG has it's own custom [events list>http://code.xwiki.org/xwiki/bin/view/Modules/WysiwygEditorModule#HCustomevents].
104 104  
105 -=== Suggest events (ajaxSuggest.js) ===
99 +1.1.1 Suggest events (ajaxSuggest.js)
106 106  
107 -* **##xwiki:suggest:selected##** (since 2.3)
101 +* *<tt>xwiki:suggest:selected</tt>* (since 2.3)
108 108  
109 109  This event is fired when a value was selected
110 110  
111 -=== Fullscreen events (fullScreenEdit.js) (since 2.5.1) ===
105 +1.1.1 Fullscreen events (fullScreenEdit.js) (since 2.5.1)
112 112  
113 -* **##xwiki:fullscreen:entered##**
114 -* **##xwiki:fullscreen:exited##**
115 -* **##xwiki:fullscreen:resized##**
107 +* *<tt>xwiki:fullscreen:entered</tt>*
108 +* *<tt>xwiki:fullscreen:exited</tt>*
109 +* *<tt>xwiki:fullscreen:resized</tt>*
116 116  
117 -=== Annotations events (AnnotationCode/Settings jsx) ===
111 +1.1.1 Annotations events (AnnotationCode/Settings jsx)
118 118  
119 -* **##xwiki:annotations:filter:changed##**
120 -* **##xwiki:annotations:settings:loaded##**
113 +* *<tt>xwiki:annotations:filter:changed</tt>*
114 +* *<tt>xwiki:annotations:settings:loaded</tt>*
121 121  
122 -=== Livetable events (livetable.js) ===
116 +1.1.1 Livetable events (livetable.js)
123 123  
124 -* **##xwiki:livetable:newrow##**
125 -* **##xwiki:livetable:loadingEntries##** (since 2.3 RC1)
126 -* **##xwiki:livetable:receivedEntries##** (since 2.3 RC1)
127 -* **##xwiki:livetable:loadingComplete##** (since 2.4 M1)
128 -* **##xwiki:livetable:displayComplete##** (since 2.4 M1)
129 -* **##xwiki:livetable:ready##** (since 2.4.4)
118 +* *<tt>xwiki:livetable:newrow</tt>*
119 +* *<tt>xwiki:livetable:loadingEntries</tt>* (since 2.3 RC1)
120 +* *<tt>xwiki:livetable:receivedEntries</tt>* (since 2.3 RC1)
121 +* *<tt>xwiki:livetable:loadingComplete</tt>* (since 2.4 M1)
122 +* *<tt>xwiki:livetable:displayComplete</tt>* (since 2.4 M1)
123 +* *<tt>xwiki:livetable:ready</tt>* (since 2.4.4)
124 +

Get Connected