How to properly include anything.js
-
Good evening everyone,
as I am currently working on a theme, I have encountered a problem (as expected).
For the theme I am working on I'd love to use a carousel – a jQuery plugin. So I modified the
plugin.json
file of my theme (a copy of Vanilla)."id": "nodebb-theme-banana", "library": "./lib/theme.js", "hooks": [ { "hook": "filter:widgets.getAreas", "method": "defineWidgetAreas", "callbacked": true } ], "scripts": [ "./lib/slick.min.js" ] }``` Now, before actually triggering the script (using the custom JS settings in the ACP) I get `Uncaught ReferenceError: require is not defined` in the console. And since that is already a boatload of fun, when I ***do*** trigger the script, it throws so many errors I am not even going to bother posting it here. So since I am obviously doing something very wrong, my question to all of you nice people: How do I properly include jQuery plugins. I just want to theme. :cat:
-
nodebb-theme-, I like it XD
@sdnyco said:
Uncaught ReferenceError: require is not defined
Usually means the js didn't compile properly. Do you see an errors client side?
In short, you want to get your library working with NodeBB? We use require.js, so give 'er a name: In short, if you're using the file contained in the zip file, go to line 23, and change this line:
define(['jquery'], factory);
to this:
define('slick', ['jquery'], factory);
Then use it in your client-side lib thusly:
require(['slick'], function(Slick) { Slick.doSomething(); });
YMMV.
Copyright © 2024 NodeBB | Contributors