Skip to content

Commit

Permalink
Adds the 'useExistingjQuery' parameter to the 'RenderIncludes()' meth…
Browse files Browse the repository at this point in the history
…od. This allows the user to specify that MiniProfiler should try to use jQuery instance that has already been loaded on the page.
  • Loading branch information
growse committed Apr 12, 2012
1 parent a84bd71 commit cfd78da
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
6 changes: 6 additions & 0 deletions StackExchange.Profiling/MiniProfiler.Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ public static void ExcludeMethod(string methodName)
[DefaultValue(false)]
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>
/// 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.
Expand Down
9 changes: 5 additions & 4 deletions StackExchange.Profiling/MiniProfiler.cs
Original file line number Diff line number Diff line change
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="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="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>
public static IHtmlString RenderIncludes(RenderPosition? position = null, bool? showTrivial = null, bool? showTimeWithChildren = null, int? maxTracesToShow = null, bool? showControls = null, bool samplingOnly = false)
/// <param name="showControls">when true, shows buttons to minimize and clear MiniProfiler results</param>
/// <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>
/// <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>
Expand Down
13 changes: 9 additions & 4 deletions StackExchange.Profiling/UI/MiniProfilerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace StackExchange.Profiling.UI
/// </summary>
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 =
@"<script type=""text/javascript"">
Expand Down Expand Up @@ -52,8 +52,12 @@ internal static HtmlString RenderIncludes(MiniProfiler profiler, RenderPosition?
}});
}});
}};
load('{path}jquery.1.7.1.js?v={version}', initMp);
if ({useExistingjQuery}) {{
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,
showControls = showControls ?? MiniProfiler.Settings.ShowControls ? "true" : "false",
currentId = profiler.Id,
authorized = authorized ? "true" : "false"
authorized = authorized ? "true" : "false",
seExistingjQuery = useExistingjQuery ?? MiniProfiler.Settings.UseExistingjQuery ? "true" : "false"
});

}
Expand Down

0 comments on commit cfd78da

Please sign in to comment.