From version < 8.1 >
edited by Ecaterina Moraru (Valica)
on 2010/11/05
To version < 10.1 >
edited by Sergiu Dumitriu
on 2010/11/06
< >
Change comment: There is no comment for this version

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.evalica
1 +XWiki.Sergiu
Syntax
... ... @@ -1,1 +1,1 @@
1 -XWiki 1.0
1 +XWiki 2.0
Content
... ... @@ -1,84 +1,76 @@
1 -#startfloatingbox()
2 -*Contents:*
3 -#toc("" "" "")
4 -#endfloatingbox()
5 -1 XWiki JavaScript API
1 +{{box cssClass="floatinginfobox" title="**Contents**"}}{{toc/}}{{/box}}
6 6  
7 -1.1 Observable XWiki Events
3 += XWiki JavaScript API =
8 8  
5 +== Observable XWiki Events ==
6 +
9 9  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.
10 10  
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:
9 +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:
12 12  
13 -{code}
14 -document.observe("xwiki:modulename:eventname", function(event){
15 - // Here, do something that will be executed at the moment the event is fired
16 - doSomething();
11 +{{code language="javascript"}}
12 +document.observe("xwiki:modulename:eventname", function(event) {
13 + // Here, do something that will be executed at the moment the event is fired
14 + doSomething();
17 17  
18 - // The event can have an option memo object to pass to its observers some information:
19 - console.log(event.memo.somethingINeedToKnow);
20 -});
21 -{code}
16 + // The event can have an option memo object to pass to its observers some information:
17 + console.log(event.memo.somethingINeedToKnow);
18 +});
19 +{{/code}}
22 22  
23 -Check out the real examples below, or [read more>http://prototypejs.org/api/element/fire] about Prototype.js's event system
21 +Check out the real examples below, or [[read more>>http://prototypejs.org/api/element/fire]] about Prototype.js's event system
24 24  
25 -1.1.1 DOM Events (xwiki.js)
23 +=== DOM Events (xwiki.js) ===
26 26  
27 -* *<tt>xwiki:dom:loading</tt>*
28 -* *<tt>xwiki:dom:loaded</tt>*
25 +* **##xwiki:dom:loading##** (((
26 +This event is 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, making internal rendering error messages expandable, insert document template handlers for links to non-existent documents, and so on. 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:
29 29  
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:
31 -
32 -{code}
28 +{{code}}
33 33  document.observe("xwiki:dom:loaded", function(){
34 - // Initialization that can rely on the fact the DOM is XWiki-tranformed goes here.
30 + // Initialization that can rely on the fact the DOM is XWiki-tranformed goes here.
35 35  });
36 -{code}
32 +{{/code}}
37 37  
38 -*It is recommended to bind startup scripts to this event* instead of <tt>window.load</tt> or <tt>document.dom:loaded</tt>.
34 +**It is recommended to bind startup scripts to this event** instead of ##window.load## or ##document.dom:loaded##.
35 +)))
36 +* **##xwiki:dom:loaded##** (((
37 +##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.
38 +)))
39 39  
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.
40 +=== Document content events (actionButtons.js) ===
41 41  
42 -1.1.1 Document content events (actionButtons.js)
42 +* **##xwiki:document:saved##**
43 +This event is sent after the document has been successfully saved in an asynchronous request (i.e. after clicking the //Save and Continue// button).
44 +* **##xwiki:document:saveFailed##**
45 +This event is sent when a save and continue attempt failed for some reason. The XMLHttpRequest response object is sent in the memo, as ##event.memo.response##.
43 43  
44 -* *<tt>xwiki:document:saved</tt>*
47 +=== Action events (actionButtons.js) ===
45 45  
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).
47 -
48 -* *<tt>xwiki:document:saveFailed</tt>*
49 -
50 -1.1.1 Action events (actionButtons.js)
51 -
52 -* *<tt>xwiki:actions:cancel</tt>*
53 -
49 +* **##xwiki:actions:cancel##**
54 54  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.
55 -
56 -* *<tt>xwiki:actions:preview</tt>*
57 -
51 +* **##xwiki:actions:preview##**
58 58  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.
53 +* **##xwiki:actions:save##**(((
54 +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:
59 59  
60 -* *<tt>xwiki:actions:save</tt>*
61 -
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:
63 -
64 -{code}
56 +{{code language="javascript"}}
65 65  document.observe("xwiki:dom:loaded", function(event){
66 - var doContinue = event.memo.continue;
67 - if (doContinue) {
68 - // do something specific
69 - }
58 + var doContinue = event.memo.continue;
59 + if (doContinue) {
60 + // do something specific
61 + }
70 70  });
71 -{code}
63 +{{/code}}
64 +)))
72 72  
73 -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.
66 +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, as ##event.memo.originalEvent##, and ##event.memo.form## respectively.
74 74  
75 -1.1.1 Document extra events (xwiki.js)
68 +=== Document extra events (xwiki.js) ===
76 76  
77 -* *<tt>xwiki:docextra:loaded</tt>*
78 -
70 +* **##xwiki:docextra:loaded##**(((
79 79  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.
80 80  
81 -{code}
73 +{{code language="javascript"}}
82 82  document.observe("xwiki:docextra:loaded", function(event){
83 83   var tabID = event.memo.id;
84 84   if (tabID == "attachments") {
... ... @@ -86,38 +86,38 @@
86 86   doSomething(event.memo.element);
87 87   }
88 88  });
89 -{code}
81 +{{/code}}
82 +)))
83 +* **##xwiki:docextra:activated##**
90 90  
91 -* *<tt>xwiki:docextra:activated</tt>*
85 +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##
92 92  
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>
87 +=== WYSIWYG events (XWikiWysiwyg.js) ===
94 94  
95 -1.1.1 WYSIWYG events (XWikiWysiwyg.js)
89 +WYSIWYG has it's own custom [[events list>>http://code.xwiki.org/xwiki/bin/view/Modules/WysiwygEditorModule#HCustomevents]].
96 96  
97 -WYSIWYG has it's own custom [events list>http://code.xwiki.org/xwiki/bin/view/Modules/WysiwygEditorModule#HCustomevents].
91 +=== Suggest events (ajaxSuggest.js) ===
98 98  
99 -1.1.1 Suggest events (ajaxSuggest.js)
93 +* **##xwiki:suggest:selected##** (since 2.3)
100 100  
101 -* *<tt>xwiki:suggest:selected</tt>* (since 2.3)
102 -
103 103  This event is fired when a value was selected
104 104  
105 -1.1.1 Fullscreen events (fullScreenEdit.js) (since 2.5.1)
97 +=== Fullscreen events (fullScreenEdit.js) (since 2.5.1) ===
106 106  
107 -* *<tt>xwiki:fullscreen:entered</tt>*
108 -* *<tt>xwiki:fullscreen:exited</tt>*
109 -* *<tt>xwiki:fullscreen:resized</tt>*
99 +* **##xwiki:fullscreen:entered##**
100 +* **##xwiki:fullscreen:exited##**
101 +* **##xwiki:fullscreen:resized##**
110 110  
111 -1.1.1 Annotations events (AnnotationCode/Settings jsx)
103 +=== Annotations events (AnnotationCode/Settings jsx) ===
112 112  
113 -* *<tt>xwiki:annotations:filter:changed</tt>*
114 -* *<tt>xwiki:annotations:settings:loaded</tt>*
105 +* **##xwiki:annotations:filter:changed##**
106 +* **##xwiki:annotations:settings:loaded##**
115 115  
116 -1.1.1 Livetable events (livetable.js)
108 +=== Livetable events (livetable.js) ===
117 117  
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)
110 +* **##xwiki:livetable:newrow##**
111 +* **##xwiki:livetable:loadingEntries##** (since 2.3 RC1)
112 +* **##xwiki:livetable:receivedEntries##** (since 2.3 RC1)
113 +* **##xwiki:livetable:loadingComplete##** (since 2.4 M1)
114 +* **##xwiki:livetable:displayComplete##** (since 2.4 M1)
115 +* **##xwiki:livetable:ready##** (since 2.4.4)

Get Connected