Advertisement
Guest User

Untitled

a guest
Feb 18th, 2015
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. /*
  2. * jQuery File Upload Plugin JS Example 8.9.1
  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.  
  12. /* global $, window */
  13.  
  14. $(function () {
  15. 'use strict';
  16.  
  17. // Initialize the jQuery File Upload widget:
  18. $('#fileupload').fileupload({
  19. // Uncomment the following to send cross-domain cookies:
  20. //xhrFields: {withCredentials: true},
  21. //url: 'server/php/'
  22. url: './post.0.fileUpload.php'
  23. });
  24.  
  25. // Enable iframe cross-domain access via redirect option:
  26. $('#fileupload').fileupload(
  27. 'option',
  28. 'redirect',
  29. window.location.href.replace(
  30. /\/[^\/]*$/,
  31. '/cors/result.html?%s'
  32. )
  33. );
  34.  
  35. if (window.location.hostname === 'blueimp.github.io') {
  36. // Demo settings:
  37. $('#fileupload').fileupload('option', {
  38. url: '//jquery-file-upload.appspot.com/',
  39. // Enable image resizing, except for Android and Opera, which actually support image resizing, but fail to send Blob objects via XHR requests:
  40. disableImageResize: /Android(?!.*Chrome)|Opera/
  41. .test(window.navigator.userAgent),
  42. maxFileSize: 5000000,
  43. acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i
  44. });
  45. // Upload server status check for browsers with CORS support:
  46. if ($.support.cors) {
  47. $.ajax({
  48. url: '//jquery-file-upload.appspot.com/',
  49. type: 'HEAD'
  50. }).fail(function () {
  51. $('<div class="alert alert-danger"/>')
  52. .text('Upload server currently unavailable - ' +
  53. new Date())
  54. .appendTo('#fileupload');
  55. });
  56. }
  57. } else {
  58. // Set file restrictions
  59. $('#fileupload').fileupload('option', {
  60. disableImageResize: /Android(?!.*Chrome)|Opera/
  61. .test(window.navigator.userAgent),
  62. maxFileSize: 5120000,
  63. //acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i
  64. acceptFileTypes: /(\.|\/)(doc|docx|pdf)$/i
  65. });
  66.  
  67. // Load existing files:
  68. $('#fileupload').addClass('fileupload-processing');
  69. $.ajax({
  70. // Uncomment the following to send cross-domain cookies:
  71. //xhrFields: {withCredentials: true},
  72. url: $('#fileupload').fileupload('option', 'url'),
  73. dataType: 'json',
  74. context: $('#fileupload')[0]
  75. }).always(function () {
  76. $(this).removeClass('fileupload-processing');
  77. }).done(function (result) {
  78. $(this).fileupload('option', 'done')
  79. .call(this, $.Event('done'), {result: result});
  80. });
  81. }
  82. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement