Ejemplo n.º 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);
 }
Ejemplo n.º 2
0
 /// <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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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));
 }