string AttachConstructor(JsModule module, string type) { var varModule = JsFunction.VarName(AttachFunction.Module); var varLines = JsFunction.VarName(module); var line = type.FirstLower(); var args = AttachFunction.Arguments.ToString(a => a == JsFunction.This ? "that" : a == this ? line : JsonConvert.SerializeObject(a, AttachFunction.JsonSerializerSettings), ", "); var result = "require(['" + module + "', '" + AttachFunction.Module.Name + "'], function(" + varLines + ", " + varModule + ") {\r\n" + "var " + line + " = " + NewLine(varLines, type) + ";\r\n" + varModule + "." + AttachFunction.FunctionName + "(" + args + ");\r\n" + line + ".ready();\r\n" + "});"; if (!AttachFunction.Arguments.Contains(JsFunction.This)) { return(result); } return("(function(that) { " + result + "})(this)"); }
string BasicConstructor(JsModule module, string type) { var varNameLines = JsFunction.VarName(module); var result = "require(['" + module + "'], function(" + varNameLines + ") { " + NewLine(varNameLines, type) + ".ready(); });"; return(result); }
public MvcHtmlString ConstructorScript(JsModule module, string type) { var result = AttachFunction != null? AttachConstructor(module, type) : BasicConstructor(module, type); return(new MvcHtmlString("<script>" + result + "</script>")); }
internal static string VarName(JsModule module) { var result = module.Name.TryAfterLast(".") ?? module.Name; result = result.TryAfterLast("/") ?? result; result = Regex.Replace(result, "[^a-zA-Z0-9]", ""); return(result); }
internal JsFunction(JsModule module, string functionName, params object[] arguments) { if (module == null) throw new ArgumentNullException("module"); if (functionName == null) throw new ArgumentNullException("functionName"); this.Module = module; this.FunctionName = functionName; this.Arguments = arguments ?? new object[0]; }
internal JsFunction(JsModule module, string functionName, params object[] arguments) { if (module == null) { throw new ArgumentNullException("module"); } if (functionName == null) { throw new ArgumentNullException("functionName"); } this.Module = module; this.FunctionName = functionName; this.Arguments = arguments ?? new object[0]; }
string BasicConstructor(JsModule module, string type) { var varNameLines = JsFunction.VarName(module); var result = "require(['" + module + "'], function(" + varNameLines + ") { " + NewLine(varNameLines, type) + ".ready(); });"; return result; }
string AttachConstructor(JsModule module, string type) { var varModule = JsFunction.VarName(AttachFunction.Module); var varLines = JsFunction.VarName(module); var line = type.FirstLower(); var args = AttachFunction.Arguments.ToString(a => a == JsFunction.This ? "that" : a == this ? line : JsonConvert.SerializeObject(a, AttachFunction.JsonSerializerSettings), ", "); var result = "require(['" + module + "', '" + AttachFunction.Module.Name + "'], function(" + varLines + ", " + varModule + ") {\r\n" + "var " + line + " = " + NewLine(varLines, type) + ";\r\n" + varModule + "." + AttachFunction.FunctionName + "(" + args + ");\r\n" + line + ".ready();\r\n" + "});"; if (!AttachFunction.Arguments.Contains(JsFunction.This)) return result; return "(function(that) { " + result + "})(this)"; }
public MvcHtmlString ConstructorScript(JsModule module, string type) { var result = AttachFunction != null ? AttachConstructor(module, type) : BasicConstructor(module, type); return new MvcHtmlString("<script>" + result + "</script>"); }
internal static string VarName(JsModule module) { var result = module.Name.TryAfterLast(".") ?? module.Name; result = result.TryAfterLast("/") ?? result; result = Regex.Replace(result, "[^a-zA-Z0-9]", ""); return result; }