Class ScriptViewElement
java.lang.Object
com.foreach.across.modules.web.ui.elements.ContainerViewElement
com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
com.foreach.across.modules.bootstrapui.elements.ScriptViewElement
- All Implemented Interfaces:
com.foreach.across.modules.web.ui.elements.HtmlViewElement
,com.foreach.across.modules.web.ui.MutableViewElement
,com.foreach.across.modules.web.ui.ViewElement
public class ScriptViewElement
extends com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
Represents a
<script>
element. A script tag may not be safely nested, using a ScriptViewElement
will ensure that
any nested ScriptViewElement
will get written after the original instead of inside it. In the original location a reference
node with all the same non-script-specific attributes will be written instead. A special attribute data-bum-ref-id
will be added
holding the HTML id of the actual <script>
that has been written in a valid location. Client-side you can use
BootstrapUiModule.refTarget(node)
on a selector to ensure you transparently fetch the actual script node.
The replacement tag written inside the original script is by default an i
element with explicit hidden styling. You can use a
different tag if necessary by setting it using setTagName(String)
.
If you really want to nest script elements, use a regular NodeViewElement
instead.- Since:
- 2.1.1
- Author:
- Arne Vandamme
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.foreach.across.modules.web.ui.elements.HtmlViewElement
com.foreach.across.modules.web.ui.elements.HtmlViewElement.Functions
Nested classes/interfaces inherited from interface com.foreach.across.modules.web.ui.MutableViewElement
com.foreach.across.modules.web.ui.MutableViewElement.Functions
Nested classes/interfaces inherited from interface com.foreach.across.modules.web.ui.ViewElement
com.foreach.across.modules.web.ui.ViewElement.Wither<T extends com.foreach.across.modules.web.ui.ViewElement>, com.foreach.across.modules.web.ui.ViewElement.WitherGetter<T extends com.foreach.across.modules.web.ui.ViewElement,
U extends Object>, com.foreach.across.modules.web.ui.ViewElement.WitherRemover<T extends com.foreach.across.modules.web.ui.ViewElement>, com.foreach.across.modules.web.ui.ViewElement.WitherSetter<T extends com.foreach.across.modules.web.ui.ViewElement> -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Value to set onsetRefTagName(String)
to avoid a reference tag from being written.Fields inherited from class com.foreach.across.modules.web.ui.elements.ContainerViewElement
ELEMENT_TYPE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddAttributes
(Map<String, Object> attributes) addChild
(com.foreach.across.modules.web.ui.ViewElement element) addChildren
(Collection<? extends com.foreach.across.modules.web.ui.ViewElement> elements) addCssClass
(String... cssClass) addFirstChild
(com.foreach.across.modules.web.ui.ViewElement element) <U extends com.foreach.across.modules.web.ui.ViewElement>
ScriptViewElementapplyUnsafe
(Consumer<U> consumer) @NonNull String
The tag which should be rendered if the script element is deferred, in case of a nested script tag.org.springframework.http.MediaType
getType()
boolean
isAsync()
boolean
isDefer()
remove
(com.foreach.across.modules.web.ui.ViewElement.WitherRemover... functions) removeAttribute
(String attributeName) removeCssClass
(String... cssClass) set
(com.foreach.across.modules.web.ui.ViewElement.WitherSetter... setters) setAsync
(boolean async) Specifies that the script is executed asynchronously (only for external scripts).setAttribute
(String attributeName, Object attributeValue) setAttributes
(Map<String, Object> attributes) setCharset
(String charset) Specifies the character encoding used in an external script file.setCustomTemplate
(String customTemplate) setDefer
(boolean defer) Specifies that the script is executed when the page has finished parsing (only for external scripts).protected ScriptViewElement
setElementType
(String elementType) setRefTagName
(@NonNull String refTagName) The tag which should be rendered if the script element is deferred, in case of a nested script tag.Specifies the URL of an external script file.protected ScriptViewElement
setTagName
(String tagName) setType
(@NonNull org.springframework.http.MediaType mediaType) Set the script media type.Set the script media type.Methods inherited from class com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
get, getAttribute, getAttribute, getAttributes, getHtmlId, getTagName, hasAttribute, hasCssClass, returnIfType
Methods inherited from class com.foreach.across.modules.web.ui.elements.ContainerViewElement
elementStream, find, find, findAll, findAll, findAll, findOrSelf, findOrSelf, flatStream, getChildren, getCustomTemplate, getElementType, getName, hasChildren, removeAllFromTree, removeChild, removeFromTree, removeFromTree
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.foreach.across.modules.web.ui.ViewElement
getCustomTemplate, getElementType, getName, matches
-
Field Details
-
NO_REF_TAG
Value to set onsetRefTagName(String)
to avoid a reference tag from being written.- See Also:
-
-
Constructor Details
-
ScriptViewElement
public ScriptViewElement()
-
-
Method Details
-
setSource
Specifies the URL of an external script file.- Parameters:
src
- url
-
getSource
- Returns:
- the URL of an external script file
-
setCharset
Specifies the character encoding used in an external script file.- Parameters:
charset
- encoding
-
getCharset
- Returns:
- the character encoding used in an external script file
-
setType
Set the script media type.- Parameters:
mediaType
- to set
-
setType
Set the script media type.- Parameters:
mediaType
- to set
-
getType
public org.springframework.http.MediaType getType()- Returns:
- the script media type
-
setAsync
Specifies that the script is executed asynchronously (only for external scripts).- Parameters:
async
- true if async
-
isAsync
public boolean isAsync()- Returns:
- true if the script is executed asynchronously (only for external scripts)
-
setDefer
Specifies that the script is executed when the page has finished parsing (only for external scripts).- Parameters:
defer
- true if script is deferred
-
isDefer
public boolean isDefer()- Returns:
- true if the script is executed when the page has finished parsing (only for external scripts)
-
addCssClass
- Specified by:
addCssClass
in interfacecom.foreach.across.modules.web.ui.elements.HtmlViewElement
- Overrides:
addCssClass
in classcom.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
-
removeCssClass
- Specified by:
removeCssClass
in interfacecom.foreach.across.modules.web.ui.elements.HtmlViewElement
- Overrides:
removeCssClass
in classcom.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
-
setAttributes
- Specified by:
setAttributes
in interfacecom.foreach.across.modules.web.ui.elements.HtmlViewElement
- Overrides:
setAttributes
in classcom.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
-
setAttribute
- Specified by:
setAttribute
in interfacecom.foreach.across.modules.web.ui.elements.HtmlViewElement
- Overrides:
setAttribute
in classcom.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
-
addAttributes
- Specified by:
addAttributes
in interfacecom.foreach.across.modules.web.ui.elements.HtmlViewElement
- Overrides:
addAttributes
in classcom.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
-
removeAttribute
- Specified by:
removeAttribute
in interfacecom.foreach.across.modules.web.ui.elements.HtmlViewElement
- Overrides:
removeAttribute
in classcom.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
-
setName
- Specified by:
setName
in interfacecom.foreach.across.modules.web.ui.MutableViewElement
- Overrides:
setName
in classcom.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
-
setCustomTemplate
- Specified by:
setCustomTemplate
in interfacecom.foreach.across.modules.web.ui.MutableViewElement
- Overrides:
setCustomTemplate
in classcom.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
-
setElementType
- Overrides:
setElementType
in classcom.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
-
addChild
- Overrides:
addChild
in classcom.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
-
addChildren
public ScriptViewElement addChildren(Collection<? extends com.foreach.across.modules.web.ui.ViewElement> elements) - Overrides:
addChildren
in classcom.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
-
addFirstChild
- Overrides:
addFirstChild
in classcom.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
-
clearChildren
- Overrides:
clearChildren
in classcom.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
-
apply
public ScriptViewElement apply(Consumer<com.foreach.across.modules.web.ui.elements.ContainerViewElement> consumer) - Overrides:
apply
in classcom.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
-
applyUnsafe
public <U extends com.foreach.across.modules.web.ui.ViewElement> ScriptViewElement applyUnsafe(Consumer<U> consumer) - Overrides:
applyUnsafe
in classcom.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
-
setTagName
- Overrides:
setTagName
in classcom.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
-
setHtmlId
- Specified by:
setHtmlId
in interfacecom.foreach.across.modules.web.ui.elements.HtmlViewElement
- Overrides:
setHtmlId
in classcom.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
-
set
- Specified by:
set
in interfacecom.foreach.across.modules.web.ui.elements.HtmlViewElement
- Specified by:
set
in interfacecom.foreach.across.modules.web.ui.MutableViewElement
- Specified by:
set
in interfacecom.foreach.across.modules.web.ui.ViewElement
- Overrides:
set
in classcom.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
-
remove
public ScriptViewElement remove(com.foreach.across.modules.web.ui.ViewElement.WitherRemover... functions) - Specified by:
remove
in interfacecom.foreach.across.modules.web.ui.elements.HtmlViewElement
- Specified by:
remove
in interfacecom.foreach.across.modules.web.ui.MutableViewElement
- Specified by:
remove
in interfacecom.foreach.across.modules.web.ui.ViewElement
- Overrides:
remove
in classcom.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
-
getRefTagName
The tag which should be rendered if the script element is deferred, in case of a nested script tag. -
setRefTagName
The tag which should be rendered if the script element is deferred, in case of a nested script tag.- Returns:
this
.
-