PageRenderTime 61ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/docs/pages/page-dialogs.html

https://github.com/dannyc/jquery-mobile
HTML | 138 lines | 101 code | 37 blank | 0 comment | 0 complexity | e11931688111a0da789dcbb7f75408db MD5 | raw file
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <title>jQuery Mobile Docs - Dialogs</title>
  7. <link rel="stylesheet" href="../../css/themes/default/" />
  8. <link rel="stylesheet" href="../_assets/css/jqm-docs.css"/>
  9. <script src="../../js/jquery.js"></script>
  10. <script src="../../experiments/themeswitcher/jquery.mobile.themeswitcher.js"></script>
  11. <script src="../_assets/js/jqm-docs.js"></script>
  12. <script src="../../js/"></script>
  13. </head>
  14. <body>
  15. <div data-role="page" class="type-interior">
  16. <div data-role="header" data-theme="f">
  17. <h1>Dialogs</h1>
  18. <a href="../../" data-icon="home" data-iconpos="notext" data-direction="reverse" class="ui-btn-right jqm-home">Home</a>
  19. </div><!-- /header -->
  20. <div data-role="content" class="ui-body">
  21. <div class="content-primary">
  22. <h2>Creating dialogs</h2>
  23. <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>
  24. <p>
  25. <code>
  26. &lt;a href=&quot;foo.html&quot; data-rel=&quot;dialog&quot;&gt;Open dialog&lt;/a&gt;
  27. </code>
  28. </p>
  29. <a href="dialog.html" data-role="button" data-inline="true" data-rel="dialog" data-transition="pop">Open dialog</a>
  30. <h2>Transitions</h2>
  31. <p>By default, the dialog will open with a 'pop' transition. Like all pages, you can specify any page transition 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", "slideup" or "flip".</p>
  32. <code>
  33. &lt;a href=&quot;foo.html&quot; data-rel=&quot;dialog&quot; data-transition=&quot;pop&quot;&gt;Open dialog&lt;/a&gt;
  34. </code>
  35. <div>
  36. <a href="dialog.html" data-role="button" data-inline="true" data-rel="dialog" data-transition="pop">data-transition="pop"</a>
  37. <a href="dialog.html" data-role="button" data-inline="true" data-rel="dialog" data-transition="slidedown">data-transition="slidedown"</a>
  38. <a href="dialog.html" data-role="button" data-inline="true" data-rel="dialog" data-transition="flip">data-transition="flip"</a>
  39. </div>
  40. <h2>Closing dialogs</h2>
  41. <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>
  42. <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>
  43. <h3>The close button</h3>
  44. <p>By default dialogs are automatically given an icon only close button if the dialog has a header. Clicking this button triggers the dialogs close function and is identical to clicking the browsers back button. If you prefer to not have the close button or prefer to create your own there is a data attribute <code>data-include-close-btn</code> that configures if the button should be automatically added.</p>
  45. <code>
  46. &lt;div data-role="page" id="popup" data-include-close-btn="false"&gt;
  47. </code>
  48. <h3>Setting the close button text and icon position</h3>
  49. <p>Just like the page plugin, you can set a dialog's close button text through an option or data attribute. 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. Additionally you can configure the icon position using the <code>data-iconpos</code> attribute. By default the iconpos attribute is set to "notext" and the button text will not be visible. Setting the iconpos to "none" will create a text only button.</p>
  50. <code>
  51. &lt;div data-role="page" id="popup" data-iconpos="left" data-close-btn-text="Nevermind"&gt;
  52. </code>
  53. <h2>History &amp; Back button behavior</h2>
  54. <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>
  55. <h2>Styling &amp; theming</h2>
  56. <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>
  57. <a href="dialog-alt.html" data-role="button" data-inline="true" data-rel="dialog" data-transition="pop">An alternate color scheme</a>
  58. <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>
  59. <a href="dialog-overlay.html" data-role="button" data-inline="true" data-rel="dialog" data-transition="pop">Custom overlay swatch</a>
  60. <p>Dialogs can also be used more like a control sheet to offer multiple buttons by removing the header:</p>
  61. <a href="dialog-buttons.html" data-role="button" data-inline="true" data-rel="dialog" data-transition="slidedown">Share photos...</a>
  62. <h2>Dialog width and margins</h2>
  63. <p>For the sake of readability, dialogs have a default <code>max-width</code> of 500 pixels (plus 15px padding on each side). 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. To override these styles, add the following CSS override rule to your stylesheet and tweak as needed:</p>
  64. <code><pre>
  65. .ui-dialog .ui-header,
  66. .ui-dialog .ui-content,
  67. .ui-dialog .ui-footer {
  68. <strong> max-width: 500px;
  69. margin: 10% auto 15px auto; </strong>
  70. }
  71. </pre></code>
  72. </div><!--/content-primary -->
  73. <div class="content-secondary">
  74. <div data-role="collapsible" data-collapsed="true" data-theme="b" data-content-theme="d">
  75. <h3>More in this section</h3>
  76. <ul data-role="listview" data-theme="c" data-dividertheme="d">
  77. <li data-role="list-divider">Pages &amp; Dialogs</li>
  78. <li><a href="page-anatomy.html">Anatomy of a page</a></li>
  79. <li><a href="page-template.html" data-ajax="false">Single page template</a></li>
  80. <li><a href="multipage-template.html" data-ajax="false">Multi-page template</a></li>
  81. <li><a href="page-titles.html">Page titles</a></li>
  82. <li><a href="page-links.html">Linking pages</a></li>
  83. <li><a href="page-transitions.html" data-ajax="false">Page transitions</a></li>
  84. <li data-theme="a"><a href="page-dialogs.html">Dialogs</a></li>
  85. <li><a href="page-cache.html">Prefetching &amp; caching pages</a></li>
  86. <li><a href="page-navmodel.html">Ajax, hashes &amp; history</a></li>
  87. <li><a href="page-dynamic.html">Dynamically injecting pages</a></li>
  88. <li><a href="page-scripting.html">Scripting pages</a></li>
  89. <li><a href="phonegap.html">PhoneGap apps</a></li>
  90. <li><a href="touchoverflow.html">touchOverflow feature</a></li>
  91. <li><a href="pages-themes.html">Theming pages</a></li>
  92. </ul>
  93. </div>
  94. </div>
  95. </div><!-- /content -->
  96. <div data-role="footer" class="footer-docs" data-theme="c">
  97. <p>&copy; 2011 The jQuery Project</p>
  98. </div>
  99. </div><!-- /page -->
  100. </body>
  101. </html>