Changes for page XWiki JavaScript API
Last modified by Simon Urli on 2022/09/14
From version 17.3
edited by Manuel Smeria
on 2013/01/08
on 2013/01/08
Change comment:
added the title and adjusted the headers properly, updated links, rewording
To version 20.1
edited by Guillaume Delhumeau
on 2014/10/27
on 2014/10/27
Change comment:
There is no comment for this version
Summary
-
Page properties (2 modified, 0 added, 0 removed)
Details
- Page properties
-
- Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. ManuelSmeria1 +XWiki.gdelhumeau - Content
-
... ... @@ -149,3 +149,30 @@ 149 149 * **##xwiki:livetable:loading##** (since 3.1.1) (should be used in place of ##xwiki:dom:loading## to startup livetables) 150 150 151 151 The livetable sends both generic events, named as above, and events specific to each livetable, containing the table name on the third position, such as ##xwiki:livetable:alldocs:loadingEntries##. The generic event has the table name in the memo, as ##event.memo.tableId##. 152 + 153 += RequireJS and jQuery APIs = 154 + 155 +By default XWiki uses PrototypeJS which is bound to the $ symbol. Starting in XWiki 5.2, you may use jQuery by //requiring// it using the [[RequireJS>>http://requirejs.org/]] AMD standard. To do this you would write your code as follows: 156 + 157 +{{code language="javascript"}} 158 +require(['jquery'], function ($) { 159 + $('#xwikicontent').append('<p>Inside of this function, $ becomes jquery!</p>'); 160 +}); 161 +{{/code}} 162 + 163 +The best part is, any scripts which are loaded using require are loaded //asynchronously// (all at the same time) and if they are not required, they are never loaded at all. 164 + 165 += Get some informations about the current document = 166 + 167 +In your javascript's applications, you can get some (meta) informations about the current document, though an AMS module. 168 +{{code language="javascript"}} 169 +require(['xwiki-meta'], function (xm) { 170 + xm.document // get he current document (eg: Main.WebHome) 171 + xm.xwiki // get the current wiki (eg: xwiki) 172 + xm.space // get the current space (eg: Main) 173 + xm.page // get the current page name (eg: WebHome) 174 + xm.version // get the current document version (eg: 1.1) 175 + xm.restURL // get the REST url of the current doc (eg: /xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome) 176 + xm.form_token // get the current CSRF token that ou should pass to your script's to avoid CSRF attacks. 177 +}); 178 +{{/code}}