Javascript embedded in the widget can't access the jquery object on page load since jquery hasn't loaded yet. You can use something like this
(function() { function onLoad() { // widget code } if (window.jQuery) { onLoad(); } else { window.addEventListener('DOMContentLoaded', onLoad); } })();Solved JQuery in Widget Template
-
Hey,
I am curious if there is a way to include jquery in my widgets template.. Right now I am using require(['https://code.jquery.com/jquery-3.1.0.min.js','https://code.jquery.com/ui/1.12.0/jquery-ui.min.js'], function(){}). I have no idea if this is the correct approach to including CDN hosted javascript in my widget. This seems to cause problems with jquery timeago throwing errors like "$(...).timeago is not a function" and "widgetAreas.find(...).timeago is not a function". Any tips would be greatly appreciated!
Use Case - Wanting to use JQuery datepicker in my widget for some reason it wasn't working
NodeBB Version - "1.1.2"'
Thanks,
Nick -
You should be able to just use the globally provided jQuery object.
-
You can close this thread..
Resolved by using app.loadJQueryUI()