dialog.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <!DOCTYPE html>
  2. <html>
  3. <!--
  4. Copyright 2010 The Closure Library Authors. All Rights Reserved.
  5. Use of this source code is governed by the Apache License, Version 2.0.
  6. See the COPYING file for details.
  7. -->
  8. <head>
  9. <title>goog.ui.Dialog</title>
  10. <script src="../base.js"></script>
  11. <script>
  12. goog.require('goog.events');
  13. goog.require('goog.events.EventType');
  14. goog.require('goog.html.testing');
  15. goog.require('goog.ui.Dialog');
  16. </script>
  17. <link rel="stylesheet" href="css/demo.css">
  18. <link rel="stylesheet" href="../css/dialog.css">
  19. <style>
  20. .modal-dialog {
  21. width: 430px;
  22. }
  23. </style>
  24. </head>
  25. <body>
  26. <h1>goog.ui.Dialog</h1>
  27. <div><input id="openOnKeyDown" type="checkbox">
  28. <label>Enable open on keydown</label>
  29. <span>(use "Space" to open dialog with no Iframe, "Enter" to open with Iframe
  30. mask</span>
  31. </div>
  32. <div><input id="swapModalOnShift" type="checkbox">
  33. <label>Enable modal change with shift when the dialog is open</label>
  34. </div>
  35. <button onclick="showDialog(dialog1);">
  36. Open Dialog (no Iframe)</button>
  37. <br>
  38. <button onclick="showDialog(dialog2);">
  39. Open Dialog (w/ Iframe mask)
  40. </button>
  41. <fieldset style="margin-top: 2em;">
  42. <legend>A sample web page</legend>
  43. <h2>
  44. A World Beyond AJAX: Accessing Google's APIs from Flash and
  45. Non-JavaScript Environments
  46. </h2>
  47. <cite>Vadim Spivak (Google)</cite>
  48. <p>
  49. AJAX isn't the only way to access Google APIs. Learn how to use Google's
  50. services from Flash and other non-JavaScript programming environments.
  51. We'll show you how easy it is to augment your site with dynamic search
  52. and feed data from non-JavaScript environments.
  53. </p>
  54. <p>
  55. Participants should be familiar with general web application
  56. development.
  57. </p>
  58. <p>Select Element:
  59. <select>
  60. <option>Option 1</option>
  61. <option>Option 2</option>
  62. <option>Option 3</option>
  63. </select>
  64. </p>
  65. <p>
  66. <object width="425" height="344">
  67. <param name="movie"
  68. value="http://www.youtube.com/v/7fbz8WOec1g&hl=en&fs=1&"></param>
  69. <param name="allowFullScreen" value="true"></param>
  70. <param name="allowscriptaccess" value="always"></param>
  71. <embed
  72. src="http://www.youtube.com/v/7fbz8WOec1g&hl=en&fs=1&"
  73. type="application/x-shockwave-flash" allowscriptaccess="always"
  74. allowfullscreen="true" width="425" height="344"></embed>
  75. </object>
  76. </p>
  77. </fieldset>
  78. <script>
  79. goog.events.listen(document, goog.events.EventType.KEYDOWN, function(e) {
  80. var code = e.keyCode;
  81. if (goog.dom.getElement('openOnKeyDown').checked) {
  82. switch (code) {
  83. case goog.events.KeyCodes.MAC_ENTER:
  84. case goog.events.KeyCodes.ENTER:
  85. showDialog(dialog1);
  86. break;
  87. case goog.events.KeyCodes.SPACE:
  88. showDialog(dialog2);
  89. break;
  90. default:
  91. // no-op
  92. }
  93. }
  94. if (goog.dom.getElement('swapModalOnShift').checked) {
  95. switch (code) {
  96. case goog.events.KeyCodes.SHIFT:
  97. if (currDialog && currDialog.isVisible()) {
  98. currDialog.setModal(!currDialog.getModal());
  99. }
  100. break;
  101. default:
  102. // no-op
  103. }
  104. }
  105. });
  106. var dialog1 = new goog.ui.Dialog();
  107. dialog1.setSafeHtmlContent(goog.html.testing.newSafeHtmlForTest(
  108. '<img src="http://images.icanhascheezburger.com/' +
  109. 'completestore/2009/3/25/128825075025577352.jpg" ' +
  110. 'width="400" height="255"><br>' +
  111. 'Lorem ipsum dolor sit amet, consectetuer' +
  112. 'adipiscing elit. Aenean sollicitudin ultrices urna. Proin vehicula ' +
  113. 'mauris ac est. Ut scelerisque, risus ut facilisis dictum, est massa ' +
  114. 'lacinia lorem, in fermentum purus ligula quis nunc. Duis porttitor ' +
  115. 'euismod risus. Nam hendrerit lacus vehicula augue. Duis ante.'));
  116. dialog1.setTitle('My favorite LOLCat');
  117. dialog1.setButtonSet(goog.ui.Dialog.ButtonSet.CONTINUE_SAVE_CANCEL);
  118. goog.events.listen(dialog1, goog.ui.Dialog.EventType.SELECT, function(e) {
  119. alert('You chose: ' + e.key);
  120. });
  121. var dialog2 = new goog.ui.Dialog(null, true);
  122. dialog2.setTextContent('Some windowed elements leak through standard ' +
  123. 'divs so we add an iframe to mask the nasties.');
  124. dialog2.setTitle('I have an Iframe mask :)');
  125. dialog2.setButtonSet(goog.ui.Dialog.ButtonSet.YES_NO_CANCEL);
  126. goog.events.listen(dialog2, goog.ui.Dialog.EventType.SELECT, function(e) {
  127. alert('You chose: ' + e.key);
  128. });
  129. var currDialog;
  130. function showDialog(dialog) {
  131. currDialog = dialog;
  132. dialog.setVisible(true);
  133. }
  134. </script>
  135. </body>
  136. </html>