Guest User

Untitled

a guest
Dec 11th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.40 KB | None | 0 0
  1. csjsPackage('csjs.ui.control.blogger');
  2.  
  3. csjsImportExternal('jQuery');
  4. csjsImport('csjs');
  5. csjsImport('csjs.i18n');
  6. csjsImport('csjs.ui.control');
  7.  
  8. /**
  9. * ListLanguageSwitch
  10. */
  11. csjs.ui.control.blogger.ListLanguageSwitch = function(strControlId) {
  12. var su = csjs.ui.control.blogger.ListLanguageSwitch.prototype.__super;
  13. su.constructor.call(this, strControlId);
  14. jQuery(this._elem).bind(csjs.i18n.I18N.eventLanguageChanged, csjsDelegate(this, this.onLanguageChanged));
  15. };
  16.  
  17. csjs.ui.control.blogger.ListLanguageSwitch.strControlTypeAttrValue = 'csjs.ui.control.blogger.ListLanguageSwitch';
  18.  
  19. csjsExtends(csjs.ui.control.blogger.ListLanguageSwitch, csjs.ui.control.AbstractControl);
  20. csjs.ui.control.blogger.ListLanguageSwitch.prototype._i18n = csjs.i18n.I18N.getInstance();
  21.  
  22. csjs.ui.control.blogger.ListLanguageSwitch.prototype.onLanguageChanged = function() {
  23. this._selectLanguage(this._elem, this._i18n.getCurrLang());
  24. };
  25.  
  26. csjs.ui.control.blogger.ListLanguageSwitch.prototype._selectLanguage = function(elemSelector, strLang) {
  27. var textColor = jQuery(elemSelector).css('color');
  28. var backgroundColor = jQuery(elemSelector).css('background-color');
  29. jQuery(elemSelector.childNodes).filter('div').filter(function(index, elem) {
  30. if (elem.innerHTML == strLang)
  31. jQuery(elem).css('border', '1px solid ' + textColor);
  32. else
  33. jQuery(elem).css('border', '1px solid ' + backgroundColor);
  34. });
  35. };
  36.  
  37. csjs.ui.control.blogger.ListLanguageSwitch.prototype._createControl = function(i18n) {
  38. jQuery(this._elem).css('text-align', 'center');
  39. var arrLangs = i18n.getLangs();
  40. for ( var i in arrLangs) {
  41. var strLang = arrLangs[i];
  42. var elem = document.createElement('div');
  43. elem.innerHTML = strLang;
  44. jQuery(elem).bind('click', {
  45. strLang : strLang
  46. }, function(event) {
  47. i18n.trigger(event.data.strLang);
  48. }).css('cursor', 'pointer').css('display', 'inline').css('padding', '2px');
  49. this._elem.appendChild(elem);
  50. }
  51. };
  52.  
  53. csjs.ui.control.blogger.ListLanguageSwitch.prototype._initGui = function() {
  54. this._createControl(this._i18n);
  55. this._selectLanguage(this._elem, this._i18n.getCurrLang());
  56. };
  57.  
  58. /**
  59. * TranslatorGadget
  60. */
  61. csjs.ui.control.blogger.TranslatorGadget = function(strControlId) {
  62. var su = csjs.ui.control.blogger.TranslatorGadget.prototype.__super;
  63. su.constructor.call(this, strControlId);
  64. };
  65.  
  66. csjsExtends(csjs.ui.control.blogger.TranslatorGadget, csjs.ui.control.AbstractControl);
  67. csjs.ui.control.blogger.TranslatorGadget.prototype._qTranslator = null;
  68.  
  69. csjs.ui.control.blogger.TranslatorGadget.prototype._initGui = function() {
  70. this._qElem.text('Translator').bind('click', csjsDelegate(this, this._toggleTranslator));
  71. this._qTranslator = jQuery('<div />').attr(csjs.ui.control.ControlsFactory.strCtrlClassAttrName, 'csjs.ui.control.blogger.Translator').appendTo('body');
  72. csjs.ui.control.ControlsFactory.getInstance().createControl(this._qTranslator[0]);
  73. };
  74.  
  75. csjs.ui.control.blogger.TranslatorGadget.prototype._toggleTranslator = function() {
  76. this._qTranslator.toggle();
  77. };
  78.  
  79. /**
  80. * Translator
  81. *
  82. * @param width
  83. * like 800 or '800px' or '50%', optional, default - 300
  84. * @param height
  85. * like 800 or '800px' or '50%' , optional, default - 200
  86. * @param stripBorder
  87. * like true or false, optional, default - false
  88. */
  89. csjs.ui.control.blogger.Translator = function(strControlId, objParams) {
  90. var su = csjs.ui.control.blogger.Translator.prototype.__super;
  91. su.constructor.call(this, strControlId, objParams);
  92. };
  93.  
  94. csjsExtends(csjs.ui.control.blogger.Translator, csjs.ui.control.AbstractControl);
  95. csjs.ui.control.blogger.Translator.prototype._qTabs = null;
  96. csjs.ui.control.blogger.Translator.prototype._qSource = null;
  97. csjs.ui.control.blogger.Translator.prototype._qI18nTable = null;
  98. csjs.ui.control.blogger.Translator.prototype._qResult = null;
  99. csjs.ui.control.blogger.Translator.prototype._isDynamicWidth = true;
  100. csjs.ui.control.blogger.Translator.prototype._isDynamicHeight = false;
  101. csjs.ui.control.blogger.Translator.prototype._defaultWidth = 300;
  102. csjs.ui.control.blogger.Translator.prototype._defaultHeight = 200;
  103. csjs.ui.control.blogger.Translator.prototype._currTabIdx = 0;
  104.  
  105. csjs.ui.control.blogger.Translator.prototype._initGui = function() {
  106. this._qTabs = jQuery('<div>').attr('style', 'padding: 0px; margin: 0px').appendTo(this._qElem);
  107. if (this._params && this._params.stripBorder)
  108. this._qTabs.css('border-width', '0px');
  109. var qUl = jQuery('<ul>').appendTo(this._qTabs);
  110. var qLi0 = jQuery('<li>').appendTo(qUl);
  111. var qA0 = jQuery('<a>').attr('href', '#' + this.getId() + '_tab1').text('Original HTML').appendTo(qLi0);
  112. var qLi1 = jQuery('<li>').appendTo(qUl);
  113. var qA1 = jQuery('<a>').attr('href', '#' + this.getId() + '_tab2').text('I18N').appendTo(qLi1);
  114. var qLi2 = jQuery('<li>').appendTo(qUl);
  115. var qA2 = jQuery('<a>').attr('href', '#' + this.getId() + '_tab3').text('I18N injected HTML').appendTo(qLi2);
  116.  
  117. this._qSource = jQuery('<textarea>').attr('id', this.getId() + '_tab1').addClass('csjs-ui-control_container').attr('style', 'resize: none;').attr('wrap', 'off').appendTo(this._qTabs);
  118. this._qI18nTable = jQuery('<div>').attr('id', this.getId() + '_tab2').attr('style', 'margin: 0px; padding: 0px; overflow: auto;').appendTo(this._qTabs);
  119. this._qResult = jQuery('<textarea>').attr('id', this.getId() + '_tab3').attr('style', 'margin: 0px; padding: 0px; overflow: auto; resize: none;').attr('wrap', 'off').appendTo(this._qTabs);
  120.  
  121. this._qTabs.tabs();
  122.  
  123. this._setDimension();
  124.  
  125. qA0.click(csjsCallback(this, this._onTabSelected, 0));
  126. qA1.click(csjsCallback(this, this._onTabSelected, 1));
  127. qA2.click(csjsCallback(this, this._onTabSelected, 2));
  128. jQuery(window).resize(csjsDelegate(this, this._onWindowResize));
  129. };
  130.  
  131. csjs.ui.control.blogger.Translator.prototype._setDimension = function() {
  132. var width = this._defaultWidth;
  133. if (this._params && this._params.width) {
  134. width = this._params.width;
  135. if (typeof this._params.width != 'number' && this._params.width.indexOf('%') < 0) {
  136. this._isDynamicWidth = false;
  137. }
  138. }
  139.  
  140. var height = this._defaultHeight;
  141. if (this._params && this._params.height) {
  142. if (typeof this._params.height === 'string' && this._params.height.indexOf('%') >= 0) {
  143. this._isDynamicHeight = true;
  144. height = parseInt(this._params.height) * 0.01 * jQuery(window).height();
  145. } else
  146. height = parseInt(this._params.height);
  147. }
  148. height = height - this._qElem.children().eq(0).children().eq(0).outerHeight();
  149.  
  150. this._qElem.css('width', width); // work for both % and px
  151. width = this._qTabs.innerWidth();
  152. this._qSource.css('width', width).css('height', height);
  153. this._qI18nTable.css('width', width).css('height', height);
  154. this._qResult.css('width', width).css('height', height);
  155. };
  156.  
  157. csjs.ui.control.blogger.Translator.prototype._onTabSelected = function(numSelectedTab) {
  158. // alert('Selected ' + numSelectedTab + ' tab!');
  159. };
  160.  
  161. csjs.ui.control.blogger.Translator.prototype._onWindowResize = function() {
  162. if (this._isDynamicWidth) {
  163. var width = this._qTabs.innerWidth();
  164.  
  165. this._qSource.css('width', width);
  166. this._qI18nTable.css('width', width);
  167. this._qResult.css('width', width);
  168. }
  169. if (this._isDynamicHeight) {
  170. var height = parseInt(this._params.height) * 0.01 * jQuery(window).height() - this._qElem.children().eq(0).children().eq(0).outerHeight();
  171.  
  172. this._qSource.css('height', height);
  173. this._qI18nTable.css('height', height);
  174. this._qResult.css('height', height);
  175. }
  176. };
Add Comment
Please, Sign In to add comment