Phx.Live.Favicon (Phoenix Live Favicon v1.0.0)

View Source

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]").

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

Types

attr()

@type attr() :: Phx.Live.Head.attr()

class_name()

@type class_name() :: String.t()

name()

@type name() :: Phx.Live.Head.name()

placeholder()

@type placeholder() :: Phx.Live.Head.name()

value()

@type value() :: Phx.Live.Head.value()

Functions

add_class(socket, class_name)

Add a class_name to the list of classes on all favicon link elements

remove_attr(socket, attr)

Remove an attribute from all favicon link elements

remove_class(socket, class_name)

Remove a class_name from the list of classes on all favicon link elements

reset(socket)

@spec reset(Phoenix.LiveView.Socket.t()) :: map()

Reset all favicon link elements to their initial values

reset_attr(socket, attr)

Reset an attribute to it's initial value on all favicon link elements

restore(socket, name)

@spec restore(Phoenix.LiveView.Socket.t(), name()) :: map()

Restore snapshot with name

restore_attr(socket, name, attr)

@spec restore_attr(Phoenix.LiveView.Socket.t(), name(), attr()) :: map()

Restore an attribute from snapshot with named name

set_attr(socket, attr, value)

Set a new value to the attribute on all favicon link elements

set_class(socket, class)

Set the class on all favicon link elements

set_dynamic(socket, placeholder, value)

Set the value of a {placeholder} on all favicon link elements

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">

snap(socket, name)

@spec snap(Phoenix.LiveView.Socket.t(), name()) :: map()

Make a snapshot with name name of all favicon link element attribute values

snap_attr(socket, name, attr)

@spec snap_attr(Phoenix.LiveView.Socket.t(), name(), attr()) :: map()

Create a snapshot named name of an attribute from all favicon link element

toggle_class(socket, class_name)

Toggle class_name on all favicon link elements