main.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * jQuery File Upload Plugin JS Example
  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. * http://www.opensource.org/licenses/MIT
  10. */
  11. /* global $, window */
  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: 'server/php/'
  19. });
  20. // Enable iframe cross-domain access via redirect option:
  21. $('#fileupload').fileupload(
  22. 'option',
  23. 'redirect',
  24. window.location.href.replace(
  25. /\/[^\/]*$/,
  26. '/cors/result.html?%s'
  27. )
  28. );
  29. if (window.location.hostname === 'blueimp.github.io') {
  30. // Demo settings:
  31. $('#fileupload').fileupload('option', {
  32. url: '//jquery-file-upload.appspot.com/',
  33. // Enable image resizing, except for Android and Opera,
  34. // which actually support image resizing, but fail to
  35. // send Blob objects via XHR requests:
  36. disableImageResize: /Android(?!.*Chrome)|Opera/
  37. .test(window.navigator.userAgent),
  38. maxFileSize: 999000,
  39. acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i
  40. });
  41. // Upload server status check for browsers with CORS support:
  42. if ($.support.cors) {
  43. $.ajax({
  44. url: '//jquery-file-upload.appspot.com/',
  45. type: 'HEAD'
  46. }).fail(function () {
  47. $('<div class="alert alert-danger"/>')
  48. .text('Upload server currently unavailable - ' +
  49. new Date())
  50. .appendTo('#fileupload');
  51. });
  52. }
  53. } else {
  54. // Load existing files:
  55. $('#fileupload').addClass('fileupload-processing');
  56. $.ajax({
  57. // Uncomment the following to send cross-domain cookies:
  58. //xhrFields: {withCredentials: true},
  59. url: $('#fileupload').fileupload('option', 'url'),
  60. dataType: 'json',
  61. context: $('#fileupload')[0]
  62. }).always(function () {
  63. $(this).removeClass('fileupload-processing');
  64. }).done(function (result) {
  65. $(this).fileupload('option', 'done')
  66. .call(this, $.Event('done'), {result: result});
  67. });
  68. }
  69. });