View Source Phx.Live.Favicon (Phoenix Live Favicon v0.2.0)
Provides commands for manipulating the Favicon of Phoenix Live View applications while minimizing data over the wire.
The available command actions support a variety of utility operations useful for Favicon manipulation. Such as setting or removing tag attributes and adding or removing CSS classes for vector (SVG) favicons.
The elements selected for manipulation are found by Javascript client code
document.querySelectorAll("link[rel*=icon]")
.
Link to this section Summary
Functions
Add a class_name
to the list of classes on all favicon link elements
Remove an attribute
from all favicon link elements
Remove a class_name
from the list of classes on all favicon link elements
Reset all favicon link elements to their initial values
Reset an attribute
to it's initial value on all favicon link elements
Restore snapshot with name
Restore an attribute
from snapshot with named name
Set a new value
to the attribute
on all favicon link elements
Set the class
on all favicon link elements
Set the value
of a {placeholder}
on all favicon link elements
Make a snapshot with name name
of all favicon link element attribute values
Create a snapshot named name
of an attribute
from all favicon link element
Toggle class_name
on all favicon link elements
Link to this section Types
@type attr() :: Phx.Live.Head.attr()
@type class_name() :: String.t()
@type name() :: Phx.Live.Head.name()
@type placeholder() :: Phx.Live.Head.name()
@type value() :: Phx.Live.Head.value()
Link to this section Functions
@spec add_class(Phoenix.LiveView.Socket.t(), class_name()) :: Phoenix.LiveView.Socket.t()
Add a class_name
to the list of classes on all favicon link elements
@spec remove_attr(Phoenix.LiveView.Socket.t(), attr()) :: Phoenix.LiveView.Socket.t()
Remove an attribute
from all favicon link elements
@spec remove_class(Phoenix.LiveView.Socket.t(), class_name()) :: Phoenix.LiveView.Socket.t()
Remove a class_name
from the list of classes on all favicon link elements
@spec reset(Phoenix.LiveView.Socket.t()) :: map()
Reset all favicon link elements to their initial values
@spec reset_attr(Phoenix.LiveView.Socket.t(), attr()) :: Phoenix.LiveView.Socket.t()
Reset an attribute
to it's initial value on all favicon link elements
@spec restore(Phoenix.LiveView.Socket.t(), name()) :: map()
Restore snapshot with name
@spec restore_attr(Phoenix.LiveView.Socket.t(), name(), attr()) :: map()
Restore an attribute
from snapshot with named name
@spec set_attr(Phoenix.LiveView.Socket.t(), attr(), value()) :: Phoenix.LiveView.Socket.t()
Set a new value
to the attribute
on all favicon link elements
@spec set_class(Phoenix.LiveView.Socket.t(), class_name()) :: Phoenix.LiveView.Socket.t()
Set the class
on all favicon link elements
@spec set_dynamic(Phoenix.LiveView.Socket.t(), placeholder(), value()) :: Phoenix.LiveView.Socket.t()
Set the value
of a {placeholder}
on all favicon link elements
dynamic-attributes-placeholders
Dynamic attributes / placeholders
To use a dynamic value for an attribute, the element must have an additional
data-dynamic-[attribute]
attribute with a value containing a named
placeholder. For example: {sub}
in attribute href
.
Example
<!-- data-dynamic-href is set -->
<!-- {sub} is used in it's value -->
<link rel='icon' href="default_fav.png" data-dynamic-href="favs/{sub}/fav-16x16.png">
When an event is pushed with set_dynamic("sub", "new_message")
the result will be:
<link rel='icon' href="favs/new_message/fav-16x16.png">
@spec snap(Phoenix.LiveView.Socket.t(), name()) :: map()
Make a snapshot with name name
of all favicon link element attribute values
@spec snap_attr(Phoenix.LiveView.Socket.t(), name(), attr()) :: map()
Create a snapshot named name
of an attribute
from all favicon link element
@spec toggle_class(Phoenix.LiveView.Socket.t(), class_name()) :: Phoenix.LiveView.Socket.t()
Toggle class_name
on all favicon link elements