コード例 #1
0
 /// <summary>
 /// Adds the specified class(es) to the element.
 /// </summary>
 /// <param name="element">Element.</param>
 /// <param name="classNames">One or more classes to be added to the class attribute of the element.</param>
 /// <returns>Element</returns>
 public static HElement AddClass(this HElement element, IEnumerable <String> classNames)
 {
     if (element != null && classNames != null)
     {
         element.Attribute("class", String.Join(" ", element.GetClasses().Concat(classNames).Distinct(StringComparer.OrdinalIgnoreCase)));
     }
     return(element);
 }
コード例 #2
0
ファイル: DataExtensions.cs プロジェクト: ygrenier/HDocument
 /// <summary>
 /// Indicates if an element contains a data value
 /// </summary>
 public static bool HasData(this HElement element, String key)
 {
     if (element == null || String.IsNullOrWhiteSpace(key))
     {
         return(false);
     }
     return(element.Attribute(MakeDataKey(key)) != null);
 }
コード例 #3
0
 /// <summary>
 /// Remove some class names to an element.
 /// </summary>
 /// <param name="element"></param>
 /// <param name="className"></param>
 /// <returns></returns>
 public static HElement RemoveClass(this HElement element, String[] className)
 {
     if (element != null && className != null && className.Length > 0)
     {
         var classes = element.GetClasses();
         element.Attribute("class", String.Join(" ", classes.Except(className, StringComparer.OrdinalIgnoreCase)));
     }
     return(element);
 }
コード例 #4
0
        /// <summary>
        /// Extract classes from an element
        /// </summary>
        public static String[] GetClasses(this HElement element)
        {
            HAttribute clsAttr = element != null?element.Attribute("class") : null;

            if (clsAttr == null || clsAttr.Value == null)
            {
                return(new String[0]);
            }
            return(ExtractClassNames(clsAttr.Value));
        }
コード例 #5
0
 /// <summary>
 /// Get the value of the attribute of the element.
 /// </summary>
 public static String Attr(this HElement element, String name)
 {
     if (element != null && !String.IsNullOrWhiteSpace(name))
     {
         var attr = element.Attribute(name);
         if (attr != null)
         {
             return(attr.Value);
         }
     }
     return(null);
 }
コード例 #6
0
 /// <summary>
 /// Remove all classes to an element.
 /// </summary>
 /// <param name="element"></param>
 /// <returns></returns>
 public static HElement RemoveClass(this HElement element)
 {
     if (element != null)
     {
         var attr = element.Attribute("class");
         if (attr != null)
         {
             attr.Remove();
         }
     }
     return(element);
 }
コード例 #7
0
 /// <summary>
 /// Remove attributes from the element
 /// </summary>
 public static HElement RemoveAttr(this HElement element, params String[] attributes)
 {
     if (element != null && attributes != null)
     {
         foreach (var attrName in attributes)
         {
             var attr = element.Attribute(attrName);
             if (attr != null)
             {
                 attr.Remove();
             }
         }
     }
     return(element);
 }
コード例 #8
0
 /// <summary>
 /// Set one attribute for the element.
 /// </summary>
 /// <param name="element">Element.</param>
 /// <param name="name">Attribute name.</param>
 /// <param name="value">Attribute value</param>
 /// <returns>The element</returns>
 public static HElement Attribute(this HElement element, String name, String value)
 {
     if (element != null && !String.IsNullOrWhiteSpace(name))
     {
         var attr = element.Attribute(name);
         if (String.IsNullOrEmpty(value))
         {
             if (attr != null)
             {
                 attr.Remove();
             }
         }
         else
         {
             if (attr == null)
             {
                 attr = new HAttribute(name);
                 element.Add(attr);
             }
             attr.Value = value;
         }
     }
     return(element);
 }
コード例 #9
0
 /// <summary>
 /// Set one attribute for the element.
 /// </summary>
 public static HElement Attr(this HElement element, String name, String value)
 {
     return(element.Attribute(name, value));
 }