Project

General

Profile

Can someone verify I can't use a BS 5 theme javascript file directly?

Added by Mark Travis about 1 year ago

I have really been enjoying playing around with the latest version of Bootstrap Studio 6.2. It will pretty much generates the HTML and CSS needed to import into Wt to use as templates.

I bought a handful of brilliant Bootstrap 5 themes from Creative Tim that I've started to try to incorporate into my project to make it look more polished.

I thought if I "required" the javascript file, and loaded the majority of the HTML into a template except where I needed my own objects, (as defined by ${Wt::Object} in the template) that I'd be able to get some of the cool features. For instance, there's a javascript kanban app and a calendar app that are pretty good. I can get my app to look exactly like the theme with little effort using Wt::WTemplate.

However, none of the javascript works. Best I can tell from the templates, the html/css defines the underlying object and the associated classes, then the javascript is activated based on the html/css class. There are several DOM listeners in the webpage that listen for a trigger for a javascript event. Or at least there are supposed to be listeners.

I think what I've discovered after a few days of research is that I can't have the javascript work automatically just by including the necessary HTML in a template, and requiring the .js be loaded. It looks like I have to figure out what javascript snippet is being called, then I have to manually assign that javascript to a theme object using the ->doJavaScript('') method. Is this correct?

In other words, I can use the javascript for the theme, but I can't automatically load it, I have to manually get involved by adding doJavaScript() to the affected objects. Correct?


Replies (2)

RE: Can someone verify I can't use a BS 5 theme javascript file directly? - Added by Roel Standaert about 1 year ago

WApplication::require(...) will load and immediately execute JavaScript. If that JavaScript is just a kind of run-once type of JavaScript, then it may perhaps not work if you're only adding the HTML that it affects later. Wt dynamically generates the contents of your page. If any JavaScript is loaded before the contents of the page are added, then either that JavaScript will have to react to changes to the page's contents, or you will have to do it with doJavaScript.

RE: Can someone verify I can't use a BS 5 theme javascript file directly? - Added by Mark Travis about 1 year ago

For instance, I just moved the require() to the method that instantiates the Template that contains the controls.

One of the features is a sidebar that expands when you click on a hamburger icon. Then you can expand line items or contract line items in the menu based on another javascript item.

I found that the very first time I clicked on an item in the menu, it expanded, but then it wouldn't collapse and none of the other line items would expand or collapse.

So, is it "one and done" for the require()? Or should it live and listen on that page as long as that page is the one in focus? Asking as I may have bugs in my code if it's supposed to be "resident" in the page.

I know I can do most of this through Wt, but it would be nice to leave it to an embeddable js library if possible to just automatically handle with no signal/slot involvement.

    (1-2/2)