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

ProcessPageAfterEditing() public static method

public static ProcessPageAfterEditing ( XmlElement destinationPageDiv, XmlElement edittedPageDiv ) : void
destinationPageDiv System.Xml.XmlElement
edittedPageDiv System.Xml.XmlElement
return void
        public static void ProcessPageAfterEditing(XmlElement destinationPageDiv, XmlElement edittedPageDiv)
        {
            // strip out any elements that are part of bloom's UI; we don't want to save them in the document or show them in thumbnails etc.
            // Thanks to http://stackoverflow.com/questions/1390568/how-to-match-attributes-that-contain-a-certain-string for the xpath.
            // The idea is to match class attriutes which have class bloom-ui, but may have other classes. We don't want to match
            // classes where bloom-ui is a substring, though, if there should be any. So we wrap spaces around the class attribute
            // and then see whether it contains bloom-ui surrounded by spaces.
            // However, we need to do this in the edited page before copying to the storage page, since we are about to suck
            // info from the edited page into the dataDiv and we don't want the bloom-ui elements in there either!
            foreach(
                var node in
                    edittedPageDiv.SafeSelectNodes("//*[contains(concat(' ', @class, ' '), ' bloom-ui ')]").Cast<XmlNode>().ToArray())
                node.ParentNode.RemoveChild(node);

            destinationPageDiv.InnerXml = edittedPageDiv.InnerXml;

            //Enhance: maybe we should just copy over all attributes?
            destinationPageDiv.SetAttribute("class", edittedPageDiv.GetAttribute("class"));
            //The SIL LEAD SHRP templates rely on "lang" on some ancestor to trigger the correct rules in labels.css.
            //Those get set by putting data-metalanguage on Page, which then leads to a lang='xyz'. Let's save that
            //back to the html in keeping with our goal of having the page look right if you were to just open the
            //html file in Firefox.
            destinationPageDiv.SetAttribute("lang", edittedPageDiv.GetAttribute("lang"));

            // Upon save, make sure we are not in layout mode.  Otherwise we show the sliders.
            foreach(
                var node in
                    destinationPageDiv.SafeSelectNodes(".//*[contains(concat(' ', @class, ' '), ' origami-layout-mode ')]")
                        .Cast<XmlNode>()
                        .ToArray())
            {
                string currentValue = node.Attributes["class"].Value;
                node.Attributes["class"].Value = currentValue.Replace("origami-layout-mode", "");
            }
        }