private DomNode ApplyClass(Action <DomStringTokenList> action)
        {
            var list = DomStringTokenList.Parse(Attribute("class"));

            action(list);
            return(Attribute("class", list.ToString()));
        }
示例#2
0
 internal static bool StaticContains(string text, DomStringTokenList names)
 {
     if (string.IsNullOrEmpty(text))
     {
         return(false);
     }
     if (text.Length < names.ToString().Length)
     {
         return(false);
     }
     return(DomStringTokenList.Parse(text).IsSupersetOf(names));
 }
示例#3
0
        public virtual DomElementCollection GetElementsByClassName(string className)
        {
            if (string.IsNullOrEmpty(className))
            {
                return(DomElementCollection.Empty);
            }

            var names = DomStringTokenList.Parse(className);

            return(new DefaultDomElementCollection(
                       this,
                       n => n.Descendants.Where(t => DomStringTokenList.StaticContains(t.Attribute("class"), names))
                       ));
        }
示例#4
0
        public bool HasClass(string name)
        {
            var list = Attribute <DomStringTokenList>("class");

            if (list == null)
            {
                return(false);
            }
            var names = DomStringTokenList.Parse(name);

            if (names.Count == 0)
            {
                return(false);
            }
            return(names.All(n => list.Contains(n)));
        }
示例#5
0
 private IEnumerable <TKey> GetKeys(string value)
 {
     return(DomStringTokenList.Parse(value).Select(Key));
 }
 public DomNode RemoveClass(string classNames)
 {
     return(ApplyClass(l => l.RemoveRange(DomStringTokenList.Parse(classNames))));
 }
 public DomNode AddClass(string classNames)
 {
     return(ApplyClass(l => l.AddRange(DomStringTokenList.Parse(classNames))));
 }