form-fileupload.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. var FormFileUpload = function () {
  2. return {
  3. //main function to initiate the module
  4. init: function () {
  5. // Initialize the jQuery File Upload widget:
  6. $('#fileupload').fileupload({
  7. // Uncomment the following to send cross-domain cookies:
  8. //xhrFields: {withCredentials: true},
  9. url: 'assets/plugins/jquery-file-upload/server/php/'
  10. });
  11. // Load existing files:
  12. // Demo settings:
  13. $.ajax({
  14. // Uncomment the following to send cross-domain cookies:
  15. //xhrFields: {withCredentials: true},
  16. url: $('#fileupload').fileupload('option', 'url'),
  17. dataType: 'json',
  18. context: $('#fileupload')[0],
  19. maxFileSize: 5000000,
  20. acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
  21. process: [{
  22. action: 'load',
  23. fileTypes: /^image\/(gif|jpeg|png)$/,
  24. maxFileSize: 20000000 // 20MB
  25. }, {
  26. action: 'resize',
  27. maxWidth: 1440,
  28. maxHeight: 900
  29. }, {
  30. action: 'save'
  31. }
  32. ]
  33. }).done(function (result) {
  34. $(this).fileupload('option', 'done')
  35. .call(this, null, {
  36. result: result
  37. });
  38. });
  39. // Upload server status check for browsers with CORS support:
  40. if ($.support.cors) {
  41. $.ajax({
  42. url: 'assets/plugins/jquery-file-upload/server/php/',
  43. type: 'HEAD'
  44. }).fail(function () {
  45. $('<span class="alert alert-error"/>')
  46. .text('Upload server currently unavailable - ' +
  47. new Date())
  48. .appendTo('#fileupload');
  49. });
  50. }
  51. // initialize uniform checkboxes
  52. App.initUniform('.fileupload-toggle-checkbox');
  53. }
  54. };
  55. }();