loading a javascript library and not getting an object returned

前端 未结 3 2095
悲&欢浪女
悲&欢浪女 2020-12-11 10:49

I am trying to load a javascript library in XPages.

Normally in HTML the reference looks as followed:





        
3条回答
  •  暖寄归人
    2020-12-11 11:47

    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;
    }
    

提交回复
热议问题