--- layout : 'default' css : 'modal-demo' title : 'Modal' description : 'A modal displays content that temporarily blocks interactions with a web site' type : 'UI Module' --- <%- @partial('header') %>

Usage

Initializing a modal

A modal can be included anywhere on the page. On initialization a modal's current size will be cached, and the element will be detached from the dom and moved inside a dimmer.

Why move modal content?

Having a modal inside the page dimmer allows for 3D animations without having the 3D perspective settings alter the rest of the page content. Additionally, content outside the dimmer can be blurred or altered without affecting the modal's content.

$('.ui.modal') .modal() ;

Types

Standard

A standard modal

$('.test.modal') .modal('show') ;

Basic

A modal can reduce its complexity

$('.basic.modal') .modal('show') ;

Variations

Size

A modal can vary in size

$('.small.modal') .modal('show') ;
$('.large.modal') .modal('show') ;

States

Active

An active modal is visible on the page

Examples

Approve / Deny Callbacks

Modals will automatically tie approve deny callbacks to any positive/approve or negative/deny buttons

$('.basic.modal') .modal('setting', 'onDeny', function(){ window.alert('Denied!'); }) .modal('setting', 'onApprove', function(){ window.alert('Approved!'); }) .modal('show') ;

Forcing a Choice

You can disable a modal's dimmer from being closed by click to force a user to make a choice

$('.basic.modal') .modal('setting', 'closable', false) .modal('show') ;

Transitions

A modal can use any named ui transition.

$('.selection') .dropdown({ onChange: function(value) { $('.test.modal') .modal('setting', 'transition', value) .modal('show') ; } }) ;

Behavior

Attach events

A modal can attach events to another element

$('.test.modal') .modal('attach events', '.test.button', 'show') ;
Launch modal

Show

A modal can show itself

$('.test.modal') .modal('show') ;

Hide

A modal can hide itself

$('.test.modal') .modal('hide') ;

Toggle

A modal can toggle its visibility

$('.test.modal') .modal('toggle') ;
Additionally, all the following behaviors can be called using the syntax $('.foo').modal('behavior name', argumentOne, argumentTwo)
refresh Refreshes centering of modal on page
show dimmer Shows associated page dimmer
hide dimmer Hides associated page dimmer
hide all Hides all visible modals initialized at the same time
cache sizes Caches current modal size
can fit Returns whether the modal can fit on the page
is active Returns whether the modal is active
set active Sets modal to active

Settings

Modal Settings

Modal settings modify the modal's behavior

Setting Default Description
offset 0 A vertical offset to allow for content outside of modal, for example a close button, to be centered.
context body Selector or jquery object specifying the area to dim
closable true Settings to false will not allow you to close the modal by clicking on the dimmer
transition scale Named transition to use when animating menu in and out. Fade is available without including ui transitions
duration 400 Duration of animation
easing easeOutExpo Animation easing is only used if javascript animations are used.

Callbacks

Callback settings specify a function to occur after a specific behavior.

Setting Context Description
onShow Modal Is called after a modal is shown.
onHide Modal Is called after a modal is hidden.
onApprove Modal Is called after a positive or approve button is pressed
onDeny Modal Is called after a negative or cancel button is pressed.

DOM Settings

DOM settings specify how this module should interface with the DOM

Setting Default Description
namespace modal Event namespace. Makes sure module teardown does not effect other events attached to an element.
selector
selector : { close : '.close, .actions .button', approve : '.actions .positive, .actions .approve', deny : '.actions .negative, .actions .cancel' },
className
className : { active : 'active', scrolling : 'scrolling' }

Debug Settings

Debug settings controls debug output to the console

Setting Default Description
name Modal Name used in debug logs
debug True Provides standard debug output to console
performance True Provides standard debug output to console
verbose True Provides ancillary debug output to console
error
error : { method : 'The method you called is not defined.'' }