From version < 1.4 >
edited by Jerome
on 2009/04/22
To version < 1.5 >
edited by Sergiu Dumitriu
on 2009/05/07
< >
Change comment: Added information about xwiki:dom:loading and the extra parameters sent to action events

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.jvelociter
1 +XWiki.Sergiu
Content
... ... @@ -6,7 +6,7 @@
6 6  
7 7  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.
8 8  
9 -Events name 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: <tt>xwiki:modulename:eventname</tt>. Your JavaScript script or extension can get notified of such an event the following way:
10 10  
11 11  {code}
12 12  document.observe("xwiki:modulename:eventname", function(event){
... ... @@ -22,9 +22,10 @@
22 22  
23 23  1.1.1 DOM Events
24 24  
25 +* *<tt>xwiki:dom:loading</tt>*
25 25  * *<tt>xwiki:dom:loaded</tt>*
26 26  
27 -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 those two events, 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:
28 +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:
28 28  
29 29  {code}
30 30  document.observe("xwiki:dom:loaded", function(){
... ... @@ -32,6 +32,10 @@
32 32  });
33 33  {code}
34 34  
36 +*It is recommended to bind startup scripts to this event* instead of <tt>window.load</tt> or <tt>document.dom:loaded</tt>.
37 +
38 +<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.
39 +
35 35  1.1.1 Action events
36 36  
37 37  * *<tt>xwiki:actions:cancel</tt>*
... ... @@ -55,6 +55,8 @@
55 55  });
56 56  {code}
57 57  
63 +All these events contain as extra information, in the second parameter sent to event listeners, the original click event (if any, and which can be stopped to prevent the action from completing), and the form being submitted.
64 +
58 58  1.1.1 Document extra events
59 59  
60 60  * *<tt>xwiki:docextra:loaded</tt>*

XWiki JavaScript API

Observable XWiki Events

This section documents a feature that is only available starting with XWiki Enterprise 1.9M2. This version is not released yet. You can stay in touch with the Roadmap or grab a snapshot.

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.

Events name are build on the following model: xwiki:modulename:eventname. Your JavaScript script or extension can get notified of such an event the following way:

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:

document.observe("xwiki:modulename:eventname", function(event){
  // Here, do something that will be executed at the moment the event is fired
  doSomething();

  // The event can have an option memo object to pass to its observers some information:
  console.log(event.memo.somethingINeedToKnow);
});

Check out the real examples below, or read more about Prototype.js's event system

DOM Events

  • xwiki:dom:loaded
  • xwiki:dom:loading
  • xwiki:dom:loaded

This event is similar to prototype's dom:loaded event, with the difference that in the time-lapse between those two events, 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:

These events are similar to prototype's dom:loaded event, 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:

document.observe("xwiki:dom:loaded", function(){
  // Initialization that can rely on the fact the DOM is XWiki-tranformed goes here.
});

It is recommended to bind startup scripts to this event instead of window.load or document.dom:loaded.

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.

Action events

  • xwiki:actions:cancel

This event is saved after ther use clicks the "Cancel" button of an editor (Wiki, WYSIWYG, object, rights, etc.)

  • xwiki:actions:preview

This event is saved after ther use clicks the "Preview" button of an editor (Wiki, WYSIWYG, object, rights, etc.)

  • xwiki:actions:save

This event is saved after the user clicks the "Save" or "Save & Continue" button of an editor (Wiki, WYSIWYG, object, rights, etc.). A memo is available if you need to know if the intend is to continue after the save. You can use it as follow:

document.observe("xwiki:dom:loaded", function(event){
  var doContinue = event.memo.continue;
  if (doContinue) {
    // do something specific
   }
});

All these events contain as extra information, in the second parameter sent to event listeners, the original click event (if any, and which can be stopped to prevent the action from completing), and the form being submitted.

Document extra events

  • xwiki:docextra:loaded

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.

document.observe("xwiki:docextra:loaded", function(event){
  var tabID = event.memo.id;
  if (tabID == "attachments") {
    // do something with the attachments tab retrieved content.
    doSomething(event.memo.element);
   }
});
  • xwiki:docextra:activated

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

Get Connected