Wiki source code of JavaScriptAPI

Version 9.1 by Sergiu Dumitriu on 2010/11/06

Hide last authors
Sergiu Dumitriu 9.1 1 {{velocity filter="none"}}
2 {{html clean="false" wiki="true"}}
Jerome 2.1 3 #startfloatingbox()
Sergiu Dumitriu 9.1 4 **Contents:**
5
6 {{toc start="" depth="" numbered=""/}}
Jerome 2.1 7 #endfloatingbox()
Sergiu Dumitriu 9.1 8 {{/html}}
9 {{/velocity}}
Jerome 1.1 10
Sergiu Dumitriu 9.1 11 = XWiki JavaScript API =
Jerome 1.1 12
Sergiu Dumitriu 9.1 13 == Observable XWiki Events ==
14
Jerome 1.1 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
Sergiu Dumitriu 9.1 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:
Jerome 1.1 18
Sergiu Dumitriu 9.1 19 {{code}}
Jerome 1.1 20 document.observe("xwiki:modulename:eventname", function(event){
21 // Here, do something that will be executed at the moment the event is fired
22 doSomething();
23
24 // The event can have an option memo object to pass to its observers some information:
25 console.log(event.memo.somethingINeedToKnow);
Sergiu Dumitriu 9.1 26 });
27 {{/code}}
Jerome 1.1 28
Sergiu Dumitriu 9.1 29 Check out the real examples below, or [[read more>>http://prototypejs.org/api/element/fire]] about Prototype.js's event system
Jerome 1.1 30
Sergiu Dumitriu 9.1 31 === DOM Events (xwiki.js) ===
Jerome 1.1 32
Sergiu Dumitriu 9.1 33 * **##xwiki:dom:loading##**
34 * **##xwiki:dom:loaded##**
Jerome 1.1 35
Sergiu Dumitriu 9.1 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:
Jerome 1.1 37
Sergiu Dumitriu 9.1 38 {{code}}
Jerome 1.1 39 document.observe("xwiki:dom:loaded", function(){
40 // Initialization that can rely on the fact the DOM is XWiki-tranformed goes here.
41 });
Sergiu Dumitriu 9.1 42 {{/code}}
Jerome 1.1 43
Sergiu Dumitriu 9.1 44 **It is recommended to bind startup scripts to this event** instead of ##window.load## or ##document.dom:loaded##.
Sergiu Dumitriu 1.5 45
Sergiu Dumitriu 9.1 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.
Sergiu Dumitriu 1.5 47
Sergiu Dumitriu 9.1 48 === Document content events (actionButtons.js) ===
Sergiu Dumitriu 3.1 49
Sergiu Dumitriu 9.1 50 * **##xwiki:document:saved##**
Sergiu Dumitriu 3.1 51
Sergiu Dumitriu 9.1 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).
Sergiu Dumitriu 3.1 53
Sergiu Dumitriu 9.1 54 * **##xwiki:document:saveFailed##**
Jerome 1.1 55
Sergiu Dumitriu 9.1 56 === Action events (actionButtons.js) ===
Jerome 1.1 57
Sergiu Dumitriu 9.1 58 * **##xwiki:actions:cancel##**
Ecaterina Moraru (Valica) 6.1 59
Sergiu Dumitriu 3.2 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.
Jerome 1.1 61
Sergiu Dumitriu 9.1 62 * **##xwiki:actions:preview##**
Jerome 1.1 63
Sergiu Dumitriu 3.2 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.
Jerome 1.1 65
Sergiu Dumitriu 9.1 66 * **##xwiki:actions:save##**
Jerome 1.1 67
Sergiu Dumitriu 9.1 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:
Jerome 1.1 69
Sergiu Dumitriu 9.1 70 {{code}}
Jerome 1.1 71 document.observe("xwiki:dom:loaded", function(event){
72 var doContinue = event.memo.continue;
73 if (doContinue) {
74 // do something specific
75 }
76 });
Sergiu Dumitriu 9.1 77 {{/code}}
Jerome 1.1 78
Sergiu Dumitriu 3.2 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.
Sergiu Dumitriu 1.5 80
Sergiu Dumitriu 9.1 81 === Document extra events (xwiki.js) ===
Jerome 1.1 82
Sergiu Dumitriu 9.1 83 * **##xwiki:docextra:loaded##**
Jerome 1.1 84
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
Sergiu Dumitriu 9.1 87 {{code}}
Jerome 1.1 88 document.observe("xwiki:docextra:loaded", function(event){
89 var tabID = event.memo.id;
90 if (tabID == "attachments") {
91 // do something with the attachments tab retrieved content.
92 doSomething(event.memo.element);
93 }
94 });
Sergiu Dumitriu 9.1 95 {{/code}}
Jerome 1.1 96
Sergiu Dumitriu 9.1 97 * **##xwiki:docextra:activated##**
Jerome 1.1 98
Sergiu Dumitriu 9.1 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##
Oana Florea 4.1 100
Sergiu Dumitriu 9.1 101 === WYSIWYG events (XWikiWysiwyg.js) ===
Ecaterina Moraru (Valica) 5.1 102
Sergiu Dumitriu 9.1 103 WYSIWYG has it's own custom [[events list>>http://code.xwiki.org/xwiki/bin/view/Modules/WysiwygEditorModule#HCustomevents]].
Ecaterina Moraru (Valica) 5.1 104
Sergiu Dumitriu 9.1 105 === Suggest events (ajaxSuggest.js) ===
Ecaterina Moraru (Valica) 8.1 106
Sergiu Dumitriu 9.1 107 * **##xwiki:suggest:selected##** (since 2.3)
Ecaterina Moraru (Valica) 8.1 108
109 This event is fired when a value was selected
110
Sergiu Dumitriu 9.1 111 === Fullscreen events (fullScreenEdit.js) (since 2.5.1) ===
Oana Florea 4.1 112
Sergiu Dumitriu 9.1 113 * **##xwiki:fullscreen:entered##**
114 * **##xwiki:fullscreen:exited##**
115 * **##xwiki:fullscreen:resized##**
Ecaterina Moraru (Valica) 6.1 116
Sergiu Dumitriu 9.1 117 === Annotations events (AnnotationCode/Settings jsx) ===
Ecaterina Moraru (Valica) 6.1 118
Sergiu Dumitriu 9.1 119 * **##xwiki:annotations:filter:changed##**
120 * **##xwiki:annotations:settings:loaded##**
Ecaterina Moraru (Valica) 6.1 121
Sergiu Dumitriu 9.1 122 === Livetable events (livetable.js) ===
Ecaterina Moraru (Valica) 6.1 123
Sergiu Dumitriu 9.1 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)

Get Connected