JqueryUI - Progressbar Display status of a determinate or indeterminate process.


SUBMITTED BY: jlolk3r

DATE: Feb. 5, 2016, 3:02 a.m.

FORMAT: HTML

SIZE: 2.9 kB

HITS: 704

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>jQuery UI Progressbar - Download Dialog</title>
  6. <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  7. <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  8. <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  9. <link rel="stylesheet" href="/resources/demos/style.css">
  10. <script>
  11. $(function() {
  12. var progressTimer,
  13. progressbar = $( "#progressbar" ),
  14. progressLabel = $( ".progress-label" ),
  15. dialogButtons = [{
  16. text: "Cancel Download",
  17. click: closeDownload
  18. }],
  19. dialog = $( "#dialog" ).dialog({
  20. autoOpen: false,
  21. closeOnEscape: false,
  22. resizable: false,
  23. buttons: dialogButtons,
  24. open: function() {
  25. progressTimer = setTimeout( progress, 2000 );
  26. },
  27. beforeClose: function() {
  28. downloadButton.button( "option", {
  29. disabled: false,
  30. label: "Start Download"
  31. });
  32. }
  33. }),
  34. downloadButton = $( "#downloadButton" )
  35. .button()
  36. .on( "click", function() {
  37. $( this ).button( "option", {
  38. disabled: true,
  39. label: "Downloading..."
  40. });
  41. dialog.dialog( "open" );
  42. });
  43. progressbar.progressbar({
  44. value: false,
  45. change: function() {
  46. progressLabel.text( "Current Progress: " + progressbar.progressbar( "value" ) + "%" );
  47. },
  48. complete: function() {
  49. progressLabel.text( "Complete!" );
  50. dialog.dialog( "option", "buttons", [{
  51. text: "Close",
  52. click: closeDownload
  53. }]);
  54. $(".ui-dialog button").last().focus();
  55. }
  56. });
  57. function progress() {
  58. var val = progressbar.progressbar( "value" ) || 0;
  59. progressbar.progressbar( "value", val + Math.floor( Math.random() * 3 ) );
  60. if ( val <= 99 ) {
  61. progressTimer = setTimeout( progress, 50 );
  62. }
  63. }
  64. function closeDownload() {
  65. clearTimeout( progressTimer );
  66. dialog
  67. .dialog( "option", "buttons", dialogButtons )
  68. .dialog( "close" );
  69. progressbar.progressbar( "value", false );
  70. progressLabel
  71. .text( "Starting download..." );
  72. downloadButton.focus();
  73. }
  74. });
  75. </script>
  76. <style>
  77. #progressbar {
  78. margin-top: 20px;
  79. }
  80. .progress-label {
  81. font-weight: bold;
  82. text-shadow: 1px 1px 0 #fff;
  83. }
  84. .ui-dialog-titlebar-close {
  85. display: none;
  86. }
  87. </style>
  88. </head>
  89. <body>
  90. <div id="dialog" title="File Download">
  91. <div class="progress-label">Starting download...</div>
  92. <div id="progressbar"></div>
  93. </div>
  94. <button id="downloadButton">Start Download</button>
  95. </body>
  96. </html>

comments powered by Disqus