const mixinafDuvet::HtmlInjector

afDuvet::HtmlInjector

(Service) - Injects HTML elements into your page. Elements are queued up and injected just before the page is sent to the browser.

Elements are listed in the HTML in the order they are added. Duplicate elements are ignored. So if a component adds a stylesheet link, that component may be used many times on a page but, only ONE link to that stylesheet will be rendered.

Source

abstract LinkTagBuilder injectLink()

Injects a <link> element into the bottom of your head. Example:

injectLink.fromClientUrl(`/css/styles.css`)

will render the following tag:

<link href="/css/styles.css">
injectMeta

Source

abstract MetaTagBuilder injectMeta()

Injects a <meta> element into the bottom of your head. Example:

injectMeta.withName("viewport").withContent("initial-scale=1")

will render the following tag:

<meta name="viewport" content="initial-scale=1">
injectRequireCall

Source

abstract ScriptTagBuilder injectRequireCall(Str moduleId, Str? funcName := null, Obj?[]? funcArgs := null)

Injects a call to a RequireJS module.

If the RequireJS module exposes an object then a function may be invoked using funcName and funcArgs. Example:

injectRequireCall("my/shirt", "addToCart", ["shirt", 1.99f])

will generate:

<script type="text/javascript">
  require(["my/shirt"], function (module) { module.addToCart("shirt", 1.99); });
</script>

Or, if the RequireJS module returns function as its module definition then it may be invoked directly by passing null as the funcName. Example:

injectRequireCall("my/title", null, ["Reduced to Clear!"])

will generate:

<script type="text/javascript">
  require(["my/title"], function (module) { module("Reduced to Clear!"); });
</script>

Note that funcArgs are converted into JSON; which is really useful, as it means you don't have to!

injectRequireScript

Source

abstract ScriptTagBuilder injectRequireScript(Str:Str functionParams, Str script)

Wraps the script in a function call to RequireJS, ensuring the given module dependencies are available.

functionParams is a map of RequireJs module names to function parameter names. Example:

injectRequireScript(["jquery":"\$"], "\$('p').addClass('magic');")

will generate:

<script type="text/javascript">
  require(["jquery"], function ($) {
     $('p').addClass('magic');
  });
</script>
injectScript

Source

abstract ScriptTagBuilder injectScript(Bool appendToHead := false)

Injects a <script> element into the bottom of your body. Example:

injectScript.fromExternalUrl(`//code.jquery.com/jquery-2.1.1.min.js`)

will render the following tag:

<script type="text/javascript" src="//code.jquery.com/jquery-2.1.1.min.js"></script>

Consider using RequireJS AMD modules instead!

injectStylesheet

Source

abstract LinkTagBuilder injectStylesheet()

Injects a <link> element, defaulted for CSS stylesheets, into the bottom of your head. Example:

injectStylesheet.fromClientUrl(`/css/styles.css`)

will render the following tag:

<link type="text/css" rel="stylesheet" href="/css/styles.css">