Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of useExistingjQuery parameter to RenderIncludes() #29

Merged
merged 2 commits into from Apr 12, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions StackExchange.Profiling/MiniProfiler.Settings.cs
Expand Up @@ -195,6 +195,12 @@ public static void ExcludeMethod(string methodName)
[DefaultValue(false)] [DefaultValue(false)]
public static bool ShowControls { get; set; } public static bool ShowControls { get; set; }


/// Determines if Miniprofiler relies on jQuery already loaded on the page; defaults to false.
/// For a per-page override you can use .RenderIncludes(useExistingjQuery: true/false)
/// </summary>
[DefaultValue(false)]
public static bool UseExistingjQuery { get; set; }

/// <summary> /// <summary>
/// By default, SqlTimings will grab a stack trace to help locate where queries are being executed. /// By default, SqlTimings will grab a stack trace to help locate where queries are being executed.
/// When this setting is true, no stack trace will be collected, possibly improving profiler performance. /// When this setting is true, no stack trace will be collected, possibly improving profiler performance.
Expand Down
9 changes: 5 additions & 4 deletions StackExchange.Profiling/MiniProfiler.cs
Expand Up @@ -334,11 +334,12 @@ public static IDisposable StepStatic(string name, ProfileLevel level = ProfileLe
/// <param name="showTrivial">Whether to show trivial timings by default (defaults to false)</param> /// <param name="showTrivial">Whether to show trivial timings by default (defaults to false)</param>
/// <param name="showTimeWithChildren">Whether to show time the time with children column by default (defaults to false)</param> /// <param name="showTimeWithChildren">Whether to show time the time with children column by default (defaults to false)</param>
/// <param name="maxTracesToShow">The maximum number of trace popups to show before removing the oldest (defaults to 15)</param> /// <param name="maxTracesToShow">The maximum number of trace popups to show before removing the oldest (defaults to 15)</param>
/// <param name="showControls">when true, shows buttons to minimize and clear MiniProfiler results</param> /// <param name="showControls">when true, shows buttons to minimize and clear MiniProfiler results</param>
/// <returns>Script and link elements normally; an empty string when there is no active profiling session.</returns> /// <param name="useExistingjQuery">Whether MiniProfiler should attempt to load its own version of jQuery, or rely on a version previously loaded on the page</param>
public static IHtmlString RenderIncludes(RenderPosition? position = null, bool? showTrivial = null, bool? showTimeWithChildren = null, int? maxTracesToShow = null, bool? showControls = null, bool samplingOnly = false) /// <returns>Script and link elements normally; an empty string when there is no active profiling session.</returns>
public static IHtmlString RenderIncludes(RenderPosition? position = null, bool? showTrivial = null, bool? showTimeWithChildren = null, int? maxTracesToShow = null, bool? showControls = null, bool? useExistingjQuery = null, bool samplingOnly = false)
{ {
return UI.MiniProfilerHandler.RenderIncludes(Current, position, showTrivial, showTimeWithChildren, maxTracesToShow, showControls); return UI.MiniProfilerHandler.RenderIncludes(Current, position, showTrivial, showTimeWithChildren, maxTracesToShow, showControls, useExistingjQuery);
} }


/// <summary> /// <summary>
Expand Down
4 changes: 2 additions & 2 deletions StackExchange.Profiling/SqlFormatters/InlineFormatter.cs
Expand Up @@ -36,9 +36,9 @@ public string FormatSql(SqlTiming timing)
foreach(var p in timing.Parameters) foreach(var p in timing.Parameters)
{ {
// If the parameter doesn't have a prefix (@,:,etc), append one // If the parameter doesn't have a prefix (@,:,etc), append one
var name = _paramPrefixes.IsMatch(p.Name) ? p.Name : Regex.Match(sql, "([@:?])" + p.Name).Value; var name = _paramPrefixes.IsMatch(p.Name) ? p.Name : Regex.Match(sql, "([@:?])" + p.Name, RegexOptions.IgnoreCase).Value;
var value = GetParameterValue(p); var value = GetParameterValue(p);
sql = Regex.Replace(sql, "(" + name + ")([^0-9]|$)", m => value + m.Groups[2], RegexOptions.IgnoreCase); sql = Regex.Replace(sql, "(" + name + ")([^0-9A-z]|$)", m => value + m.Groups[2], RegexOptions.IgnoreCase);
} }


return sql; return sql;
Expand Down
13 changes: 9 additions & 4 deletions StackExchange.Profiling/UI/MiniProfilerHandler.cs
Expand Up @@ -15,7 +15,7 @@ namespace StackExchange.Profiling.UI
/// </summary> /// </summary>
public class MiniProfilerHandler : IRouteHandler, IHttpHandler public class MiniProfilerHandler : IRouteHandler, IHttpHandler
{ {
internal static HtmlString RenderIncludes(MiniProfiler profiler, RenderPosition? position = null, bool? showTrivial = null, bool? showTimeWithChildren = null, int? maxTracesToShow = null, bool? showControls = null) internal static HtmlString RenderIncludes(MiniProfiler profiler, RenderPosition? position = null, bool? showTrivial = null, bool? showTimeWithChildren = null, int? maxTracesToShow = null, bool? showControls = null, bool? useExistingjQuery = null)
{ {
const string format = const string format =
@"<script type=""text/javascript""> @"<script type=""text/javascript"">
Expand Down Expand Up @@ -52,8 +52,12 @@ internal static HtmlString RenderIncludes(MiniProfiler profiler, RenderPosition?
}}); }});
}}); }});
}}; }};

if ({useExistingjQuery}) {{
load('{path}jquery.1.7.1.js?v={version}', initMp); jQueryMP = jQuery;
initMp();
}} else {{
load('{path}jquery.1.7.1.js?v={version}', initMp);
}}


}}; }};


Expand Down Expand Up @@ -111,7 +115,8 @@ internal static HtmlString RenderIncludes(MiniProfiler profiler, RenderPosition?
maxTracesToShow = maxTracesToShow ?? MiniProfiler.Settings.PopupMaxTracesToShow, maxTracesToShow = maxTracesToShow ?? MiniProfiler.Settings.PopupMaxTracesToShow,
showControls = showControls ?? MiniProfiler.Settings.ShowControls ? "true" : "false", showControls = showControls ?? MiniProfiler.Settings.ShowControls ? "true" : "false",
currentId = profiler.Id, currentId = profiler.Id,
authorized = authorized ? "true" : "false" authorized = authorized ? "true" : "false",
seExistingjQuery = useExistingjQuery ?? MiniProfiler.Settings.UseExistingjQuery ? "true" : "false"
}); });


} }
Expand Down