Le repo des sources pour le site web des JM2L
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 

107 рядки
3.3 KiB

  1. /*
  2. * jQuery File Upload Audio Preview Plugin 1.0.3
  3. * https://github.com/blueimp/jQuery-File-Upload
  4. *
  5. * Copyright 2013, Sebastian Tschan
  6. * https://blueimp.net
  7. *
  8. * Licensed under the MIT license:
  9. * http://www.opensource.org/licenses/MIT
  10. */
  11. /* jshint nomen:false */
  12. /* global define, window, document */
  13. (function (factory) {
  14. 'use strict';
  15. if (typeof define === 'function' && define.amd) {
  16. // Register as an anonymous AMD module:
  17. define([
  18. 'jquery',
  19. 'load-image',
  20. './jquery.fileupload-process'
  21. ], factory);
  22. } else {
  23. // Browser globals:
  24. factory(
  25. window.jQuery,
  26. window.loadImage
  27. );
  28. }
  29. }(function ($, loadImage) {
  30. 'use strict';
  31. // Prepend to the default processQueue:
  32. $.blueimp.fileupload.prototype.options.processQueue.unshift(
  33. {
  34. action: 'loadAudio',
  35. // Use the action as prefix for the "@" options:
  36. prefix: true,
  37. fileTypes: '@',
  38. maxFileSize: '@',
  39. disabled: '@disableAudioPreview'
  40. },
  41. {
  42. action: 'setAudio',
  43. name: '@audioPreviewName',
  44. disabled: '@disableAudioPreview'
  45. }
  46. );
  47. // The File Upload Audio Preview plugin extends the fileupload widget
  48. // with audio preview functionality:
  49. $.widget('blueimp.fileupload', $.blueimp.fileupload, {
  50. options: {
  51. // The regular expression for the types of audio files to load,
  52. // matched against the file type:
  53. loadAudioFileTypes: /^audio\/.*$/
  54. },
  55. _audioElement: document.createElement('audio'),
  56. processActions: {
  57. // Loads the audio file given via data.files and data.index
  58. // as audio element if the browser supports playing it.
  59. // Accepts the options fileTypes (regular expression)
  60. // and maxFileSize (integer) to limit the files to load:
  61. loadAudio: function (data, options) {
  62. if (options.disabled) {
  63. return data;
  64. }
  65. var file = data.files[data.index],
  66. url,
  67. audio;
  68. if (this._audioElement.canPlayType &&
  69. this._audioElement.canPlayType(file.type) &&
  70. ($.type(options.maxFileSize) !== 'number' ||
  71. file.size <= options.maxFileSize) &&
  72. (!options.fileTypes ||
  73. options.fileTypes.test(file.type))) {
  74. url = loadImage.createObjectURL(file);
  75. if (url) {
  76. audio = this._audioElement.cloneNode(false);
  77. audio.src = url;
  78. audio.controls = true;
  79. data.audio = audio;
  80. return data;
  81. }
  82. }
  83. return data;
  84. },
  85. // Sets the audio element as a property of the file object:
  86. setAudio: function (data, options) {
  87. if (data.audio && !options.disabled) {
  88. data.files[data.index][options.name || 'preview'] = data.audio;
  89. }
  90. return data;
  91. }
  92. }
  93. });
  94. }));