demo.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * jQuery File Upload Demo
  3. * https://github.com/blueimp/jQuery-File-Upload
  4. *
  5. * Copyright 2010, Sebastian Tschan
  6. * https://blueimp.net
  7. *
  8. * Licensed under the MIT license:
  9. * https://opensource.org/licenses/MIT
  10. */
  11. /* global $ */
  12. $(function () {
  13. 'use strict';
  14. // Initialize the jQuery File Upload widget:
  15. $('#fileupload').fileupload({
  16. // Uncomment the following to send cross-domain cookies:
  17. //xhrFields: {withCredentials: true},
  18. url: 'lib/jQuery-File-Upload-master/server/php/'
  19. });
  20. // Enable iframe cross-domain access via redirect option:
  21. $('#fileupload').fileupload(
  22. 'option',
  23. 'redirect',
  24. window.location.href.replace(/\/[^/]*$/, 'lib/jQuery-File-Upload-master//cors/result.html?%s')
  25. );
  26. if (window.location.hostname === 'blueimp.github.io') {
  27. // Demo settings:
  28. $('#fileupload').fileupload('option', {
  29. url: '//jquery-file-upload.appspot.com/',
  30. // Enable image resizing, except for Android and Opera,
  31. // which actually support image resizing, but fail to
  32. // send Blob objects via XHR requests:
  33. disableImageResize: /Android(?!.*Chrome)|Opera/.test(
  34. window.navigator.userAgent
  35. ),
  36. maxFileSize: 999000,
  37. acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i
  38. });
  39. // Upload server status check for browsers with CORS support:
  40. if ($.support.cors) {
  41. $.ajax({
  42. url: '//jquery-file-upload.appspot.com/',
  43. type: 'HEAD'
  44. }).fail(function () {
  45. $('<div class="alert alert-danger"/>')
  46. .text('Upload server currently unavailable - ' + new Date())
  47. .appendTo('#fileupload');
  48. });
  49. }
  50. } else {
  51. $('#fileupload').fileupload('option', {
  52. // Enable image resizing, except for Android and Opera,
  53. // which actually support image resizing, but fail to
  54. // send Blob objects via XHR requests:
  55. disableImageResize: /Android(?!.*Chrome)|Opera/.test(
  56. window.navigator.userAgent
  57. ),
  58. imageMaxWidth: 100,
  59. imageMaxHeight: 100,
  60. maxFileSize: 9999999,
  61. acceptFileTypes: /(\.|\/)(txt|gif|jpe?g|png)$/i
  62. });
  63. // Load existing files:
  64. $('#fileupload').addClass('fileupload-processing');
  65. $.ajax({
  66. // Uncomment the following to send cross-domain cookies:
  67. //xhrFields: {withCredentials: true},
  68. url: $('#fileupload').fileupload('option', 'url'),
  69. dataType: 'json',
  70. context: $('#fileupload')[0]
  71. })
  72. .always(function () {
  73. $(this).removeClass('fileupload-processing');
  74. })
  75. .done(function (result) {
  76. $(this)
  77. .fileupload('option', 'done')
  78. // eslint-disable-next-line new-cap
  79. .call(this, $.Event('done'), { result: result });
  80. });
  81. }
  82. });