/// <summary> /// [CsQuery] A simple function to turn a sequence of Key/Value pairs into a pick list /// </summary> /// <param name="select"></param> /// <param name="list"></param> private void MakePickList(CQ select, IEnumerable <KeyValuePair <string, string> > list) { foreach (var item in list) { var opt = select["<option />"] .Attr("value", item.Key) .Text(item.Value); select.Append(opt); } }
/// <summary> /// [CsQuery] A simple function to turn a sequence of Key/Value pairs into a pick list /// </summary> /// <param name="select"></param> /// <param name="list"></param> private void MakePickList(CQ select, IEnumerable<KeyValuePair<string,string>> list) { foreach (var item in list) { var opt = select["<option />"] .Attr("value",item.Key) .Text(item.Value); select.Append(opt); } }
public void Contents() { Assert.AreEqual(jQuery("#ap").Contents().Length, 9, "Check element contents"); Assert.IsTrue(jQuery("#iframe").Length > 0, "Check existence of IFrame document"); jQuery("#loadediframe").Append(@"<html> <head> <title>iframe</title> </head> <body> <div><span>span text</span></div> </body> </html>"); var ibody = jQuery("#loadediframe").Contents().Find("body"); Assert.IsTrue(ibody.Length > 0, "Check existance of IFrame body"); var csq = new CQ("span", ibody); Assert.AreEqual(csq.Text(), "span text", "Find span in IFrame and check its text"); jQuery(ibody).Append("<div>init text</div>"); csq = new CQ("div", ibody); Assert.AreEqual(csq.Length, 2, "Check the original div and the new div are in IFrame"); csq = new CQ("div:last", ibody); Assert.AreEqual(csq.Text(), "init text", "Add text to div in IFrame"); csq = new CQ("div:last", ibody); csq.Text("div text"); Assert.AreEqual(new CQ("div:last", ibody).Text(), "div text", "Add text to div in IFrame"); csq = new CQ("div:last", ibody).Remove(); Assert.AreEqual(jQuery("div", ibody).Length, 1, "Delete the div and check only one div left in IFrame"); Assert.AreEqual(jQuery("div", ibody).Text(), "span text", "Make sure the correct div is still left after deletion in IFrame"); csq = new CQ("<table/>", ibody); csq.Append("<tr><td>cell</td></tr>").AppendTo(ibody); csq = new CQ("table", ibody); csq.Remove(); csq = new CQ("div", ibody); Assert.AreEqual(csq.Length, 1, "Check for JS error on add and delete of a table in IFrame"); // using contents will get comments regular, text, and comment nodes var c = jQuery("#nonnodes").Contents().Contents(); Assert.AreEqual(c.Length, 1, "Check node,textnode,comment contents is just one"); Assert.AreEqual(c[0].NodeValue, "hi", "Check node,textnode,comment contents is just the one from span"); }
public void SimpleClone() { CQ hlinks = Dom.Select("#hlinks-user"); int spanCount = hlinks.Find("span").Length; CQ clone = hlinks.Clone(); Assert.AreEqual(hlinks.Find("*").Length + 1, clone.Select("*").Length, "Clone has same total elements as original"); CQ newHome = Dom.Select("#hidden-div"); spanCount = newHome.Find("span").Length; int cloneSpanCount = clone.Select("span").Length; Assert.AreEqual(1, newHome.Children().Length, "Sanity check - target has 1 child"); newHome.Append(clone); Assert.AreEqual(2, newHome.Children().Length, "Target has 2 children after cloning"); Assert.AreEqual(spanCount + cloneSpanCount, newHome.Find("span").Length, "Same # of spans in the clone"); }
public void SimpleClone() { var dom = TestDom("TestHtml"); CQ hlinks = dom.Select("#hlinks-user"); CQ clone = hlinks.Clone(); Assert.AreEqual(hlinks.Find("*").Length, clone.Find("*").Length, "Clone has same total elements as original"); CQ newHome = dom.Select("#hidden-div"); var spanCount = newHome.Find("span").Length; int cloneSpanCount = clone.Find("span").Length; Assert.AreEqual(1, newHome.Children().Length, "Sanity check - target has 1 child"); newHome.Append(clone); Assert.AreEqual(2, newHome.Children().Length, "Target has 2 children after cloning"); }
protected override void Cq_Render() { var table = Doc["table"]; for (int row = 0; row < TableRows; row++) { CQ curRow = Doc["<tr></tr>"]; for (int col = 0; col < TableColumns; col++) { CQ curCol = Doc["<td />"].Text( String.Format("Row {0} Column {1}", row, col) ); curRow.Append(curCol); } table.Append(curRow); } // fix caption var el = Doc["#table-caption"]; el.Text(String.Format(el.Text(), TableRows, TableColumns)); }