Spanish Total.js
English
Documentation For AI agents
Contents

Styles, scripts and assets

The CSS and the public script of a widget, external libraries and the preview image.

.md GitHub
On this page

A widget brings its look and its browser code in its own file. This page covers the <style> and <script> sections, external libraries and the preview image.

Styles

Write the CSS of the widget in <style> and scope every rule with CLASS:

.CLASS-box { padding: 20px; border: 1px solid #E0E0E0; border-radius: var(--radius); }
.CLASS-center { text-align: center; }

The editor adds the styles of all installed widgets to the page that it shows. On the public site, CMS adds them to the <head> of every page that uses a layout, also on pages without the widget. Scoped rules keep widgets from changing each other.

The CSS variables of the layout, such as --radius and --gap, and the grid classes of the UI library, such as row and col-sm-6, are available because the official layouts load the library.

A script for the visitors

A <script> section outside <body> and <settings> runs on the public site. CMS adds the scripts of all installed widgets before the end of the <body> of every page that uses a layout, so write it for any page:

$(document).on('click', '.CLASS-question', function() {
    $(this).parent().tclass('CLASS-open');
});

A delegated event on document, as above, works for every instance and does nothing on pages without the widget. jQuery and the helpers such as tclass come from the UI library of the layout.

The editor does not run these scripts, nor the scripts of the layout, so the page in the editor stays still.

External libraries

List the files of a library in exports.dependencies. CMS adds a <link> for each .css address and a <script> for each .js address to the <head> of every public page:

<script total>

    exports.id = 'fadein';
    exports.name = 'Fade-in box';
    exports.author = 'Jane Doe';
    exports.version = '1';
    exports.dependencies = ['https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css'];

</script>

<style>
    .CLASS-box { padding: 20px; background-color: #FFF4E5; border-radius: var(--radius); }
</style>

<body>
    <div class="CLASS-box animate__animated animate__fadeIn">
        <div class="CMS_widgets"></div>
    </div>
</body>

You can also write the list as one string separated by commas, or add a full HTML tag such as <script src="..." defer></script>. The editor does not load the dependencies.

Preview image

exports.preview is the picture on the Widgets screen and in the widget picker. The official widgets use a data: URI with the image inside, which keeps the widget in one file:

exports.preview = 'data:image/png;base64,iVBORw0KGgo...';

When the preview is an https:// address, CMS downloads the picture into its files when it saves the widget and uses the local copy.

Made in Europe