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
  • Field Details

  • Constructor Details

    • ScriptViewElement

      public ScriptViewElement()
  • Method Details

    • setSource

      public ScriptViewElement setSource(String src)
      Specifies the URL of an external script file.
      Parameters:
      src - url
    • getSource

      public String getSource()
      Returns:
      the URL of an external script file
    • setCharset

      public ScriptViewElement setCharset(String charset)
      Specifies the character encoding used in an external script file.
      Parameters:
      charset - encoding
    • getCharset

      public String getCharset()
      Returns:
      the character encoding used in an external script file
    • setType

      public ScriptViewElement setType(String mediaType)
      Set the script media type.
      Parameters:
      mediaType - to set
    • setType

      public ScriptViewElement setType(@NonNull @NonNull org.springframework.http.MediaType mediaType)
      Set the script media type.
      Parameters:
      mediaType - to set
    • getType

      public org.springframework.http.MediaType getType()
      Returns:
      the script media type
    • setAsync

      public ScriptViewElement setAsync(boolean async)
      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

      public ScriptViewElement setDefer(boolean defer)
      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

      public ScriptViewElement addCssClass(String... cssClass)
      Specified by:
      addCssClass in interface com.foreach.across.modules.web.ui.elements.HtmlViewElement
      Overrides:
      addCssClass in class com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
    • removeCssClass

      public ScriptViewElement removeCssClass(String... cssClass)
      Specified by:
      removeCssClass in interface com.foreach.across.modules.web.ui.elements.HtmlViewElement
      Overrides:
      removeCssClass in class com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
    • setAttributes

      public ScriptViewElement setAttributes(Map<String,Object> attributes)
      Specified by:
      setAttributes in interface com.foreach.across.modules.web.ui.elements.HtmlViewElement
      Overrides:
      setAttributes in class com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
    • setAttribute

      public ScriptViewElement setAttribute(String attributeName, Object attributeValue)
      Specified by:
      setAttribute in interface com.foreach.across.modules.web.ui.elements.HtmlViewElement
      Overrides:
      setAttribute in class com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
    • addAttributes

      public ScriptViewElement addAttributes(Map<String,Object> attributes)
      Specified by:
      addAttributes in interface com.foreach.across.modules.web.ui.elements.HtmlViewElement
      Overrides:
      addAttributes in class com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
    • removeAttribute

      public ScriptViewElement removeAttribute(String attributeName)
      Specified by:
      removeAttribute in interface com.foreach.across.modules.web.ui.elements.HtmlViewElement
      Overrides:
      removeAttribute in class com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
    • setName

      public ScriptViewElement setName(String name)
      Specified by:
      setName in interface com.foreach.across.modules.web.ui.MutableViewElement
      Overrides:
      setName in class com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
    • setCustomTemplate

      public ScriptViewElement setCustomTemplate(String customTemplate)
      Specified by:
      setCustomTemplate in interface com.foreach.across.modules.web.ui.MutableViewElement
      Overrides:
      setCustomTemplate in class com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
    • setElementType

      protected ScriptViewElement setElementType(String elementType)
      Overrides:
      setElementType in class com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
    • addChild

      public ScriptViewElement addChild(com.foreach.across.modules.web.ui.ViewElement element)
      Overrides:
      addChild in class com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
    • addChildren

      public ScriptViewElement addChildren(Collection<? extends com.foreach.across.modules.web.ui.ViewElement> elements)
      Overrides:
      addChildren in class com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
    • addFirstChild

      public ScriptViewElement addFirstChild(com.foreach.across.modules.web.ui.ViewElement element)
      Overrides:
      addFirstChild in class com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
    • clearChildren

      public ScriptViewElement clearChildren()
      Overrides:
      clearChildren in class com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
    • apply

      public ScriptViewElement apply(Consumer<com.foreach.across.modules.web.ui.elements.ContainerViewElement> consumer)
      Overrides:
      apply in class com.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 class com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
    • setTagName

      protected ScriptViewElement setTagName(String tagName)
      Overrides:
      setTagName in class com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
    • setHtmlId

      public ScriptViewElement setHtmlId(String htmlId)
      Specified by:
      setHtmlId in interface com.foreach.across.modules.web.ui.elements.HtmlViewElement
      Overrides:
      setHtmlId in class com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
    • set

      public ScriptViewElement set(com.foreach.across.modules.web.ui.ViewElement.WitherSetter... setters)
      Specified by:
      set in interface com.foreach.across.modules.web.ui.elements.HtmlViewElement
      Specified by:
      set in interface com.foreach.across.modules.web.ui.MutableViewElement
      Specified by:
      set in interface com.foreach.across.modules.web.ui.ViewElement
      Overrides:
      set in class com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
    • remove

      public ScriptViewElement remove(com.foreach.across.modules.web.ui.ViewElement.WitherRemover... functions)
      Specified by:
      remove in interface com.foreach.across.modules.web.ui.elements.HtmlViewElement
      Specified by:
      remove in interface com.foreach.across.modules.web.ui.MutableViewElement
      Specified by:
      remove in interface com.foreach.across.modules.web.ui.ViewElement
      Overrides:
      remove in class com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement
    • getRefTagName

      @NonNull public @NonNull String getRefTagName()
      The tag which should be rendered if the script element is deferred, in case of a nested script tag.
    • setRefTagName

      public ScriptViewElement setRefTagName(@NonNull @NonNull String refTagName)
      The tag which should be rendered if the script element is deferred, in case of a nested script tag.
      Returns:
      this.