Search code examples
javascriptjqueryliferayliferay-themeliferay-7

jQuery plugin in a Liferay 7 theme


I need some help understanding Liferay 7 themes, specifically to use jQuery plugins. As I am having the same issue as in this thread: https://web.liferay.com/community/forums/-/message_boards/view_message/79089004

"is not a function" is occuring whenever I call the plugin function I tried to install. I am tring all the possible placements for this:

<script type="text/javascript" src="${javascript_folder}/mCustomScrollbar.js"></script>

When I inspect the page I can see the jQuery object there, but it seems the plugin is not sticking..

$(".content").mCustomScrollbar();

is just a no go, and I can't figure it out why..


Solution

  • crossposting from the Liferay Forums

    Not that the cleanest solution, but if you simply want to keep loading your modules as globals, you might be able to do the following:

    <script>
        define._amd = define.amd;
        define.amd = false;
    </script>
    
    <script type="text/javascript" src="${javascript_folder}/mCustomScrollbar.js"></script>
    
    <script>
        define.amd = define._amd;
    </script>
    

    Setting the amd flag to false before loading your umd-wrapped plugins should do the trick and they should keep loading all the same.

    Additionally, if you're hosting the file, you could actually replace &&define.amd by &&false or something similar in the plugin umd definition to make sure it will laod as a global as well.

    Let me know if that works for you!