APIs

Show:
  1. /**
  2. * BlockTwitterItem block resides inside a scene or timeline
  3. * @class BlockTwitterItem
  4. * @extends Block
  5. * @constructor
  6. * @param {string} i_placement location where objects resides which can be scene or timeline
  7. * @param {string} i_campaign_timeline_chanel_player_id required and set as block id when block is inserted onto timeline_channel
  8. * @return {Object} Block instance
  9. */
  10. define(['jquery', 'backbone', 'Block'], function ($, Backbone, Block) {
  11.  
  12. var BlockTwitterItem = Block.extend({
  13.  
  14. /**
  15. Constructor
  16. @method initialize
  17. **/
  18. constructor: function (options) {
  19. var self = this;
  20. self.m_blockType = 4505;
  21. _.extend(options, {blockType: self.m_blockType})
  22. Block.prototype.constructor.call(this, options);
  23. self._initSubPanel(Elements.BLOCK_TWITTER_ITEM_COMMON_PROPERTIES);
  24. self._listenItemSelectDropDownChange();
  25. self._listenFontSelectionChange();
  26. self.m_twitterFontSelector = self.m_blockProperty.getTwitterItemFontSelector();
  27. },
  28.  
  29. /**
  30. Load up property values in the common panel
  31. @method _populate
  32. @return none
  33. **/
  34. _populate: function () {
  35. var self = this;
  36. var domPlayerData = self._getBlockPlayerData();
  37. var xSnippet = $(domPlayerData).find('XmlItem');
  38. var fieldType = $(xSnippet).attr('fieldType');
  39. var label = fieldType == 'resource' ? $(Elements.BOOTBOX_PROFILE_IMAGE).text() : $(Elements.BOOTBOX_LABEL_TEXT).text();
  40. self._populatePlayItemLabel(label);
  41. self._populateToggleItemType(fieldType);
  42. self._populateLabel();
  43. },
  44.  
  45. /**
  46. Listen to selection of twitter item
  47. @method _listenItemSelectDropDownChange
  48. **/
  49. _listenItemSelectDropDownChange: function () {
  50. var self = this;
  51. self.m_itemTypeSelect = function (e) {
  52. if (!self.m_selected)
  53. return;
  54. var fieldType = $(e.target).attr('name');
  55. if (_.isUndefined(fieldType))
  56. return;
  57. var listLabel = $(e.target).text();
  58. var domPlayerData = self._getBlockPlayerData();
  59. var xSnippet = $(domPlayerData).find('XmlItem');
  60.  
  61. switch (fieldType) {
  62. case 'text':
  63. {
  64. $(xSnippet).attr('fieldName', 'text');
  65. $(xSnippet).attr('fieldType', 'text');
  66. break;
  67. }
  68. case 'resource':
  69. {
  70. $(xSnippet).attr('fieldName', 'user.profile_image_url');
  71. $(xSnippet).attr('fieldType', 'resource');
  72. break;
  73. }
  74. }
  75. self._populatePlayItemLabel(listLabel);
  76. self._populateToggleItemType(fieldType);
  77. self._setBlockPlayerData(domPlayerData, BB.CONSTS.NO_NOTIFICATION);
  78. };
  79. $(Elements.TWITTER_ITEM_DROPDOWN).on('click', self.m_itemTypeSelect);
  80. },
  81.  
  82. /**
  83. Populate the twitter label (most viewed / custom list)
  84. @method _populatePlayItemLabel
  85. @params {String} i_label
  86. **/
  87. _populatePlayItemLabel: function (i_label) {
  88. var self = this;
  89. $(Elements.TWITTER_ITEMTYPE_SELECT).text(i_label);
  90. },
  91.  
  92. /**
  93. Toggle the view of proper list selection
  94. @method _populateToggleItemType
  95. @params {String} i_fieldType
  96. **/
  97. _populateToggleItemType: function (i_fieldType) {
  98. var self = this;
  99. switch (i_fieldType) {
  100. case 'text':
  101. {
  102. $(Elements.TWITTER_ITEM_LABEL).show();
  103. break;
  104. }
  105. case 'resource':
  106. {
  107. $(Elements.TWITTER_ITEM_LABEL).hide();
  108. break;
  109. }
  110. }
  111. },
  112.  
  113. /**
  114. Load up property values in the common panel
  115. @method _populate
  116. @return none
  117. **/
  118. _populateLabel: function () {
  119. var self = this;
  120. var domPlayerData = self._getBlockPlayerData();
  121. var xSnippetFont = $(domPlayerData).find('Font');
  122. self.m_twitterFontSelector.setConfig({
  123. bold: xSnippetFont.attr('fontWeight') == 'bold' ? true : false,
  124. italic: xSnippetFont.attr('fontStyle') == 'italic' ? true : false,
  125. underline: xSnippetFont.attr('textDecoration') == 'underline' ? true : false,
  126. alignment: xSnippetFont.attr('textAlign'),
  127. font: xSnippetFont.attr('fontFamily'),
  128. color: BB.lib.colorToHex(BB.lib.decimalToHex(xSnippetFont.attr('fontColor'))),
  129. size: xSnippetFont.attr('fontSize')
  130. });
  131. },
  132.  
  133. /**
  134. Listen to changes in font UI selection from Block property and take action on changes
  135. @method _listenFontSelectionChange
  136. **/
  137. _listenFontSelectionChange: function () {
  138. var self = this;
  139. BB.comBroker.listenWithNamespace(BB.EVENTS.FONT_SELECTION_CHANGED, self, function (e) {
  140. if (!self.m_selected || e.caller !== self.m_twitterFontSelector)
  141. return;
  142. var config = e.edata;
  143. var domPlayerData = self._getBlockPlayerData();
  144. var xSnippetFont = $(domPlayerData).find('Font');
  145. config.bold == true ? xSnippetFont.attr('fontWeight', 'bold') : xSnippetFont.attr('fontWeight', 'normal');
  146. config.italic == true ? xSnippetFont.attr('fontStyle', 'italic') : xSnippetFont.attr('fontStyle', 'normal');
  147. config.underline == true ? xSnippetFont.attr('textDecoration', 'underline') : xSnippetFont.attr('textDecoration', 'none');
  148. xSnippetFont.attr('fontColor', BB.lib.colorToDecimal(config.color));
  149. xSnippetFont.attr('fontSize', config.size);
  150. xSnippetFont.attr('fontFamily', config.font);
  151. xSnippetFont.attr('textAlign', config.alignment);
  152. self._setBlockPlayerData(domPlayerData);
  153. });
  154. },
  155.  
  156. /**
  157. Populate the common block properties panel, called from base class if exists
  158. @method _loadBlockSpecificProps
  159. @return none
  160. **/
  161. _loadBlockSpecificProps: function () {
  162. var self = this;
  163. self._populate();
  164. this._viewSubPanel(Elements.BLOCK_TWITTER_ITEM_COMMON_PROPERTIES);
  165. },
  166.  
  167. /**
  168. Delete this block
  169. @method deleteBlock
  170. @params {Boolean} i_memoryOnly if true only remove from existance but not from msdb
  171. **/
  172. deleteBlock: function (i_memoryOnly) {
  173. var self = this;
  174. $(Elements.TWITTER_ITEM_DROPDOWN).off('click', self.m_itemTypeSelect);
  175. BB.comBroker.stopListenWithNamespace(BB.EVENTS.FONT_SELECTION_CHANGED, self);
  176. self._deleteBlock(i_memoryOnly);
  177. }
  178. });
  179.  
  180. return BlockTwitterItem;
  181. });