/// <summary> /// Deals with tbody as the target of appends. /// </summary> /// /// <param name="target"> /// The true target. /// </param> /// /// <returns> /// Either the element itself, or the TBODY element if the target was a TABLE /// </returns> private IDomElement GetTrueTarget(IDomElement target) { //Special handling for tables: make sure we add to the TBODY IDomElement element = target; if (target.NodeNameID == HtmlData.tagTABLE) { bool addBody = false; if (target.HasChildren) { IDomElement body = target.ChildElements.FirstOrDefault(item => item.NodeNameID == HtmlData.tagTBODY); if (body != null) { element = body; } else if (target.FirstElementChild == null) { // Add a body if there are no elements in this table yet addBody = true; } // default = leave it alone, they've already added elements. don't worry whether it's valid or not, // assume they know what they're doing. } else { addBody = true; } if (addBody) { element = Document.CreateElement("tbody"); target.AppendChild(element); } } return(element); }
/// <summary> /// Append each element passed by parameter to each element in the selection set. The inserted /// elements are returned. /// </summary> /// /// <param name="elements"> /// The elements to be excluded. /// </param> /// <param name="insertedElements"> /// A CQ object containing all the elements added. /// </param> /// /// <returns> /// The current CQ object. /// </returns> private CQ Append(IEnumerable <IDomObject> elements, out CQ insertedElements) { insertedElements = NewCqInDomain(); bool first = true; // must copy the enumerable first, since this can cause // els to be removed from it if they move across a document boundary List <IDomObject> list = new List <IDomObject>(elements); foreach (var obj in Elements) { // Make sure they didn't really mean to add to a tbody or something IDomElement target = GetTrueTarget(obj); foreach (var e in list) { IDomObject toInsert = first ? e : e.Clone(); target.AppendChild(toInsert); insertedElements.SelectionSet.Add(toInsert); } first = false; } return(this); }
private CQ Wrap(IEnumerable <IDomObject> wrapper, bool keepSiblingsTogether) { // get innermost structure CQ wrapperTemplate = EnsureCsQuery(wrapper); IDomElement wrappingEl = null; IDomElement wrappingElRoot = null; int depth = GetInnermostContainer(wrapperTemplate.Elements, out wrappingEl, out wrappingElRoot); if (wrappingEl != null) { IDomObject nextEl = null; IDomElement innerEl = null; IDomElement innerElRoot = null; foreach (IDomObject el in SelectionSet) { if (nextEl == null || (!ReferenceEquals(nextEl, el)) && !keepSiblingsTogether) { var template = wrappingElRoot.Cq().Clone(); if (el.ParentNode != null) { template.InsertBefore(el); } // This will always succceed because we tested before this loop. But we need // to run it again b/c it's a clone now GetInnermostContainer(template.Elements, out innerEl, out innerElRoot); } nextEl = el.NextSibling; innerEl.AppendChild(el); } } return(this); }
private static void CreateDropDown(IDomElement el, IEnumerable <KeyValuePair <string, object> > data, string zeroText = null) { foreach (var kvp in data) { var opt = el.Document.CreateElement("option"); opt["value"] = kvp.Key; el.AppendChild(opt); var text = el.Document.CreateTextNode( zeroText != null && kvp.Key == "0" ? zeroText : kvp.Value.ToString() ); opt.AppendChild(text); } }
/// <summary> /// Deals with tbody as the target of appends /// </summary> /// <param name="apparentTarget"></param> /// <returns></returns> protected IDomElement getTrueTarget(IDomElement target) { //Special handling for tables: make sure we add to the TBODY IDomElement element = target; if (target.NodeName == "table") { bool addBody = false; if (target.HasChildren) { IDomElement body = target.ChildElements.FirstOrDefault(item => item.NodeName == "tbody"); if (body != null) { element = body; } else if (target.FirstElementChild == null) { // Add a body if there are no elements in this table yet addBody = true; } // default = leave it alone, they've already added elements. don't worry whether it's valid or not, // assume they know what they're doing. } else { addBody = true; } if (addBody) { element = Document.CreateElement("tbody"); target.AppendChild(element); } } return element; }
private void BuildUI() { _processViewerArea = DomManager.Document.GetElementById("process-viewer-area"); _mainTable = DomManager.CreateElement("table"); _mainTable.SetAttribute("cellspacing", "2"); _mainTable.SetAttribute("cellpadding", "2"); IDomElement tr = DomManager.CreateElement("tr"); tr.SetAttribute("valign", "top"); IDomElement td = DomManager.CreateElement("td"); IDomElement sipTableHeader = DomManager.CreateElement("span"); sipTableHeader.InnerHtml = "Processes:<br />----------------------------------------<br />"; td.AppendChild(sipTableHeader); IDomElement sipTable = BuildSIPTable(); _sipTableBody = DomManager.CreateElement("tbody"); sipTable.AppendChild(_sipTableBody); td.AppendChild(sipTable); tr.AppendChild(td); td = DomManager.CreateElement("td"); IDomElement threadTableHeader = DomManager.CreateElement("span"); threadTableHeader.InnerHtml = "Threads:<br />---------------------------------------------------------------<br />"; td.AppendChild(threadTableHeader); IDomElement threadTable = BuildThreadTable(); _threadTableBody = DomManager.CreateElement("tbody"); threadTable.AppendChild(_threadTableBody); td.AppendChild(threadTable); tr.AppendChild(td); _mainTable.AppendChild(tr); _processViewerArea.AppendChild(DomManager.CreateElement("br")); _lastUpdatedElement = DomManager.CreateElement("span"); _processViewerArea.AppendChild(_lastUpdatedElement); _processViewerArea.AppendChild(DomManager.CreateElement("br")); _processViewerArea.AppendChild(_mainTable); }