Skip to content
This repository
tree: d07f1b5af0
Fetching contributors…

Cannot retrieve contributors at this time

file 149 lines (109 sloc) 9.409 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery Mobile Docs - Dialogs</title>
<link rel="stylesheet" href="../../../css/themes/default/" />
<link rel="stylesheet" href="../../_assets/css/jqm-docs.css"/>

<script src="../../../js/jquery.js"></script>
<script src="../../../docs/_assets/js/jqm-docs.js"></script>
<script src="../../../js/"></script>


<div data-role="page" class="type-interior">

<div data-role="header" data-theme="f">
<a href="../../../" data-icon="home" data-iconpos="notext" data-direction="reverse">Home</a>
<a href="../../nav.html" data-icon="search" data-iconpos="notext" data-rel="dialog" data-transition="fade">Search</a>
</div><!-- /header -->

<div data-role="content" class="ui-body">
<div class="content-primary">
<form action="#" method="get">

            <ul data-role="controlgroup" data-type="horizontal" class="localnav">
<li><a href="index.html" data-role="button" data-transition="fade" class="ui-btn-active">Basics</a></li>
<li><a href="options.html" data-role="button" data-transition="fade">Options</a></li>
<li><a href="methods.html" data-role="button" data-transition="fade">Methods</a></li>
<li><a href="events.html" data-role="button" data-transition="fade">Events</a></li>
<p>Any page can be presented as a modal dialog by adding the <code>data-rel="dialog"</code> attribute to the page anchor link. When the "dialog" attribute is applied, the framework adds styles to add rounded corners, margins around the page and a dark background to make the "dialog" appear to be suspended above the page.</p>

&lt;a href=&quot;foo.html&quot; data-rel=&quot;dialog&quot;&gt;Open dialog&lt;/a&gt;

<a href="../dialog.html" data-role="button" data-inline="true" data-rel="dialog" data-transition="pop">Open dialog</a>

<p>By default, the dialog will open with a 'pop' transition. Like all pages, you can specify any <a href="page-transitions.html">page transition</a> you want on the dialog by adding the <code>data-transition</code> attribute to the link. To make it feel more dialog-like, we recommend specifying a transition of "pop", "slidedown" or "flip".</p>

&lt;a href=&quot;foo.html&quot; data-rel=&quot;dialog&quot; data-transition=&quot;pop&quot;&gt;Open dialog&lt;/a&gt;

<a href="../dialog.html" data-role="button" data-inline="true" data-rel="dialog" data-transition="pop">data-transition="pop"</a>
<a href="../dialog.html" data-role="button" data-inline="true" data-rel="dialog" data-transition="slidedown">data-transition="slidedown"</a>
<a href="../dialog.html" data-role="button" data-inline="true" data-rel="dialog" data-transition="flip">data-transition="flip"</a>

<h2>Closing dialogs</h2>
<p>When any link is clicked within in a dialog, the framework will automatically close the dialog and transition to the requested page, just as if the dialog were a normal page. To create a "cancel" button in a dialog, just link to the page that triggered the dialog to open and add the <code>data-rel="back"</code> attribute to your link. This pattern of linking to the previous page is also usable in non-JS devices as well.</p>
<p>For JavaScript-generated links, you can simply set the href attribute to "#" and use the <code>data-rel="back"</code> attribute. You can also call the dialog's <code>close()</code> method to programmatically close dialogs, for example: <code>$('.ui-dialog').dialog('close')</code>. </p>

<h3>Setting the close button text</h3>
<p>Just like the page plugin, you can set a dialog's close button text through an option or data attribute.
This option is used to customize the text of the close button which is helpful for translating this into different languages. This is displayed as an icon-only button by default so the text isn't visible on-screen, but is read by screen readers so this is an important accessibility feature.
The option can be configured for all dialogs by binding to the <code>mobileinit</code> event and setting the <code>$.mobile.dialog.prototype.options.closeBtnText</code> property to a string of your choosing, or you can place the data attribute <code>data-close-btn-text</code> to configure the text from your markup.

<h2>History &amp; Back button behavior</h2>
<p>Since dialogs are typically used to support actions within a page, the framework does not include dialogs in the hash state history tracking. This means that dialogs will not appear in your browsing history chronology when the Back button is clicked. For example, if you are on a page, click a link to open a dialog, close the dialog, then navigate to another page, if you were to click the browser's Back button at that point you will navigate back to the first page, not the dialog.</p>

<h2>Chaining Dialogs</h2>
<p>Please note: If a dialog opens another dialog (chaining), closing the last one with a link of type <code>data-rel="back"</code> will always navigate to the previous dialog until the root-page of type <code>data-role="page"</code> is reached. This guarantees a consistent navigation between dialogs.</p>

<h2>Styling &amp; theming</h2>
<p>Dialogs can be styled with different theme swatches, just like any page by adding <code>data-theme</code> attributes to the header, content, or footer containers. Here is an example of a different dialog design:</p>
<a href="../dialog-alt.html" data-role="button" data-inline="true" data-rel="dialog" data-transition="pop">An alternate color scheme</a>

<p>Dialogs appear to be floating above an overlay layer. This overlay adopts the swatch "a" content color by default, but the <code>data-overlay-theme</code> attribute can be added to the page wrapper to set the overlay to any swatch letter. Here is an example of a dialog with the overlay set to swatch "e":</p>
<a href="../dialog-overlay.html" data-role="button" data-inline="true" data-rel="dialog" data-transition="pop">Custom overlay swatch</a>

<p>Dialogs can also be used more like a control sheet to offer multiple buttons if you simply remove the top margin from the dialog's inner container element. For example, if your dialog page had a class of <code>my-dialog</code>, you could add this CSS to pin that dialog to the top: <code> .ui-dialog-contain { margin-top: 0 }</code>, or you could just apply that style to all dialogs with <code>.ui-dialog .ui-dialog-contain { margin-top: 0 }</code>.</p>
<a href="../dialog-buttons.html" data-role="button" data-inline="true" data-rel="dialog" data-transition="slidedown">Share photos...</a>

<h2>Dialog width and margins</h2>
<p>For the sake of readability, dialogs have a default <code>width</code> of 92.5% and a <code>max-width</code> of 500 pixels. There is also a 10% top <code>margin</code> to give dialogs larger top margin on larger screens, but collapse to a small margin on smartphones. The dialog's inner container is shifted towards the <code>top</code> with 15px to hide the corner styling if a dialog is used as a control sheet (see above). To override these styles, add the following CSS override rule to your stylesheet and tweak as needed:</p>

.ui-dialog-contain {
<strong>width: 92.5%;</strong>
<strong>max-width: 500px;</strong>
<strong>margin: 10% auto 15px auto;</strong>
padding: 0;
position: relative;
<strong>top: -15px;</strong>

</div><!--/content-primary -->

<div class="content-secondary">

<div data-role="collapsible" data-collapsed="true" data-theme="b" data-content-theme="d">

<h3>More in this section</h3>

<ul data-role="listview" data-theme="c" data-dividertheme="d">

<li data-role="list-divider">Pages &amp; Dialogs</li>
<li><a href="../page-anatomy.html">Anatomy of a page</a></li>
<li><a href="../page-template.html" data-ajax="false">Single page template</a></li>
<li><a href="../multipage-template.html" data-ajax="false">Multi-page template</a></li>
<li><a href="../page-titles.html">Page titles</a></li>
<li><a href="../page-links.html">Linking pages</a></li>
<li><a href="../page-transitions.html">Page transitions</a></li>
<li><a href="../loader.html">Page loading widget</a></li>
<li data-theme="a"><a href="index.html">Dialogs</a></li>
<li><a href="../popup/index.html">Popups</a></li>
<li><a href="../page-cache.html">Prefetching &amp; caching pages</a></li>
<li><a href="../page-navmodel.html">Ajax, hashes &amp; history</a></li>
<li><a href="../page-dynamic.html">Dynamically injecting pages</a></li>
<li><a href="../page-scripting.html">Scripting pages</a></li>
<li><a href="../phonegap.html">PhoneGap apps</a></li>
<li><a href="../touchoverflow.html">touchOverflow feature</a></li>
<li><a href="../pages-themes.html">Theming pages</a></li>

</div><!-- /content -->

<div data-role="footer" class="footer-docs" data-theme="c">
<p>&copy; 2012 jQuery Foundation and other contributors</p>

</div><!-- /page -->

Something went wrong with that request. Please try again.