Bloom.Book.HtmlDom.RemoveClassesBeginingWith C# (CSharp) Method

RemoveClassesBeginingWith() public static method

public static RemoveClassesBeginingWith ( XmlElement xmlElement, string classPrefix ) : void
xmlElement System.Xml.XmlElement
classPrefix string
return void
        public static void RemoveClassesBeginingWith(XmlElement xmlElement, string classPrefix)
        {
            var classes = xmlElement.GetAttribute("class");
            var original = classes;

            if(String.IsNullOrEmpty(classes))
                return;
            var parts = classes.SplitTrimmed(' ');

            classes = "";
            foreach(var part in parts)
            {
                if(!part.StartsWith(classPrefix))
                    classes += part + " ";
            }
            xmlElement.SetAttribute("class", classes.Trim());

            //	Debug.WriteLine("RemoveClassesBeginingWith    " + xmlElement.InnerText+"     |    "+original + " ---> " + classes);
        }

Usage Example

        private static void UpdateContentLanguageClassesOnElement(XmlElement e, Dictionary <string, string> contentLanguages, BookData bookData, string contentLanguageIso2, string contentLanguageIso3, string[] dataDefaultLanguages)
        {
            HtmlDom.RemoveClassesBeginingWith(e, "bloom-content");
            var lang = e.GetAttribute("lang");

            //These bloom-content* classes are used by some stylesheet rules, primarily to boost the font-size of some languages.
            //Enhance: this is too complex; the semantics of these overlap with each other and with bloom-visibility-code-on, and with data-language-order.
            //It would be better to have non-overlapping things; 1 for order, 1 for visibility, one for the lang's role in this collection.
            string orderClass;

            if (contentLanguages.TryGetValue(lang, out orderClass))
            {
                HtmlDom.AddClass(e, orderClass);                 //bloom-content1, bloom-content2, bloom-content3
            }

            //Enhance: it's even more likely that we can get rid of these by replacing them with bloom-content2, bloom-content3
            if (lang == bookData.MetadataLanguage1IsoCode)
            {
                HtmlDom.AddClass(e, "bloom-contentNational1");
            }
            if (lang == bookData.Language3IsoCode)
            {
                HtmlDom.AddClass(e, "bloom-contentNational2");
            }

            HtmlDom.RemoveClassesBeginingWith(e, "bloom-visibility-code");
            if (ShouldNormallyShowEditable(lang, dataDefaultLanguages, contentLanguageIso2, contentLanguageIso3, bookData))
            {
                HtmlDom.AddClass(e, "bloom-visibility-code-on");
            }

            UpdateRightToLeftSetting(bookData, e, lang);
        }
All Usage Examples Of Bloom.Book.HtmlDom::RemoveClassesBeginingWith