Javascript XWiki augmentation

As indicated on https://dev.xwiki.org/xwiki/bin/view/Community/DevelopmentPractices#HJavaScriptBestPractices JavaScript code should be organized in modules. What you did, by extending XWiki.widgets, is the old way. But more importantly you shouldn’t use Prototype.js anymore, and Class.create() is Prototype.js API. You should use the standard JavaScript syntax for creating classes Classes - JavaScript | MDN . This means:

define('xwiki-tabList', [...], function() {
  class KeyboardAccessibleTabList {
    ...
  }

  return KeyboardAccessibleTabList;
});

Next you need to publish this module to the global RequireJS configuration so that anyone else can use it:

Once the configuration is published anyone can write:

require(['xwiki-tabList'], function(TabList) {
  let tabList = new TabList();
  ...
});

Hope this helps,
Marius

1 Like