Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.42 KB | None | 0 0
  1. import "./object-property-text.html";
  2. import { stageitemUpdateItemdata, stageitemUpdateItemstyle } from "../../../api/api.js";
  3.  
  4. Template.ObjectPropertyText.viewmodel({
  5. share:"stage", // shares all common stage properties from the Editor component
  6. // these are defalut properties for text style buttons.
  7. textStyleBold:false,
  8. textStyleItalic:false,
  9. textStyleUnderline:false,
  10. textStyleStrikethrough:false,
  11. textStyleLineover:false,
  12. textFontFill:"",
  13. textStroke:"",
  14. textStrokeWidth:0,
  15.  
  16. selectedFont(){
  17. // Return currently selected font of the selected text element on stage
  18. return this.selectedStageItemObj().style.fontFamily
  19. },
  20. textData(){
  21. // Return current Text data for the selected text element on stage
  22. return this.selectedStageItemObj().itemData;
  23. },
  24. allTextFonts(){
  25. // Get all fonts list and values and return them as an object to bind with ui state.
  26. const fontsArray = [{fontName:"Arial", fontVal:"Arial"}],
  27. fontNames = this.parent().parent().allWebFontsNames.value,
  28. fontVals = this.parent().parent().allWebFontsVals.value;
  29. _.each(fontNames, function(f,i){
  30. fontsArray.push({fontName:f, fontVal:fontVals[i]})
  31. });
  32. return fontsArray;
  33. },
  34. onRendered(){
  35. // Set spectrum color picker default config.
  36. let spectrumDefaults = {
  37. preferredFormat: "hex",
  38. showInput: true,
  39. showPalette: true,
  40. showSelectionPalette: true,
  41. palette: [ ],
  42. localStorageKey: "spectrum.explainee.studio",
  43. clickoutFiresChange: true,
  44. showInitial: true,
  45. allowEmpty:true
  46. };
  47. // Initiate tabs, and color picker
  48. $("#textItemProperties").tabs();
  49. $("#textStyleFontColor").spectrum(spectrumDefaults);
  50. $("#textStroke").spectrum(spectrumDefaults);
  51. },
  52. events:{
  53. "click .tab"(e){
  54. e.preventDefault();
  55. },
  56. "click #textStyleTextUpdateBtn"(e,t){
  57. const newText = $("#textStyleTextVal").val(),
  58. id = this.selectedStageItemObj.value._id;
  59. stageitemUpdateItemdata(id, newText, () => {
  60. Meteor.setTimeout(() => {
  61. $("#"+id).trigger("click");
  62. },10);
  63. });
  64. },
  65. "keypress #textStyleTextVal"(e,t){
  66. if(e.which == 13) {
  67. const newText = $("#textStyleTextVal").val(),
  68. id = this.selectedStageItemObj.value._id;
  69. stageitemUpdateItemdata(id, newText, () => {
  70. Meteor.setTimeout(() => {
  71. $("#"+id).trigger("click");
  72. },10);
  73. });
  74. }
  75. },
  76. "change #textStyleFontFamily"(e,t){
  77. const newFontFamily = e.currentTarget.value,
  78. id = this.selectedStageItemObj.value._id;
  79. stageitemUpdateItemstyle(id, `fontFamily::${newFontFamily}`,() => {
  80. Meteor.setTimeout(() => {
  81. $("#"+id).trigger("click");
  82. },10);
  83. });
  84. },
  85. "click #textStyleBold"(e,t){
  86. const id = this.selectedStageItemObj.value._id;
  87. let fontWeight = this.selectedStageItemObj.value.style.fontWeight;
  88. if(fontWeight == "bold"){
  89. fontWeight = "normal";
  90. }
  91. else fontWeight = "bold";
  92. stageitemUpdateItemstyle(id, `fontWeight::${fontWeight}`, () => {
  93. Meteor.setTimeout(() => {
  94. $("#"+id).trigger("click");
  95. },10);
  96. });
  97. },
  98. "click #textStyleItalic"(e,t){
  99. const id = this.selectedStageItemObj.value._id;
  100. let fontStyle = this.selectedStageItemObj.value.style.fontStyle;
  101. (fontStyle == "italic") ? fontStyle = "normal" : fontStyle = "italic";
  102. stageitemUpdateItemstyle(id, `fontStyle::${fontStyle}`, () => {
  103. Meteor.setTimeout(() => {
  104. $("#"+id).trigger("click");
  105. },10);
  106. });
  107. },
  108. "click #textStyleUnderline"(e,t){
  109. const id = this.selectedStageItemObj.value._id;
  110. let textDecoration = this.selectedStageItemObj.value.style.textDecoration;
  111. (textDecoration == "underline") ? textDecoration = "none" : textDecoration = "underline" ;
  112. stageitemUpdateItemstyle(id, `textDecoration::${textDecoration}`, () => {
  113. Meteor.setTimeout(() => {
  114. $("#"+id).trigger("click");
  115. },10);
  116. });
  117. },
  118. "click #textStyleStrikethrough"(e,t){
  119. const id = this.selectedStageItemObj.value._id;
  120. let textDecoration = this.selectedStageItemObj.value.style.textDecoration;
  121. (textDecoration == "line-through") ? textDecoration = "none" : textDecoration = "line-through";
  122. stageitemUpdateItemstyle(id, `textDecoration::${textDecoration}`, () => {
  123. Meteor.setTimeout(() => {
  124. $("#"+id).trigger("click");
  125. },10);
  126. });
  127. },
  128. "click #textStyleOverline"(e,t){
  129. const id = this.selectedStageItemObj.value._id;
  130. let textDecoration = this.selectedStageItemObj.value.style.textDecoration;
  131. (textDecoration == "overline") ? textDecoration = "none" : textDecoration = "overline";
  132. stageitemUpdateItemstyle(id, `textDecoration::${textDecoration}`, () => {
  133. Meteor.setTimeout(() => {
  134. $("#"+id).trigger("click");
  135. },10);
  136. });
  137. },
  138. "change #textStyleFontColor"(e,t){
  139. let newColor = $("#textStyleFontColor").spectrum("get");
  140. const id = this.selectedStageItemObj.value._id;
  141. if(newColor){
  142. newColor =newColor.toHexString();
  143. }
  144. stageitemUpdateItemstyle(id, "fill::"+newColor);
  145. },
  146.  
  147. "change #textStroke"(e,t){
  148. let newColor = $("#textStroke").spectrum("get");
  149. const id = this.selectedStageItemObj.value._id;
  150. if(newColor){
  151. newColor =newColor.toHexString();
  152. }
  153. stageitemUpdateItemstyle(id, `stroke::${newColor}`, () => {
  154. Meteor.setTimeout(() => {
  155. $("#"+id).trigger("click");
  156. },10);
  157. });
  158. },
  159. "mouseup #textStrokeWidth"(e,t){
  160. const strokeWidth = this.textStrokeWidth.value,
  161. id = this.selectedStageItemObj.value._id;
  162. stageitemUpdateItemstyle(id, `strokeWidth::${strokeWidth}`);
  163. }
  164.  
  165. },
  166. autorun(){
  167. // Autoruns on every change and updates the state to the text Element sidebar
  168. const selectedItemObj = this.selectedStageItemObj(),
  169. selectedFonObj = selectedItemObj.style;
  170. this.selectedFont(selectedFonObj.fontFamily);
  171. $("select").material_select();
  172. (selectedFonObj.fontWeight == "bold") ? this.textStyleBold(true) : this.textStyleBold(false);
  173. (selectedFonObj.fontStyle == "italic") ? this.textStyleItalic(true) : this.textStyleItalic(false);
  174. (selectedFonObj.textDecoration == "underline") ? this.textStyleUnderline(true) : this.textStyleUnderline(false);
  175. (selectedFonObj.textDecoration == "line-through") ? this.textStyleStrikethrough(true) : this.textStyleStrikethrough(false);
  176. (selectedFonObj.textDecoration == "overline") ? this.textStyleLineover(true) : this.textStyleLineover(false);
  177. this.textFontFill(selectedFonObj.fill);
  178. this.textStroke(selectedFonObj.stroke);
  179. $("#textStyleFontColor").spectrum("set",selectedFonObj.fill);
  180. $("#textStroke").spectrum("set",selectedFonObj.stroke);
  181. this.textStrokeWidth(selectedFonObj.strokeWidth);
  182. }
  183. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement