I am trying to load a javascript library in XPages.
Normally in HTML the reference looks as followed:
Another way to handle this is to use the AMD loader which is a part of Dojo on newer versions of Domino.
This code implements the basic example from the hammer.js documentation (I'm only using jQuery for the ready function):
require({
async: true,
aliases: [['jquery', '//code.jquery.com/jquery-1.11.3.min.js'],
['Hammer', '//cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.4/hammer.min.js']]
}, ['jquery', 'Hammer'], function(jq, Hammer){
$(function() {
var myElement = document.getElementById('myElement');
// create a simple instance
// by default, it only adds horizontal recognizers
var mc = new Hammer(myElement);
// listen to events...
mc.on("panleft panright tap press", function(ev) {
myElement.textContent = ev.type +" gesture detected.";
});
});
});
Then just add the code to your xpage in a script tag:
I'm also using the stylesheet from the example:
#myElement {
background: silver;
height: 300px;
text-align: center;
font: 30px/300px Helvetica, Arial, sans-serif;
}