API Docs for: 1.0.0
Show:

File: Resources/public/js/views/fields/ez-media-view.js

  1. /*
  2. * Copyright (C) eZ Systems AS. All rights reserved.
  3. * For full copyright and license information view LICENSE file distributed with this source code.
  4. */
  5. YUI.add('ez-media-view', function (Y) {
  6. "use strict";
  7. /**
  8. * Provides the Media field view
  9. *
  10. * @module ez-media-view
  11. */
  12. Y.namespace('eZ');
  13.  
  14. var IS_UNSUPPORTED = 'is-media-unsupported';
  15.  
  16. /**
  17. * The Media field view
  18. *
  19. * @namespace eZ
  20. * @class MediaView
  21. * @constructor
  22. * @extends eZ.FieldView
  23. */
  24. Y.eZ.MediaView = Y.Base.create('mediaView', Y.eZ.FieldView, [], {
  25.  
  26. render: function () {
  27. Y.eZ.FieldView.prototype.render.call(this);
  28. this._watchPlayerEvents();
  29. return this;
  30. },
  31.  
  32. _variables: function () {
  33. return {
  34. "isAudio": this.get('fieldDefinition').fieldSettings.mediaType === "TYPE_HTML5_AUDIO",
  35. };
  36. },
  37.  
  38. /**
  39. * Adds the unsupported class when the file can not read by the browser
  40. *
  41. * @method _mediaError
  42. * @param {Node} player the video/audio node
  43. */
  44. _mediaError: function (player) {
  45. var error = player.get('error');
  46.  
  47. if ( error && error.code === error.MEDIA_ERR_SRC_NOT_SUPPORTED ) {
  48. this.get('container').addClass(IS_UNSUPPORTED);
  49. }
  50. },
  51.  
  52. /**
  53. * Sets the event handler on the video/audio element to detect whether
  54. * the file is supported.
  55. *
  56. * @method _watchPlayerEvents
  57. * @protected
  58. */
  59. _watchPlayerEvents: function () {
  60. var that = this,
  61. container = this.get('container'),
  62. player = container.one('.ez-media-player');
  63.  
  64. if ( !player ) {
  65. return;
  66. }
  67. this._attachedViewEvents.push(player.on('error', function () {
  68. that._mediaError(player);
  69. }));
  70. },
  71. });
  72.  
  73. Y.eZ.FieldView.registerFieldView('ezmedia', Y.eZ.MediaView);
  74. });
  75.