jQuery plugin in a Liferay 7 theme

六眼飞鱼酱① 提交于 2019-12-03 22:29:18

问题


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..


回答1:


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!



来源:https://stackoverflow.com/questions/39490126/jquery-plugin-in-a-liferay-7-theme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!