/// <summary> /// Adds or removes the "enabled" property based on the parameter value /// </summary> /// <param name="selection"></param> /// <param name="addRemoveSwitch"></param> /// <returns></returns> public static CQ ToggleDisabled(this CQ selection, bool addRemoveSwitch) { return(selection.Each((el) => { selection.Prop("disabled", addRemoveSwitch); })); }
private static CQ ReplaceOuterWithTag(this CQ element, string tag) { element.Each(domobj => { CQ t = new CQ(tag); CQ o = new CQ(domobj); o.ReplaceOuterWith(t); }); return(element); }
protected string GetChildTags(CQ csq) { string tags = ""; csq.Each(delegate(IDomObject e) { tags += (tags == "" ? "" : ",") + "'" + e.NodeName + "'"; }); return(tags); }
public void BasicDomCreation() { string tags = String.Empty; csq.Each(delegate(IDomObject e) { tags += (tags == "" ? "" : ",") + e.NodeName; }); Assert.AreEqual(12, csq.Length, "Found correct number of elements in the DOM"); }
public void WriteBooks(AppConf appConfig) { AppName = appConfig.Name; FireEvent(AppInitializing, new WebBookEventArgs(appConfig)); Fs appFs = appConfig.AppRoot; // get all the pages AppMetaManager manager = new AppMetaManager(appConfig.BamConf); List <string> pageNames = new List <string>(manager.GetPageNames(appConfig.Name)); WritePageList(appFs, pageNames.ToArray()); // read all the pages pageNames.Each(pageName => { FireEvent(WritingBook, new WebBookEventArgs(appConfig)); CurrentPage = pageName; // create a new book for every page WebBook book = new WebBook { Name = pageName }; string content = appFs.ReadAllText("pages", "{0}.html"._Format(pageName)); // get all the [data-navigate-to] and a elements CQ cq = CQ.Create(content); CQ navElements = cq["a, [data-navigate-to]"]; navElements.Each(nav => { // create a WebBookPage for each target string href = nav.Attributes["href"]; string navTo = nav.Attributes["data-navigate-to"]; string url = string.IsNullOrEmpty(navTo) ? href : navTo; if (!string.IsNullOrEmpty(url)) { url = url.Contains('?') ? url.Split('?')[0] : url; string layout = nav.Attributes["data-layout"]; layout = string.IsNullOrEmpty(layout) ? "basic" : layout; if (pageNames.Contains(url)) { book.Pages.Add(new WebBookPage { Name = url, Layout = layout }); } } }); WriteBook(appFs, book); FireEvent(WroteBook, new WebBookEventArgs(appConfig)); }); FireEvent(AppInitialized, new WebBookEventArgs(appConfig)); }
public void CssStringHash() { Assert.AreEqual(jQuery("#qunit-fixture").Css("display"), "block", "Check for css property \"display\""); Assert.IsTrue(jQuery("#nothiddendiv").Is(":visible"), "Modifying CSS display: Assert element is visible"); jQuery("#nothiddendiv").CssSet("{display: 'none'}"); Assert.IsTrue(!jQuery("#nothiddendiv").Is(":visible"), "Modified CSS display: Assert element is hidden"); jQuery("#nothiddendiv").CssSet("{display: 'block'}"); Assert.IsTrue(jQuery("#nothiddendiv").Is(":visible"), "Modified CSS display: Assert element is visible"); //Assert.IsTrue( jQuery(window).Is(":visible"), "Calling is(':visible') on window does not throw an error in IE."); //Assert.IsTrue( jQuery(document).Is(":visible"), "Calling is(':visible') on document does not throw an error in IE."); var div = jQuery("<div>"); // These should be "auto" (or some better value) // temporarily provide "0px" for backwards compat //Assert.AreEqual( div.Css("width"), "0px", "Width on disconnected node." ); //Assert.AreEqual( div.Css("height"), "0px", "Height on disconnected node." ); div.CssSet("{ width: 4, height: 4 }"); Assert.AreEqual(div.Css("width"), "4px", "Width on disconnected node."); Assert.AreEqual(div.Css("height"), "4px", "Height on disconnected node."); var div2 = jQuery("<div style='display:none;'><input type='text' style='height:20px;'/><textarea style='height:20px;'/><div style='height:20px;'></div></div>") .AppendTo("body"); Assert.AreEqual(div2.Find("input").Css("height"), "20px", "Height on hidden input."); Assert.AreEqual(div2.Find("textarea").Css("height"), "20px", "Height on hidden textarea."); Assert.AreEqual(div2.Find("div").Css("height"), "20px", "Height on hidden textarea."); div2.Remove(); // handle negative numbers by ignoring #1599, #4216 jQuery("#nothiddendiv").CssSet("{width: 1, height: 1}"); var width = parseFloat(jQuery("#nothiddendiv").Css("width")); var height = parseFloat(jQuery("#nothiddendiv").Css("height")); //TODO - add detailed CSS validations. For now this would create the start of probably many //special cases, not going down that road. //jQuery("#nothiddendiv").CssSet("{ width: -1, height: -1 }"); //Assert.AreEqual( parseFloat(jQuery("#nothiddendiv").Css("width")), width, "Test negative width ignored"); //Assert.AreEqual( parseFloat(jQuery("#nothiddendiv").Css("height")), height, "Test negative height ignored"); Assert.AreEqual(jQuery("<div style='display: none;'>").Css("display"), "none", "Styles on disconnected nodes"); jQuery("#floatTest").CssSet("{'float': 'right'}"); Assert.AreEqual(jQuery("#floatTest").Css("float"), "right", "Modified CSS float using \"float\": Assert float is right"); jQuery("#floatTest").CssSet("{'font-size': '30px'}"); Assert.AreEqual(jQuery("#floatTest").Css("font-size"), "30px", "Modified CSS font-size: Assert font-size is 30px"); CQ.Each("0,0.25,0.5,0.75,1".Split(','), (string n) => { jQuery("#foo").CssSet("{ opacity: " + n + "}"); Assert.AreEqual(jQuery("#foo").Css("opacity"), n, "Assert opacity is " + parseFloat(n) + " as a String"); jQuery("#foo").CssSet("{opacity: " + n + "}"); Assert.AreEqual(jQuery("#foo").Css("opacity"), n, "Assert opacity is " + parseFloat(n) + " as a Number"); }); jQuery("#foo").CssSet("{opacity: ''}"); Assert.AreEqual(jQuery("#foo").Css("opacity"), "1", "Assert opacity is 1 when set to an empty String"); //Assert.AreEqual( jQuery("#empty").Css("opacity"), "0", "Assert opacity is accessible via filter property set in stylesheet in IE" ); jQuery("#empty").Css("{ opacity: '1'}"); Assert.AreEqual(jQuery("#empty").Css("opacity"), "1", "Assert opacity is taken from style attribute when set vs stylesheet in IE with filters"); //jQuery.support.opacity ? // Assert.IsTrue(true, "Requires the same number of tests"): // Assert.IsTrue( ~jQuery("#empty")[0].currentStyle.filter.indexOf("gradient"), "Assert setting opacity doesn't overwrite other filters of the stylesheet in IE" ); div = jQuery("#nothiddendiv"); var child = jQuery("#nothiddendivchild"); // STOPPED HERE: Things get wierd with CSS because obviously we can only set values and not expect browser interpretation upon reading. /// Assert.AreEqual( parseInt(div.Css("fontSize")), 16, "Verify fontSize px set." ); //// We always return strings. //Assert.AreEqual(parseInt(div.Css("font-size")), "16px", "Verify fontSize px set."); ////Assert.AreEqual( parseInt(child.Css("fontSize")), 16, "Verify fontSize px set." ); //Assert.AreEqual(parseInt(child.Css("font-size")), 16, "Verify fontSize px set."); //child.Css("height", "100%"); //Assert.AreEqual(child[0].Style.Height, "100%", "Make sure the height is being set correctly."); //child.Attr("class", "em"); //Assert.AreEqual(parseInt(child.Css("font-size")), 32, "Verify fontSize em set."); //// Have to verify this as the result depends upon the browser's CSS //// support for font-size percentages //child.Attr("class", "prct"); //var prctval = parseInt(child.Css("font-size")); //int? checkval = 0; //if (prctval == 16 || prctval == 24) //{ // checkval = prctval; //} //Assert.AreEqual(prctval, checkval, "Verify fontSize % set."); //Assert.AreEqual(child.Css("width").GetType(), typeof(string), "Make sure that a string width is returned from css('width')."); //var old = child[0].Style.Height; //// Test NaN //child.Css("height", parseFloat("zoo")); //Assert.AreEqual(child[0].Style.Height, old, "Make sure height isn't changed on NaN."); //// Test null //child.Css("height", null); //Assert.AreEqual(child[0].Style.Height, old, "Make sure height isn't changed on null."); //old = child[0].Style["font-size"]; //// Test NaN //child.Css("font-size", parseFloat("zoo")); //Assert.AreEqual(child[0].Style["font-size"], old, "Make sure font-size isn't changed on NaN."); //// Test null //child.Css("font-size", null); //Assert.AreEqual(child[0].Style["font-size"], old, "Make sure font-size isn't changed on null."); }
public void Miscellaneous() { t("Headers", ":header", Arrays.String("qunit-header", "qunit-banner", "qunit-userAgent")); t("Has Children - :has()", "p:has(a)", Arrays.String("firstp", "ap", "en", "sap")); var select = document.GetElementById("select1"); Assert.IsTrue(match(select, ":has(option)"), "Has Option Matches"); t("Text Contains", "a:contains(Google)", Arrays.String("google", "groups")); t("Text Contains", "a:contains(Google Groups)", Arrays.String("groups")); // [CsQuery] We don't at this time allow constructst like "a:contains(Google Groups(link))" // without quoting (e.g. inner parsing of parens without quotes). Deal with it. This is changed // from the original to quote the selection. t("Text Contains", "a:contains('Google Groups (Link)')", Arrays.String("groups")); t("Text Contains", "a:contains('(Link)')", Arrays.String("groups")); var tmp = document.CreateElement("div"); tmp.Id = "tmp_input"; document.Body.AppendChild(tmp); CQ.Each(Arrays.String("button", "submit", "reset"), (type) => { jQuery(tmp).Append( "<input id='input_T' type='T'/><button id='button_T' type='T'>test</button>".Replace("T", type)); t("Input Buttons :" + type, "#tmp_input :" + type, Arrays.String("input_" + type, "button_" + type)); Assert.IsTrue(match(Sizzle["#input_" + type][0], ":" + type), "Input Matches :" + type); Assert.IsTrue(match(Sizzle["#button_" + type][0], ":" + type), "Button Matches :" + type); }); document.Body.RemoveChild(tmp); //[CsQuery] These tests are UI related and therefore not needed //var input = document.CreateElement("input"); //input.Type = "text"; //input.Id = "focus-input"; //document.Body.AppendChild( input ); //input.focus(); // Inputs can't be focused unless the document has focus //if ( document.activeElement !== input || (document.hasFocus && !document.hasFocus()) || // (document.querySelectorAll && !document.querySelectorAll("input:focus").length) ) { // ok( true, "The input was not focused. Skip checking the :focus match." ); // ok( true, "The input was not focused. Skip checking the :focus match." ); //} else { // t( "Element focused", "input:focus", Arrays.String("focus-input" ) ); // ok( match( input, ":focus" ), ":focus Matches" ); //} // :active selector: this selector does not depend on document focus //if ( document.activeElement === input ) { // ok( match( input, ":active" ), ":active Matches" ); //} else { // ok( true, "The input did not become active. Skip checking the :active match." ); //} //input.blur(); // When IE is out of focus, blur does not work. Force it here. //if ( document.activeElement === input ) { // document.body.focus(); //} //ok( !match( input, ":focus" ), ":focus doesn't match" ); //ok( !match( input, ":active" ), ":active doesn't match" ); //document.body.removeChild( input ); }