Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Addition of useExistingjQuery parameter to RenderIncludes() #29

Merged
merged 2 commits into from

3 participants

@growse

Following on from http://stackoverflow.com/questions/10105231/why-does-miniprofiler-load-jquery-1-7-1-even-though-ive-already-loaded-that-on I've made some changes to RenderIncludes that now takes an optional parameter. I also added the relevant setting in the Settings file.

The javascript feels a bit hacky, but I couldn't figure out a better way of messing with the format string based on the value of a bool. You may have a much better way of doing this.

Hopefully this is useful.

peter-raven and others added some commits
@peter-raven peter-raven Fixed issues with InlineFormatter parameter replacement - more robust…
… regex and case insensitivity.
a84bd71
@growse growse Adds the 'useExistingjQuery' parameter to the 'RenderIncludes()' meth…
…od. This allows the user to specify that MiniProfiler should try to use jQuery instance that has already been loaded on the page.
cfd78da
@SamSaffron
Owner

yeah .. seems sane

@SamSaffron SamSaffron merged commit 868fd8e into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 12, 2012
  1. @peter-raven @growse

    Fixed issues with InlineFormatter parameter replacement - more robust…

    peter-raven authored growse committed
    … regex and case insensitivity.
  2. @growse

    Adds the 'useExistingjQuery' parameter to the 'RenderIncludes()' meth…

    growse authored
    …od. This allows the user to specify that MiniProfiler should try to use jQuery instance that has already been loaded on the page.
This page is out of date. Refresh to see the latest.
View
6 StackExchange.Profiling/MiniProfiler.Settings.cs
@@ -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.
View
9 StackExchange.Profiling/MiniProfiler.cs
@@ -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>
View
4 StackExchange.Profiling/SqlFormatters/InlineFormatter.cs
@@ -36,9 +36,9 @@ public string FormatSql(SqlTiming timing)
foreach(var p in timing.Parameters)
{
// 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);
- 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;
View
13 StackExchange.Profiling/UI/MiniProfilerHandler.cs
@@ -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"">
@@ -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);
+ }}
}};
@@ -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"
});
}
Something went wrong with that request. Please try again.