public final class ComponentHandler extends Object
MaterialButton
is the js class that operates on buttons. In general, a component class
definess : componentHandler
is initiated. The
components classes are then defined. Each defined component registers itself
to componentHandler
and is mapped to a css selector. For
example, MaterialMenu
is mapped to mdl-js-menu
when
it is registered in componentHandler
.componentHandler
will retrieve the
mapped css and scan the DOM looking for elements decorated with that css
selector. The matched elements are to be upgraded using instances of the
component's class. Again, with the menus example, when
componentHandler
finds an element in the DOM containing the css
selector mdl-js-menu
, it sets up a new instance of
MaterialMenu
and feeds it with the element node of the menu.MaterialMenu
will then "upgrade" the
menu. It detaches the node from the DOM and puts a container in its place.
Then, it puts back the menu node inside the container and puts a background
node just before the menu node. The background node is of animation use when
the menu is opened.mdl-js-ripple-effect
,
the MaterialMenu
instance will add a ripple container in each
item of the menu.MaterialMenu
instance then retrieves the for attribute from
the menu element. That attributes holds the id of the action button that will
show the menu when it is clicked. It, then, locates the button in the DOM and
adds a click listener to it. It then adds the appropriate event handlers to
close the menu.componentHandler
scans the DOM looking for components to be
upgraded. In that case, componentHandler
will not find the
dynamically generated components because they are not attached to the DOM
yet. To handle this use case, componentHandler
exposes a set of
functions to deal with dynamically generated components.Element
to be upgraded is attached to
the DOM before firing the upgrade. For instance MaterialMenu
require that the to-be-upgraded component is already attached to the DOM and
since MaterialMenu
also scans the DOM looking for the action
button related to the menu it also requires that this button is itself
attached to the DOM.Modifier and Type | Method and Description |
---|---|
static void |
downgradeElement(com.google.gwt.dom.client.Element element)
Intuitively, one could think that the downgrade function symetrically does
the exact opposite of what the upgrade function does but in fact it does
not.
|
static void |
upgradeElement(com.google.gwt.dom.client.Element element)
Upgrade a specific component rather than all components of the DOM.
|
public static void upgradeElement(com.google.gwt.dom.client.Element element)
Element
must be provided as input. The
Element
node to be provided is the node decorated with the
mdl-js-xxx
css selector.The DOM tree of the component must
follow the guidelines enforced on declarative components regarding the
expected html and css styling.element
- the target html node of the component to be upgraded.public static void downgradeElement(com.google.gwt.dom.client.Element element)
element
- the DOM node to downgradeCopyright © 2016 com.github.ilyes4j. All rights reserved.