/ZendFramework/demos/Zend/ProgressBar/JsPush.php

https://bitbucket.org/Dal-Papa/is-340-publish-base · PHP · 165 lines · 115 code · 27 blank · 23 comment · 8 complexity · 6b12c88c68206e0577417ae8ad176a70 MD5 · raw file

  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_ProgressBar
  17. * @subpackage Demos
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * This sample file demonstrates a simple use case of a jspush-driven progressbar
  23. */
  24. if (isset($_GET['progress'])) {
  25. set_include_path(realpath(dirname(__FILE__) . '/../../../library')
  26. . PATH_SEPARATOR . get_include_path());
  27. require_once 'Zend/ProgressBar.php';
  28. require_once 'Zend/ProgressBar/Adapter/JsPush.php';
  29. $adapter = new Zend_ProgressBar_Adapter_JsPush(array('updateMethodName' => 'Zend_ProgressBar_Update',
  30. 'finishMethodName' => 'Zend_ProgressBar_Finish'));
  31. $progressBar = new Zend_ProgressBar($adapter, 0, 100);
  32. for ($i = 1; $i <= 100; $i++) {
  33. if ($i < 20) {
  34. $text = 'Just beginning';
  35. } else if ($i < 50) {
  36. $text = 'A bit done';
  37. } else if ($i < 80) {
  38. $text = 'Getting closer';
  39. } else {
  40. $text = 'Nearly done';
  41. }
  42. $progressBar->update($i, $text);
  43. usleep(100000);
  44. }
  45. $progressBar->finish();
  46. die;
  47. }
  48. ?>
  49. <html>
  50. <head>
  51. <title>Zend_ProgressBar Javascript Push Demo and Test</title>
  52. <style type="text/css">
  53. iframe {
  54. position: absolute;
  55. left: -100px;
  56. top: -100px;
  57. width: 10px;
  58. height: 10px;
  59. overflow: hidden;
  60. }
  61. #progressbar {
  62. position: absolute;
  63. left: 10px;
  64. top: 10px;
  65. }
  66. .pg-progressbar {
  67. position: relative;
  68. width: 250px;
  69. height: 24px;
  70. overflow: hidden;
  71. border: 1px solid #c6c6c6;
  72. }
  73. .pg-progress {
  74. z-index: 150;
  75. position: absolute;
  76. left: 0;
  77. top: 0;
  78. width: 0;
  79. height: 24px;
  80. overflow: hidden;
  81. }
  82. .pg-progressstyle {
  83. height: 22px;
  84. border: 1px solid #748a9e;
  85. background-image: url('animation.gif');
  86. }
  87. .pg-text,
  88. .pg-invertedtext {
  89. position: absolute;
  90. left: 0;
  91. top: 4px;
  92. width: 250px;
  93. text-align: center;
  94. font-family: sans-serif;
  95. font-size: 12px;
  96. }
  97. .pg-invertedtext {
  98. color: #ffffff;
  99. }
  100. .pg-text {
  101. z-index: 100;
  102. color: #000000;
  103. }
  104. </style>
  105. <script type="text/javascript">
  106. function startProgress()
  107. {
  108. var iFrame = document.createElement('iframe');
  109. document.getElementsByTagName('body')[0].appendChild(iFrame);
  110. iFrame.src = 'JsPush.php?progress';
  111. }
  112. function Zend_ProgressBar_Update(data)
  113. {
  114. document.getElementById('pg-percent').style.width = data.percent + '%';
  115. document.getElementById('pg-text-1').innerHTML = data.text;
  116. document.getElementById('pg-text-2').innerHTML = data.text;
  117. }
  118. function Zend_ProgressBar_Finish()
  119. {
  120. document.getElementById('pg-percent').style.width = '100%';
  121. document.getElementById('pg-text-1').innerHTML = 'Demo done';
  122. document.getElementById('pg-text-2').innerHTML = 'Demo done';
  123. }
  124. </script>
  125. </head>
  126. <body onload="startProgress();">
  127. <div id="progressbar">
  128. <div class="pg-progressbar">
  129. <div class="pg-progress" id="pg-percent">
  130. <div class="pg-progressstyle"></div>
  131. <div class="pg-invertedtext" id="pg-text-1"></div>
  132. </div>
  133. <div class="pg-text" id="pg-text-2"></div>
  134. </div>
  135. </div>
  136. <div id="progressBar"><div id="progressDone"></div></div>
  137. </body>
  138. </html>