jFactory > Reference > Traits > TraitCSS
TraitCSS
Registers CSS that will be automatically removed at Remove Phase.
Registry
myComponent.$.css
Injected Methods
$css(registryId {string}, styleBody {string})
Returns: jQuery selection
Calls jQuery to create and append to <head>
an HTMLStyleElement containing the value of styleBody
.
myComponent.$css('myStyle', "div {border: 1px solregistryId red}");
-
Setting the Element id on the fly
Preceding the
registryId
with a “#” will also set the Element id:myComponent.$css("#css1", "body {color:red}").appendTo("body") // => creates a style with id = css1
$cssFetch(registryId {string}, url {string} [, appendTo {jQuery argument} = "head"])
Returns: JFactoryPromise
resolved as a jQuery
Loads a CSS file by appending a <link type="stylesheet" href=[url]>
into appenTo
(jQuery argument, default “head”)
and returns a promise that can be awaited.
If a <link> with the same url is already in document at the same appendTo
, the existing element is shared. So you can safely recall $cssFetch(sameUrl) without side effects.
Defers current Phase: This method registers a Task that blocks the resolution of the current Phase (if any) until the whole Task chain (including subpromises) is resolved.
Auto completed: The promise chain is completed and expired as soon as all subpromises are resolved. This behavior can be disabled by setting
anyPromiseOfTheChain.$chain.chainConfig.chainAutoComplete = false
before the promise chain is completed.
-
Setting the Element id on the fly
Preceding the
registryId
with a “#” will also set the Element id. See$css()
$cssRemove(registryId {string} [, reason {string} = "$cssRemove()]")
Removes the CSS registered with the key registryId
previously created by $css()
or $cssFetch()
.
An optional reason
can be given for debugging the expired cssFetch()
Promise Chain.
$cssRemoveAll(removePhase)
(Automatically called at Remove Phase)
Removes any CSS previously registered by $css()
or $cssFetch()
if their Remove Phase match the given removePhase
.
myComponent.$cssRemoveAll(jFactory.PHASE.DISABLE)