main.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * jQuery File Upload Plugin JS Example 6.7
  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. /*jslint nomen: true, unparam: true, regexp: true */
  12. /*global $, window, document */
  13. $(function () {
  14. 'use strict';
  15. // Initialize the jQuery File Upload widget:
  16. $('#fileupload').fileupload();
  17. // Enable iframe cross-domain access via redirect option:
  18. $('#fileupload').fileupload(
  19. 'option',
  20. 'redirect',
  21. window.location.href.replace(
  22. /\/[^\/]*$/,
  23. '/cors/result.html?%s'
  24. )
  25. );
  26. if (window.location.hostname === 'blueimp.github.com') {
  27. // Demo settings:
  28. $('#fileupload').fileupload('option', {
  29. url: '//jquery-file-upload.appspot.com/',
  30. maxFileSize: 5000000,
  31. acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
  32. process: [
  33. {
  34. action: 'load',
  35. fileTypes: /^image\/(gif|jpeg|png)$/,
  36. maxFileSize: 20000000 // 20MB
  37. },
  38. {
  39. action: 'resize',
  40. maxWidth: 1440,
  41. maxHeight: 900
  42. },
  43. {
  44. action: 'save'
  45. }
  46. ]
  47. });
  48. // Upload server status check for browsers with CORS support:
  49. if ($.support.cors) {
  50. $.ajax({
  51. url: '//jquery-file-upload.appspot.com/',
  52. type: 'HEAD'
  53. }).fail(function () {
  54. $('<span class="alert alert-error"/>')
  55. .text($.mage.__('Upload server currently unavailable - ') +
  56. new Date())
  57. .appendTo('#fileupload');
  58. });
  59. }
  60. } else {
  61. // Load existing files:
  62. $('#fileupload').each(function () {
  63. var that = this;
  64. $.getJSON(this.action, function (result) {
  65. if (result && result.length) {
  66. $(that).fileupload('option', 'done')
  67. .call(that, null, {result: result});
  68. }
  69. });
  70. });
  71. }
  72. });