JAVASCRIPT   113

style-properties.js

Guest on 19th July 2021 07:04:08 PM

  1. function RedNaoBaseStyleProperty(styleSetter,formElement,elementName,cssProperty,propertyLabel)
  2. {
  3.     this.StyleSetter=styleSetter;
  4.     this.FormElement=formElement;
  5.     this.ElementName=elementName;
  6.     this.CssProperty=cssProperty;
  7.     this.PropertyLabel=propertyLabel;
  8. }
  9.  
  10. RedNaoBaseStyleProperty.prototype.AppendToElement=function(jqueryElement)
  11. {
  12.     var createdElement=rnJQuery(this.GenerateInlineElement());
  13.     jqueryElement.append(createdElement);
  14.     this.GenerationCompleted(createdElement);
  15. };
  16.  
  17. RedNaoBaseStyleProperty.prototype.GetPropertyValue=function()
  18. {
  19.     if(RedNaoPathExists(this.FormElement.Options,'Styles.'+this.ElementName+'.Properties.' +this.CssProperty))
  20.         return this.FormElement.Options.Styles[this.ElementName].Properties[this.CssProperty];
  21.  
  22.     return null;
  23. };
  24.  
  25. RedNaoBaseStyleProperty.prototype.SetPropertyValue=function(value)
  26. {
  27.     Properties=this.StyleSetter.GetOrCreateSection('Properties');
  28.     Properties[this.CssProperty]=value;
  29. };
  30.  
  31. RedNaoBaseStyleProperty.prototype.RemoveProperty=function()
  32. {
  33.     if(typeof this.FormElement.Options.Styles[this.ElementName]=='undefined')
  34.         return;
  35.     if(typeof this.FormElement.Options.Styles[this.ElementName].Properties=='undefined')
  36.         return;
  37.  
  38.     if(typeof this.FormElement.Options.Styles[this.ElementName].Properties[this.CssProperty] =='undefined')
  39.         return;
  40.  
  41.     delete this.FormElement.Options.Styles[this.ElementName].Properties[this.CssProperty];
  42.  
  43.     var count=0;
  44.     for(var property in this.FormElement.Options.Styles[this.ElementName].Properties)
  45.     {
  46.         count ++;
  47.         break;
  48.     }
  49.     if(count==0)
  50.     {
  51.         this.StyleSetter.RemoveSection('Properties');
  52.     }
  53.  
  54. };
  55.  
  56. /************************************************************************************* Font Family Style ***************************************************************************************************/
  57.  
  58. function RedNaoFontFamilyStyleProperty(styleSetter,formElement,elementName,cssProperty,propertyLabel)
  59. {
  60.     RedNaoBaseStyleProperty.call(this,styleSetter,formElement,elementName,cssProperty,propertyLabel);
  61.  
  62.     this.Fonts=fonts = [smartFormsTranslation.Default,
  63.                                     '"Arial","Helvetica","sans-serif"',
  64.                                     '"Arial Black","Gadget","sans-serif"',
  65.                                     '"Comic Sans MS","cursive"',
  66.                                     '"Courier New","Courier","monospace"',
  67.                                     '"Georgia","serif"',
  68.                                     '"Impact","Charcoal","sans-serif"',
  69.                                     '"Lucida Console","Monaco","monospace"',
  70.                                     '"Lucida Sans Unicode","Lucida Grande","sans-serif"',
  71.                                     '"Palatino Linotype","Book Antiqua","Palatino,serif"',
  72.                                     '"Tahoma","Geneva","sans-serif"',
  73.                                     '"Times New Roman","Times","serif"',
  74.                                     '"Trebuchet MS","Helvetica","sans-serif"',
  75.                                     '"Verdana","Geneva","sans-serif"'];
  76.  
  77.  
  78.  
  79. }
  80. RedNaoFontFamilyStyleProperty.prototype=Object.create(RedNaoBaseStyleProperty.prototype);
  81.  
  82. RedNaoFontFamilyStyleProperty.prototype.GenerateInlineElement=function()
  83. {
  84.     var selectedFont=this.GetPropertyValue();
  85.     if(selectedFont==null)
  86.         selectedFont=smartFormsTranslation.Default;
  87.  
  88.     var fontOptions="";
  89.     for(var i=0;i<fonts.length;i++)
  90.     {
  91.         if(fonts[i]==selectedFont)
  92.             fontOptions+="<option value='"+fonts[i]+"' selected='sel'>"+fonts[i]+"</option>";
  93.         else
  94.             fontOptions+="<option value='"+fonts[i]+"'>"+fonts[i]+"</option>";
  95.  
  96.     }
  97.  
  98.     return "<tr>" +
  99.         "   <td>" +
  100.         this.PropertyLabel +
  101.         "</td>" +
  102.         "   <td> " +
  103.         "<select id='smartDonationsEditFont'  style='width:500px'>"+
  104.         fontOptions+
  105.         "</select>"  +
  106.         "   </td>" +
  107.         "</tr>" ;
  108. };
  109.  
  110. RedNaoFontFamilyStyleProperty.prototype.GenerationCompleted=function(jQueryElement)
  111. {
  112.     var self=this;
  113.     jQueryElement.find('#smartDonationsEditFont').change(function(){
  114.         var selectedValue=rnJQuery(this).val();
  115.         if(selectedValue==smartFormsTranslation.Default)
  116.             self.RemoveProperty();
  117.         else
  118.             self.SetPropertyValue(selectedValue);
  119.  
  120.         self.FormElement.ApplyTagStyleForElement(self.ElementName);
  121.     });
  122. };
  123.  
  124.  
  125. /************************************************************************************* RedNaoColorStyleProperty ***************************************************************************************************/
  126.  
  127. function RedNaoColorStyleProperty(styleSetter,formElement,elementName,cssProperty,propertyLabel)
  128. {
  129.     RedNaoBaseStyleProperty.call(this,styleSetter,formElement,elementName,cssProperty,propertyLabel);
  130. }
  131. RedNaoColorStyleProperty.prototype=Object.create(RedNaoBaseStyleProperty.prototype);
  132.  
  133. RedNaoColorStyleProperty.prototype.GenerateInlineElement=function()
  134. {
  135.     var selectedColor=this.GetPropertyValue();
  136.     if(selectedColor!=null)
  137.         selectedColor=selectedColor.substring(1);
  138.     return "<tr> " +
  139.                 "<td>" +
  140.                     this.PropertyLabel +
  141.                     "</td>" +
  142.                     "<td>" +
  143.                     "<input placeholder='"+smartFormsTranslation.Default+"'  class='color'  "+ (selectedColor!=null?("value='"+selectedColor+"'"):"")+"/>"+
  144.                 "</td>" +
  145.             "</tr>";
  146. };
  147.  
  148. RedNaoColorStyleProperty.prototype.GenerationCompleted=function(jQueryElement)
  149. {
  150.     jscolor.init();
  151.     var self=this;
  152.     jQueryElement.find('.color').change(function(){
  153.         var selectedColor=rnJQuery(this).val();
  154.  
  155.         if(selectedColor=="")
  156.             self.RemoveProperty();
  157.         else
  158.             self.SetPropertyValue('#'+selectedColor);
  159.  
  160.         self.FormElement.ApplyTagStyleForElement(self.ElementName);
  161.  
  162.     });
  163. };

Raw Paste


Login or Register to edit or fork this paste. It's free.