/// <summary> /// Получить атрибуты (в том числе события) одной строкой /// </summary> public virtual string GetStringAttributes() { if (!string.IsNullOrWhiteSpace(CacheAttributes)) { return(CacheAttributes.Trim()); } if (!string.IsNullOrWhiteSpace(ID)) { SetAttribute("id", ID.Trim()); } if (!string.IsNullOrWhiteSpace(Accesskey)) { SetAttribute("accesskey", Accesskey.Trim()); } if (Contenteditable) { SetAttribute("contenteditable", "true"); } if (Hidden) { SetAttribute("hidden", null); } if (Tabindex != default) { SetAttribute("tabindex", Tabindex.ToString()); } if (!string.IsNullOrWhiteSpace(Title)) { SetAttribute("title", Title.Trim()); } CacheAttributes = " "; foreach (KeyValuePair <string, string> kvp in CustomAttributes) { if (kvp.Value is null) { CacheAttributes += kvp.Key + " "; } else { CacheAttributes += kvp.Key + "=\"" + kvp.Value + "\" "; } } string tmp_css_string = GetStringCSS(); if (!string.IsNullOrWhiteSpace(tmp_css_string)) { CacheAttributes += "class=\"" + tmp_css_string + "\" "; } if (CustomStyles.Count > 0) { CacheAttributes += "style=\"" + GetStringStyles() + "\" "; } return(CacheAttributes.Trim()); }
/// <summary> /// Установить значение атрибута (добавить если атрибут отсутсвует). /// </summary> /// <param name="attr_name">Имя атрибута dom объекта</param> /// <param name="attr_value">Если знаение атрибута IS NULL, то генератор объявит имя атрибута без упоминания значения этого атрибута (т.е. будет пропущен знак = и его значение)</param> public ahsDom SetAttribute(string attr_name, string attr_value) { attr_name = attr_name.Trim().ToLower(); if (IndependentAttributes.Contains(attr_name)) { return(this); } if (attr_name == "id") { if (attr_value != ID) { CacheAttributes = string.Empty; ID = attr_value; } } if (attr_name == "accesskey") { if (attr_value != Accesskey) { CacheAttributes = string.Empty; Accesskey = attr_value; } } if (attr_name == "contenteditable") { bool new_value = attr_value.ToLower() == "true" || attr_value.ToLower().EndsWith("editable"); if (Contenteditable != new_value) { CacheAttributes = string.Empty; Contenteditable = new_value; } } if (attr_name == "hidden") { bool new_value = attr_value.ToLower() == "true" || attr_value.ToLower() == "hidden"; if (new_value != Hidden) { CacheAttributes = string.Empty; Hidden = new_value; } } if (attr_name == "tabindex") { if (attr_value != Tabindex.ToString()) { if (!Regex.IsMatch(attr_value, @"^-?\d+$")) { return(this); } CacheAttributes = string.Empty; Tabindex = int.Parse(attr_value); } } if (attr_name == "title") { if (attr_value != Title) { CacheAttributes = string.Empty; Title = attr_value; } } if (!CustomAttributes.ContainsKey(attr_name)) { CacheAttributes = string.Empty; CustomAttributes.Add(attr_name, attr_value); } else if (CustomAttributes[attr_name] != attr_value) { CacheAttributes = string.Empty; CustomAttributes[attr_name] = attr_value; } return(this); }