API Docs for: 1.0.0
Show:

File: Resources/public/js/alloyeditor/buttons/mixins/embeddiscovercontent.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-alloyeditor-button-mixin-embeddiscovercontent', function (Y) {
  6. "use strict";
  7.  
  8. /**
  9. * Provides the EmbedDiscoverContent mixin
  10. *
  11. * @module ez-alloyeditor-button-mixin-embeddiscovercontent
  12. */
  13. Y.namespace('eZ.AlloyEditorButton');
  14.  
  15. var React = Y.eZ.React;
  16.  
  17. /**
  18. * ButtonEmbedDiscoverContent is a mixing providing the necessary code to
  19. * trigger UDW and use the content choosen by the user to correctly set the
  20. * properties of the ezembed widget.
  21. *
  22. * @class ButtonEmbedDiscoverContent
  23. * @namespace eZ.AlloyEditorButton
  24. */
  25. Y.eZ.AlloyEditorButton.ButtonEmbedDiscoverContent = {
  26. propTypes: {
  27. /**
  28. * The editor instance where the component is being used.
  29. *
  30. * @property {Object} editor
  31. */
  32. editor: React.PropTypes.object.isRequired,
  33.  
  34. /**
  35. * The title of the UDW. This property is deprecated, please
  36. * implement a _getUDWTitle method instead.
  37. *
  38. * @property {String} udwTitle
  39. * @deprecated
  40. */
  41. udwTitle: React.PropTypes.string,
  42.  
  43. /**
  44. * The method to use as the contentDiscoveredHandler in the UDW
  45. *
  46. * @property {String} udwContentDiscoveredMethod
  47. */
  48. udwContentDiscoveredMethod: React.PropTypes.string,
  49.  
  50. /**
  51. * The method to use as the isSelectable function in the UDW
  52. *
  53. * @property {String} udwIsSelectableMethod
  54. */
  55. udwIsSelectableMethod: React.PropTypes.string,
  56.  
  57. /**
  58. * The loadContent flag to pass to the UDW
  59. *
  60. * @property {Boolean} udwLoadContent
  61. */
  62. udwLoadContent: React.PropTypes.bool,
  63.  
  64. /**
  65. * The label of the button
  66. *
  67. * @property {String} label
  68. * @deprecated
  69. */
  70. label: React.PropTypes.string,
  71. },
  72.  
  73. /**
  74. * Triggers the UDW to choose the content to embed.
  75. *
  76. * @method _chooseContent
  77. * @protected
  78. */
  79. _chooseContent: function () {
  80. var selectable = this.props.udwIsSelectableMethod,
  81. title;
  82.  
  83. if ( !this._getUDWTitle ) {
  84. console.log('[DEPRECATED] using deprecated `udwTitle` property');
  85. console.log('[DEPRECATED] when using ButtonEmbedDiscoverContent please implement _getUDWTitle instead');
  86. title = this.props.udwTitle;
  87. } else {
  88. title = this._getUDWTitle();
  89. }
  90.  
  91.  
  92. this.props.editor.get('nativeEditor').fire('contentDiscover', {
  93. config: {
  94. title: title,
  95. multiple: false,
  96. contentDiscoveredHandler: this[this.props.udwContentDiscoveredMethod],
  97. isSelectable: selectable ? this[selectable] : undefined,
  98. loadContent: this.props.udwLoadContent,
  99. }
  100. });
  101. },
  102.  
  103. /**
  104. * Sets the href of the ezembed widget based on the given content info
  105. *
  106. * @method _setContentInfo
  107. * @protected
  108. * @param {eZ.ContentInfo} contentInfo
  109. */
  110. _setContentInfo: function (contentInfo) {
  111. var embedWidget = this._getWidget();
  112.  
  113. embedWidget.setHref('ezcontent://' + contentInfo.get('contentId'));
  114. embedWidget.focus();
  115. },
  116.  
  117. /**
  118. * Fires the `updatedEmbed` event. This should be called right after the
  119. * embed element is updated.
  120. *
  121. * @method _fireUpdatedEmbed
  122. * @protected
  123. * @param {Object} selection the UDW selection
  124. */
  125. _fireUpdatedEmbed: function (selection) {
  126. /**
  127. * Fired when the embed widget is updated in the editor. This event
  128. * can be listened to render the embed widget that has been updated.
  129. *
  130. * @event updatedEmbed
  131. * @param {Object} embedStruct the UDW selection
  132. */
  133. this.props.editor.get('nativeEditor').fire('updatedEmbed', {
  134. embedStruct: selection,
  135. });
  136. },
  137. };
  138. });
  139.