Dialog Optional
Displays content in a dialog box, a subwindow above the other elements of the page.
Features
- Uses modern Html
<dialog>
tag. - Can be used to display static content, or content from url.
- Manages autofocus; when opened from keyboard, the close button will be focused.
- Styles for media, e.g. images and video.
- Executes
<script>
tags from relative urls.
Configuration
- Include the compiled css file in the Html:
<link href="/css/components/dialog.min.css" rel="stylesheet" />
- Include the compiled javascript file in the Html:
<script src="/javascript/dialog.min.js"></script>
Implementation
Basic
Set the data-dialog
attribute of an element. The component will automatically determine which action to take based on the attribute value. The attribute can contain:
- Html
- Url
- A selector to an element within the document
- Empty - get url from
href
attribute (<a>
tag)
Advanced
The dialog can also be implemented programatically, via javascript. Useful functions for opening a dialog are:
dialog.open.html(code);
- Show html.dialog.open.element(selector);
- Show html from the first element within the document that matches the specified selector.dialog.open.url(href);
- Fetch html from url.
Examples
View source for Html code.
Attributes
Static content via attribute: open
Static content from element: open
Url content via url: open
Url content via href attribute: open
Media
Image: open
Image, large: open
Image, with caption: open
Video, YouTube: open
Video, YouTube, large: open
Video, Vimeo: open
Video, Vimeo, with caption: open