Package com.vaadin.client
Class PolymerUtils
java.lang.Object
com.vaadin.client.PolymerUtils
Utils class, intended to ease working with Polymer related code on a client
side.
- Since:
- 1.0.
- Author:
- Vaadin Ltd
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddReadyListener(elemental.dom.Element polymerElement, Runnable listener) Adds thelistenerwhich will be invoked when thepolymerElementbecomes "ready" meaning that it's methodreadyis called.static elemental.json.JsonValuecreateModelTree(Object object) Makes an attempt to convert an object into json.static voidfireReadyEvent(elemental.dom.Element polymerElement) Fires the ready event for thepolymerElement.static elemental.dom.ElementgetCustomElement(elemental.dom.Node root, elemental.json.JsonArray path) Gets the custom element usingpathof indices starting from theroot.static elemental.dom.ElementgetDomElementById(elemental.dom.Node shadowRootParent, String id) Deprecated.This is Polymer specific.static elemental.dom.ElementgetDomRoot(elemental.dom.Node templateElement) Returns the shadow root of thetemplateElement.static elemental.dom.NodegetElementInShadowRootById(elemental.dom.ShadowRoot shadowRoot, String id) Deprecated.This is not in use anywhere and can be removedstatic StringGets the tag name of thenode.static booleanDeprecated.Use the genericElementUtil.hasTag(Node, String)insteadstatic voidinvokeWhenDefined(String tagName, Runnable runnable) Invokes therunnablewhen the custom element with the giventagNameis initialized (its DOM structure becomes available).static booleanisInShadowRoot(elemental.dom.Element element) Returns true if and only if the element has a shadow root ancestor.static booleanisPolymerElement(elemental.dom.Element htmlNode) Checks whether thehtmlNodeis a polymer 2 element.static booleanisReady(elemental.dom.Node shadowRootParent) Returnstrueif the DOM structure of the polymer custom elementshadowRootParentis ready (meaning that it has shadow root and its shadow root may be queried for children referenced by id).static booleanmayBePolymerElement(elemental.dom.Element htmlNode) Deprecated.This is not in use anywhere and can be removedstatic elemental.dom.NodesearchForElementInShadowRoot(elemental.dom.ShadowRoot shadowRoot, String cssQuery) Deprecated.This is not in use anywhere and can be removedstatic voidsetListValueByIndex(elemental.dom.Element htmlNode, String path, int listIndex, elemental.json.JsonValue newValue) Sets new value for list element for specifiedhtmlNode.static voidsetProperty(elemental.dom.Element element, String path, Object value) Sets a property to an element by using the Polymersetmethod.static voidsplice(elemental.dom.Element htmlNode, String path, int startIndex, int deleteCount, elemental.json.JsonArray itemsToAdd) Calls Polymersplicemethod on specifiedhtmlNode.static voidstoreNodeId(elemental.dom.Node domNode, int id, String path) Store the StateNode.id into the polymer property under 'nodeId'
-
Method Details
-
setListValueByIndex
public static void setListValueByIndex(elemental.dom.Element htmlNode, String path, int listIndex, elemental.json.JsonValue newValue) Sets new value for list element for specifiedhtmlNode.- Parameters:
htmlNode- node to call set method onpath- polymer model path to propertylistIndex- list index to set element intonewValue- new value to be set at desired index- See Also:
-
splice
public static void splice(elemental.dom.Element htmlNode, String path, int startIndex, int deleteCount, elemental.json.JsonArray itemsToAdd) Calls Polymersplicemethod on specifiedhtmlNode. Splice call is made viaapplymethod in order to force the method to treatitemsToAddas numerous parameters, not a single one.- Parameters:
htmlNode- node to call splice method onpath- polymer model path to propertystartIndex- start index of a list for splice operationdeleteCount- number of elements to delete from the list after startIndexitemsToAdd- elements to add after startIndex- See Also:
-
storeNodeId
Store the StateNode.id into the polymer property under 'nodeId'- Parameters:
domNode- polymer dom nodeid- id of a state nodepath- polymer model path to property
-
createModelTree
Makes an attempt to convert an object into json.- Parameters:
object- the object to convert to json- Returns:
- json from object,
nullfor null
-
isPolymerElement
public static boolean isPolymerElement(elemental.dom.Element htmlNode) Checks whether thehtmlNodeis a polymer 2 element.- Parameters:
htmlNode- HTML element to check- Returns:
trueif thehtmlNodeis a polymer element
-
mayBePolymerElement
Deprecated.This is not in use anywhere and can be removedChecks whether thehtmlNodecan turn into polymer 2 element later.Lazy loaded dependencies can load Polymer later than the element itself gets processed by the Flow. This method helps to determine such elements.
- Parameters:
htmlNode- HTML element to check- Returns:
trueif thehtmlNodecan become a polymer 2 element
-
searchForElementInShadowRoot
@Deprecated public static elemental.dom.Node searchForElementInShadowRoot(elemental.dom.ShadowRoot shadowRoot, String cssQuery) Deprecated.This is not in use anywhere and can be removedGet first element by css query in the shadow root provided.- Parameters:
shadowRoot- shadow root elementcssQuery- css query- Returns:
- first element matching the query or
nullfor no matches - See Also:
-
getElementInShadowRootById
@Deprecated public static elemental.dom.Node getElementInShadowRootById(elemental.dom.ShadowRoot shadowRoot, String id) Deprecated.This is not in use anywhere and can be removedGet the element by id from the shadow root provided.- Parameters:
shadowRoot- shadow root elementid- element id- Returns:
- the element with id provided or
nullfor no matches - See Also:
-
getDomElementById
@Deprecated public static elemental.dom.Element getDomElementById(elemental.dom.Node shadowRootParent, String id) Deprecated.This is Polymer specific. UseElementUtil.getElementById(Node, String)for the generic versionFind the DOM element inside shadow root of theshadowRootParent.- Parameters:
shadowRootParent- the parent whose shadow root contains the element with theidid- the identifier of the element to search for- Returns:
- the element with the given
idinside the shadow root of the parent
-
isReady
public static boolean isReady(elemental.dom.Node shadowRootParent) Returnstrueif the DOM structure of the polymer custom elementshadowRootParentis ready (meaning that it has shadow root and its shadow root may be queried for children referenced by id).- Parameters:
shadowRootParent- the polymer custom element- Returns:
trueif theshadowRootParentelement is ready
-
hasTag
Deprecated.Use the genericElementUtil.hasTag(Node, String)insteadChecks whether thenodehas requiredtag.- Parameters:
node- the node to checktag- the required tag name- Returns:
trueif the node has required tag name
-
getCustomElement
public static elemental.dom.Element getCustomElement(elemental.dom.Node root, elemental.json.JsonArray path) Gets the custom element usingpathof indices starting from theroot.- Parameters:
root- the root element to start frompath- the indices path identifying the custom element.- Returns:
- the element inside the
rootby the path of indices
-
getDomRoot
public static elemental.dom.Element getDomRoot(elemental.dom.Node templateElement) Returns the shadow root of thetemplateElement.- Parameters:
templateElement- the owner of the shadow root- Returns:
- the shadow root of the element
-
invokeWhenDefined
Invokes therunnablewhen the custom element with the giventagNameis initialized (its DOM structure becomes available).- Parameters:
tagName- the name of the custom elementrunnable- the command to run when the element if initialized
-
getTag
Gets the tag name of thenode.- Parameters:
node- the node to get the tag name from- Returns:
- the tag name of the node
-
addReadyListener
Adds thelistenerwhich will be invoked when thepolymerElementbecomes "ready" meaning that it's methodreadyis called.The listener won't be called if the element is already "ready" and the listener will be removed immediately once it's executed.
- Parameters:
polymerElement- the custom (polymer) element to listen its readiness statelistener- the callback to execute once the element becomes ready
-
fireReadyEvent
public static void fireReadyEvent(elemental.dom.Element polymerElement) Fires the ready event for thepolymerElement.- Parameters:
polymerElement- the custom (polymer) element whose state is "ready"
-
setProperty
Sets a property to an element by using the Polymersetmethod.- Parameters:
element- the element to set the property topath- the path of the propertyvalue- the value
-
isInShadowRoot
public static boolean isInShadowRoot(elemental.dom.Element element) Returns true if and only if the element has a shadow root ancestor.- Parameters:
element- the element to test- Returns:
- whether the element is in a shadow root
-