public void TestErrorNoContext() { try { JsContext.Add(new JsCall("init")); Assert.Fail(); } catch (Exception) {} }
public void TestRunnable() { var v1 = new JsVariable("var1"); var v2 = new JsVariable("var2"); var cl = new JsClosure(() => JsContext.Add(new JsCall("alert", v1, v2)), v2, v1); Assert.AreEqual("function(var2, var1){alert(var1, var2);}", cl.Encode()); }
public void TestExecute() { var expr = JsContext.Execute(() => { JsContext.Add(new JsCall("init")); JsContext.Add(new JsCall("init2", 123)); }); Assert.AreEqual("init();init2(123);", expr.Encode()); }
public void TestEncodeOnLoadAsHtml() { string result = new JsClosure(() => { JsContext.Add(new JsCall("init")); JsContext.Add(new JsCall("init2", 123)); }).EncodeOnLoadAsHtml(); Assert.AreEqual("<script>jQuery(function(){init();init2(123);})</script>", result); }
/** * This method generates corresponding javascript call of the proxied component * and registers it in the current scripting context. * * @param method method name * @param params arbitrary method parameters */ protected void Invoke(string method, params object[] parameters) { if (Id == null && _query == null) { return; } var p = new List <object>(); p.AddRange(parameters); String selector = Id == null ? "$('" + _query + "').": "$$('" + ClientId + "')."; JsContext.Add(new JsCall(selector + Family, ClassName, method, p)); }
static void Handle(Exception e) { JsContext.Add(new JsCall("alert", e.Message)); }