Change comment:
There is no comment for this version
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -201,7 +201,7 @@ 201 201 {{code language="javascript"}} 202 202 require(['xwiki-meta'], function (xm) { 203 203 xm.document // get the current document (eg: Main.WebHome) 204 - xm. xwiki // get the current wiki (eg: xwiki)204 + xm.wiki // get the current wiki (eg: xwiki) 205 205 xm.space // get the current space (eg: Main) 206 206 xm.page // get the current page name (eg: WebHome) 207 207 xm.version // get the current document version (eg: 1.1) ... ... @@ -213,3 +213,21 @@ 213 213 {{warning}} 214 214 It is actually the only clean way. In the past, we used to add some <meta> tags in the <head> section of the page, but is not even valid in HTML5. So now we have introduced this API that we will maintain, meanwhile relying on any other element in the page could be broken in the future! 215 215 {{/warning}} 216 + 217 +== Be retro-compatible with versions older than 6.3 == 218 + 219 +If you want to be compatible with older version, you can use this trick: 220 + 221 +{{code language="javascript"}} 222 +require(['xwiki-meta'], function (xm) { 223 + // Note that the require['xwiki-meta'] (meta information about the current document) is not available on 224 + // XWiki versions < 6.3, then we get these meta information directly from the DOM. 225 + var document = xm ? xm.document : $('meta[name="document"]').attr('content'); 226 + var wiki = xm ? xm.wiki : $('meta[name="wiki"]').attr('content'); 227 + var space = xm ? xm.space : $('meta[name="space"]').attr('content'); 228 + var page = xm ? xm.wiki : $('meta[name="page"]').attr('content'); 229 + var version = xm ? xm.version : $('meta[name="version"]').attr('content'); 230 + var restURL = xm ? xm.restURL : $('meta[name="restURL"]').attr('content'); 231 + var form_token = xm ? xm.form_token : $('meta[name="form_token"]').attr('content'); 232 +} 233 +{{/code}}