3.3.1.6. Exposing version of jQuery globally

Warning

You are looking at documentation for an older release. Not what you want? See the current release documentation.

The built-in jQuery is currently declared as an AMD module. By default, jQuery will not be available in the window object of the browser. This section shows how to make jQuery available so you can write a code like in a plain script.

The following script will make jQuery available by mounting the jQuery object in the window object:

require( ["SHARED/jquery"], function($) {
  // the '$' in window.$ is alias, you can make the other for yourself.
  window.$ = $;
});

This script must be integrated as a shared script:


<scripts>
  <name>imediatejs</name>
  <script>
    <path>/myfolder/imediateJScript.js</path>
  </script>
</scripts>

A portlet can then provide its own script on which it depends:


<portlet>
  <name>foo</name>
  <script>
    <name>portletjs</name>
    <path>/myfolder/portlet.js</path>
  </script>
  <depends>
    <scripts>imediatejs</scripts>
  </depends>
</scripts>

With the following JavaScript:

$("#foo").html("<h1>hello global jQuery</h1>");
Copyright ©. All rights reserved. eXo Platform SAS
blog comments powered byDisqus