Le repo des sources pour le site web des JM2L
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 

107 wiersze
3.3 KiB

  1. /*
  2. * jQuery File Upload Video 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: 'loadVideo',
  35. // Use the action as prefix for the "@" options:
  36. prefix: true,
  37. fileTypes: '@',
  38. maxFileSize: '@',
  39. disabled: '@disableVideoPreview'
  40. },
  41. {
  42. action: 'setVideo',
  43. name: '@videoPreviewName',
  44. disabled: '@disableVideoPreview'
  45. }
  46. );
  47. // The File Upload Video Preview plugin extends the fileupload widget
  48. // with video preview functionality:
  49. $.widget('blueimp.fileupload', $.blueimp.fileupload, {
  50. options: {
  51. // The regular expression for the types of video files to load,
  52. // matched against the file type:
  53. loadVideoFileTypes: /^video\/.*$/
  54. },
  55. _videoElement: document.createElement('video'),
  56. processActions: {
  57. // Loads the video file given via data.files and data.index
  58. // as video 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. loadVideo: function (data, options) {
  62. if (options.disabled) {
  63. return data;
  64. }
  65. var file = data.files[data.index],
  66. url,
  67. video;
  68. if (this._videoElement.canPlayType &&
  69. this._videoElement.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. video = this._videoElement.cloneNode(false);
  77. video.src = url;
  78. video.controls = true;
  79. data.video = video;
  80. return data;
  81. }
  82. }
  83. return data;
  84. },
  85. // Sets the video element as a property of the file object:
  86. setVideo: function (data, options) {
  87. if (data.video && !options.disabled) {
  88. data.files[data.index][options.name || 'preview'] = data.video;
  89. }
  90. return data;
  91. }
  92. }
  93. });
  94. }));