PageRenderTime 23ms CodeModel.GetById 40ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/manual.htm

https://github.com/philwhln/ajax-upload
HTML | 230 lines | 212 code | 15 blank | 3 comment | 0 complexity | 93b81f740bccc745842b231d926864b8 MD5 | raw file
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  5. <title>Testing AJAX Upload</title>
  6. <!-- We will load jQuery and Prototypejs to ensure that we don't have any conflicts -->
  7. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
  8. <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js" type="text/javascript"></script>
  9. <!-- Also test with jQuery UI Dialog-->
  10. <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-darkness/jquery-ui.css" type="text/css" media="all" />
  11. <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js" type="text/javascript"></script>
  12. <!-- AJAX Upload script itself doesn't have any dependencies -->
  13. <script type="text/javascript" src="../ajaxupload.js"></script>
  14. <style type="text/css">
  15. body {
  16. font-family: verdana;
  17. font-size: 12px;
  18. background: #373A32;
  19. color: #D0D0D0;
  20. }
  21. h1,h2 {
  22. font-size: 14px;
  23. font-weight: 400;
  24. color: white;
  25. }
  26. a {color: white;}
  27. .wr {
  28. width: 500px;
  29. margin: 0 auto;
  30. }
  31. .button {}
  32. .button.hover {color:green;}
  33. </style>
  34. </head>
  35. <body>
  36. <div class="wr">
  37. <p>This is a set of tests, to confirm that AJAX Upload works with most options.</p>
  38. <h2>Test 1 - Default options</h2>
  39. <p>
  40. <a id="test1" class="button" href="http://valums.com/">Inline "A" element as upload button</a>
  41. <script>
  42. jQuery(function(){
  43. new AjaxUpload('test1', {
  44. action: 'upload-test.php',
  45. onComplete: function(file, response){
  46. alert(response);
  47. }
  48. });
  49. });
  50. </script>
  51. </p>
  52. <h2>Test 1b - With select multiple:true</h2>
  53. <p>
  54. <a id="test1a" class="button" href="http://valums.com/">Inline "A" element as multiple upload button</a>
  55. <script>
  56. jQuery(function(){
  57. new AjaxUpload('test1a', {
  58. action: 'upload-test.php',
  59. name: 'userfile[]',
  60. multiple: true,
  61. onComplete: function(file, response){
  62. alert(response);
  63. }
  64. });
  65. });
  66. </script>
  67. </p>
  68. <h2>Test 2 - Huge button - Default options - addressing with #test2</h2>
  69. <div id="test2" class="button" style="background: #AFA8A4; border: 5px solid black; width:100%; height: 500px; margin: 20px 0;">
  70. "DIV" element as upload button. Fixed width and height.
  71. </div>
  72. <script>
  73. jQuery(function(){
  74. new AjaxUpload('#test2', {
  75. action: 'upload-test.php',
  76. onComplete: function(file, response){
  77. alert(response);
  78. }
  79. });
  80. });
  81. </script>
  82. <h2>Test 3 - Resize window and check 1 and 2 again</h2>
  83. <h2>Test 4 - Check all options !!!</h2>
  84. <p>
  85. When alerted upload is disabled.
  86. <a id="test4" class="button" href="http://valums.com/">Select</a>
  87. <a id="test4upload" href='#'>Submit &amp; Enable</a>
  88. </p>
  89. <p>Check with image and some other file</p>
  90. <pre>
  91. var upload = new AjaxUpload(jQuery('#test4'), {
  92. action: 'upload-test.php',
  93. name: 'woohoo-custom-name',
  94. data: {
  95. 'key1': "This data won't be sent, we will overwrite it."
  96. },
  97. autoSubmit: false,
  98. responseType: 'json',
  99. onChange: function(file, ext){
  100. },
  101. onSubmit: function(file, ext){
  102. // Allow only images. You should add security check on the server-side.
  103. if (ext && /^(jpg|png|jpeg|gif)$/i.test(ext)) {
  104. this.setData({
  105. 'key1': 'This should be alerted',
  106. 'key2': '...'
  107. });
  108. } else {
  109. alert('not image');
  110. return false;
  111. }
  112. },
  113. onComplete: function(file, response){
  114. this.disable();
  115. alert(response.post.key1);
  116. }
  117. });
  118. jQuery('#test4upload').click(function(){
  119. upload.submit();
  120. upload.enable();
  121. return false;
  122. });
  123. </pre>
  124. <script>
  125. jQuery(function(){
  126. var upload = new AjaxUpload(jQuery('#test4'), {
  127. action: 'upload-test.php',
  128. name: 'woohoo-custom-name',
  129. data: {
  130. 'key1': "This data won't be sent, we will overwrite it."
  131. },
  132. autoSubmit: false,
  133. responseType: 'json',
  134. onChange: function(file, ext){
  135. },
  136. onSubmit: function(file, ext){
  137. // Allow only images. You should add security check on the server-side.
  138. if (ext && /^(jpg|png|jpeg|gif)$/i.test(ext)) {
  139. this.setData({
  140. 'key1': 'This should be alerted',
  141. 'key2': '...'
  142. });
  143. } else {
  144. alert('not image');
  145. return false;
  146. }
  147. },
  148. onComplete: function(file, response){
  149. this.disable();
  150. alert(response.post.key1);
  151. }
  152. });
  153. jQuery('#test4upload').click(function(){
  154. upload.submit();
  155. upload.enable();
  156. return false;
  157. });
  158. });
  159. </script>
  160. <h2>Test 5 - Return false in onChange and file values</h2>
  161. <p>
  162. <a id="test5" class="button" href="http://valums.com/">Select</a>
  163. </p>
  164. <pre>
  165. new AjaxUpload(document.getElementById('test5'),{
  166. onChange: function(file, ext){
  167. return false;
  168. }
  169. });
  170. </pre>
  171. <script>
  172. jQuery(function(){
  173. new AjaxUpload(document.getElementById('test5'),{
  174. onChange: function(file, ext){
  175. alert(file + '\n' + ext);
  176. return false;
  177. }
  178. });
  179. });
  180. </script>
  181. <h2>Test 6 - with jQuery UI dialog - onSubmit this.disable();</h2>
  182. <p>
  183. <a id="open_dialog" href="#">Button in jQuery dialog, using input[type=file]</a>
  184. </p>
  185. <div id="dialog" style="display:none;" title="Basic dialog with Upload button">
  186. <p>
  187. The Ajax Upload should work perfectly with jQuery UI dialog
  188. </p>
  189. <input id="dialog_upload" class="button" type="file" />
  190. </div>
  191. <script>
  192. jQuery(function($){
  193. var upload = new AjaxUpload('dialog_upload', {
  194. action: 'upload-test.php',
  195. onSubmit: function(){
  196. this.disable();
  197. },
  198. onComplete: function(file, response){
  199. alert(response);
  200. }
  201. });
  202. $("#dialog").dialog({
  203. autoOpen: false,
  204. beforeclose: function(event, ui){},
  205. dragStop: function(event, ui){}
  206. });
  207. $('#open_dialog').click(function(){
  208. $("#dialog").dialog("open");
  209. return false;
  210. });
  211. });
  212. </script>
  213. </div>
  214. </body>
  215. </html>