-
Notifications
You must be signed in to change notification settings - Fork 33
Utility Functions
All Polymer elements mix in the PolymerBase
and PolymerMixin
classes, which
provide a set of useful convenience functions for instances to use.
-
$$(String selector)
. Returns the first node in this element's local DOM that matchesselector
. -
toggleClass(String name, [bool value, Element node])
. Toggles the named boolean class on the host element, adding the class ifvalue
is true and removing it ifvalue
is false or null. Ifnode
is specified, sets the class onnode
instead of the host element. -
toggleAttribute(String name, [bool value, Element node])
. LiketoggleClass
, but toggles the named boolean attribute. -
attributeFollows(String name, Element newNode, Element oldNode)
. Moves a boolean attribute fromoldNode
tonewNode
, unsetting the attribute (if set) onoldNode
and setting it onnewNode
. -
classFollows(String name, Element newNode, Element oldNode)
. Moves a class fromoldNode
tonewNode
, removing the class (if present) onoldNode
and adding it tonewNode
. -
fire(String type, {detail, bool canBubble, bool cancelable, Node node})
. Fires a custom event with the desired properties. -
int async(void callback(), {int waitTime})
. Callsmethod
asynchronously. If no wait time is specified, runs tasks with microtask timing (after the current method finishes, but before the next event from the event queue is processed). Returns a handle that can be used to cancel the task. -
cancelAsync(handle)
. Cancels the identified async task. -
debounce(String jobName, void callback(), {int waitTime})
. Calldebounce
to collapse multiple requests for a named task into one invocation, which is made after the wait time has elapsed with no new request. If no wait time is given, the callback is called at microtask timing (guaranteed to be before paint). -
cancelDebouncer(String jobName)
. Cancels an active debouncer without calling the callback. -
flushDebouncer(String jobName)
. Calls the debounced callback immediately and cancels the debouncer. -
bool isDebouncerActive(String jobName)
. Returns true if the named debounce task is waiting to run. -
transform(String transform, [Element node])
. Applies a CSS transform to the specified node, or host element if no node is specified.transform
is specified as a string. For example:transform('rotateX(90deg)', this.$['myDiv']);
-
translate3d(String x, String y, String z, [Element node])
. Transforms the specified node, or host element if no node is specified. For example:this.translate3d('100px', '100px', '100px');
-
importHref(String href, {void onLoad(e), void onError(e)})
. Dynamically imports an HTML document.Note: To call
importHref
from outside a Polymer element, usePolymer.importHref
. Dart Note: Html files imported this way cannot contain dart script tags.
this.importHref('path/to/page.html', (e) {
// e.target.import is the import document.
}, (e) {
// loading error
});