rack-mini-profiler 0.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rack-mini-profiler might be problematic. Click here for more details.

@@ -0,0 +1 @@
1
+ .profiler-result,.profiler-queries{color:#555;line-height:1;font-size:12px;}.profiler-result pre,.profiler-queries pre,.profiler-result code,.profiler-queries code,.profiler-result label,.profiler-queries label,.profiler-result table,.profiler-queries table,.profiler-result tbody,.profiler-queries tbody,.profiler-result thead,.profiler-queries thead,.profiler-result tfoot,.profiler-queries tfoot,.profiler-result tr,.profiler-queries tr,.profiler-result th,.profiler-queries th,.profiler-result td,.profiler-queries td{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline;background-color:transparent;overflow:visible;max-height:none;}.profiler-result table,.profiler-queries table{border-collapse:collapse;border-spacing:0;}.profiler-result a,.profiler-queries a,.profiler-result a:hover,.profiler-queries a:hover{cursor:pointer;color:#07c;}.profiler-result a,.profiler-queries a{text-decoration:none;}.profiler-result a:hover,.profiler-queries a:hover{text-decoration:underline;}.profiler-result{font-family:Helvetica,Arial,sans-serif;}.profiler-result .profiler-toggle-duration-with-children{float:right;}.profiler-result table.profiler-client-timings{margin-top:10px;}.profiler-result .profiler-label{color:#555;overflow:hidden;text-overflow:ellipsis;}.profiler-result .profiler-unit{color:#aaa;}.profiler-result .profiler-trivial{display:none;}.profiler-result .profiler-trivial td,.profiler-result .profiler-trivial td *{color:#aaa !important;}.profiler-result pre,.profiler-result code,.profiler-result .profiler-number,.profiler-result .profiler-unit{font-family:Consolas,monospace,serif;}.profiler-result .profiler-number{color:#111;}.profiler-result .profiler-info{text-align:right;}.profiler-result .profiler-info .profiler-name{float:left;}.profiler-result .profiler-info .profiler-server-time{white-space:nowrap;}.profiler-result .profiler-timings th{background-color:#fff;color:#aaa;text-align:right;}.profiler-result .profiler-timings th,.profiler-result .profiler-timings td{white-space:nowrap;}.profiler-result .profiler-timings .profiler-duration-with-children{display:none;}.profiler-result .profiler-timings .profiler-duration{font-family:Consolas,monospace,serif;color:#111;text-align:right;}.profiler-result .profiler-timings .profiler-indent{letter-spacing:4px;}.profiler-result .profiler-timings .profiler-queries-show .profiler-number,.profiler-result .profiler-timings .profiler-queries-show .profiler-unit{color:#07c;}.profiler-result .profiler-timings .profiler-queries-duration{padding-left:6px;}.profiler-result .profiler-timings .profiler-percent-in-sql{white-space:nowrap;text-align:right;}.profiler-result .profiler-timings tfoot td{padding-top:10px;text-align:right;}.profiler-result .profiler-timings tfoot td a{font-size:95%;display:inline-block;margin-left:12px;}.profiler-result .profiler-timings tfoot td a:first-child{float:left;margin-left:0px;}.profiler-result .profiler-queries{font-family:Helvetica,Arial,sans-serif;}.profiler-result .profiler-queries .profiler-stack-trace{margin-bottom:15px;}.profiler-result .profiler-queries pre{font-family:Consolas,monospace,serif;white-space:pre-wrap;}.profiler-result .profiler-queries th{background-color:#fff;border-bottom:1px solid #555;font-weight:bold;padding:15px;white-space:nowrap;}.profiler-result .profiler-queries td{padding:15px;text-align:left;background-color:#fff;}.profiler-result .profiler-queries td:last-child{padding-right:25px;}.profiler-result .profiler-queries .profiler-odd td{background-color:#e5e5e5;}.profiler-result .profiler-queries .profiler-since-start,.profiler-result .profiler-queries .profiler-duration{text-align:right;}.profiler-result .profiler-queries .profiler-info div{text-align:right;margin-bottom:5px;}.profiler-result .profiler-queries .profiler-gap-info,.profiler-result .profiler-queries .profiler-gap-info td{background-color:#ccc;}.profiler-result .profiler-queries .profiler-gap-info .profiler-unit{color:#777;}.profiler-result .profiler-queries .profiler-gap-info .profiler-info{text-align:right;}.profiler-result .profiler-queries .profiler-gap-info.profiler-trivial-gaps{display:none;}.profiler-result .profiler-queries .profiler-trivial-gap-container{text-align:center;}.profiler-result .profiler-queries .str{color:maroon;}.profiler-result .profiler-queries .kwd{color:#00008b;}.profiler-result .profiler-queries .com{color:gray;}.profiler-result .profiler-queries .typ{color:#2b91af;}.profiler-result .profiler-queries .lit{color:maroon;}.profiler-result .profiler-queries .pun{color:#000;}.profiler-result .profiler-queries .pln{color:#000;}.profiler-result .profiler-queries .tag{color:maroon;}.profiler-result .profiler-queries .atn{color:red;}.profiler-result .profiler-queries .atv{color:blue;}.profiler-result .profiler-queries .dec{color:purple;}.profiler-result .profiler-warning,.profiler-result .profiler-warning *,.profiler-result .profiler-warning .profiler-queries-show,.profiler-result .profiler-warning .profiler-queries-show .profiler-unit{color:#f00;}.profiler-result .profiler-warning:hover,.profiler-result .profiler-warning *:hover,.profiler-result .profiler-warning .profiler-queries-show:hover,.profiler-result .profiler-warning .profiler-queries-show .profiler-unit:hover{color:#f00;}.profiler-result .profiler-nuclear{color:#f00;font-weight:bold;padding-right:2px;}.profiler-result .profiler-nuclear:hover{color:#f00;}.profiler-results{z-index:2147483643;position:fixed;top:0px;}.profiler-results.profiler-left{left:0px;}.profiler-results.profiler-left.profiler-no-controls .profiler-result:last-child .profiler-button,.profiler-results.profiler-left .profiler-controls{-webkit-border-bottom-right-radius:10px;-moz-border-radius-bottomright:10px;border-bottom-right-radius:10px;}.profiler-results.profiler-left .profiler-button,.profiler-results.profiler-left .profiler-controls{border-right:1px solid #888;}.profiler-results.profiler-right{right:0px;}.profiler-results.profiler-right.profiler-no-controls .profiler-result:last-child .profiler-button,.profiler-results.profiler-right .profiler-controls{-webkit-border-bottom-left-radius:10px;-moz-border-radius-bottomleft:10px;border-bottom-left-radius:10px;}.profiler-results.profiler-right .profiler-button,.profiler-results.profiler-right .profiler-controls{border-left:1px solid #888;}.profiler-results .profiler-button,.profiler-results .profiler-controls{display:none;z-index:2147483640;border-bottom:1px solid #888;background-color:#fff;padding:4px 7px;text-align:right;cursor:pointer;}.profiler-results .profiler-button.profiler-button-active,.profiler-results .profiler-controls.profiler-button-active{background-color:maroon;}.profiler-results .profiler-button.profiler-button-active .profiler-number,.profiler-results .profiler-controls.profiler-button-active .profiler-number,.profiler-results .profiler-button.profiler-button-active .profiler-nuclear,.profiler-results .profiler-controls.profiler-button-active .profiler-nuclear{color:#fff;font-weight:bold;}.profiler-results .profiler-button.profiler-button-active .profiler-unit,.profiler-results .profiler-controls.profiler-button-active .profiler-unit{color:#fff;font-weight:normal;}.profiler-results .profiler-controls{display:block;font-size:12px;font-family:Consolas,monospace,serif;cursor:default;text-align:center;}.profiler-results .profiler-controls span{border-right:1px solid #aaa;padding-right:5px;margin-right:5px;cursor:pointer;}.profiler-results .profiler-controls span:last-child{border-right:none;}.profiler-results .profiler-popup{display:none;z-index:2147483641;position:absolute;background-color:#fff;border:1px solid #aaa;padding:5px 10px;text-align:left;line-height:18px;overflow:auto;-moz-box-shadow:0px 1px 15px #555;-webkit-box-shadow:0px 1px 15px #555;box-shadow:0px 1px 15px #555;}.profiler-results .profiler-popup .profiler-info{margin-bottom:3px;padding-bottom:2px;border-bottom:1px solid #ddd;}.profiler-results .profiler-popup .profiler-info .profiler-name{font-size:110%;font-weight:bold;}.profiler-results .profiler-popup .profiler-info .profiler-name .profiler-overall-duration{display:none;}.profiler-results .profiler-popup .profiler-info .profiler-server-time{font-size:95%;}.profiler-results .profiler-popup .profiler-timings th,.profiler-results .profiler-popup .profiler-timings td{padding-left:6px;padding-right:6px;}.profiler-results .profiler-popup .profiler-timings th{font-size:95%;padding-bottom:3px;}.profiler-results .profiler-popup .profiler-timings .profiler-label{max-width:275px;}.profiler-results .profiler-queries{display:none;z-index:2147483643;position:absolute;overflow-y:auto;overflow-x:hidden;background-color:#fff;}.profiler-results .profiler-queries th{font-size:17px;}.profiler-results.profiler-min .profiler-result{display:none;}.profiler-results.profiler-min .profiler-controls span{display:none;}.profiler-results.profiler-min .profiler-controls .profiler-min-max{border-right:none;padding:0px;margin:0px;}.profiler-queries-bg{z-index:2147483642;display:none;background:#000;opacity:0.7;position:absolute;top:0px;left:0px;min-width:100%;}.profiler-result-full .profiler-result{width:950px;margin:30px auto;}.profiler-result-full .profiler-result .profiler-button{display:none;}.profiler-result-full .profiler-result .profiler-popup .profiler-info{font-size:25px;border-bottom:1px solid #aaa;padding-bottom:3px;margin-bottom:25px;}.profiler-result-full .profiler-result .profiler-popup .profiler-info .profiler-overall-duration{padding-right:20px;font-size:80%;color:#888;}.profiler-result-full .profiler-result .profiler-popup .profiler-timings td,.profiler-result-full .profiler-result .profiler-popup .profiler-timings th{padding-left:8px;padding-right:8px;}.profiler-result-full .profiler-result .profiler-popup .profiler-timings th{padding-bottom:7px;}.profiler-result-full .profiler-result .profiler-popup .profiler-timings td{font-size:14px;padding-bottom:4px;}.profiler-result-full .profiler-result .profiler-popup .profiler-timings td:first-child{padding-left:10px;}.profiler-result-full .profiler-result .profiler-popup .profiler-timings .profiler-label{max-width:550px;}.profiler-result-full .profiler-result .profiler-queries{margin:25px 0;}.profiler-result-full .profiler-result .profiler-queries table{width:100%;}.profiler-result-full .profiler-result .profiler-queries th{font-size:16px;color:#555;line-height:20px;}.profiler-result-full .profiler-result .profiler-queries td{padding:15px 10px;text-align:left;}.profiler-result-full .profiler-result .profiler-queries .profiler-info div{text-align:right;margin-bottom:5px;}
@@ -0,0 +1,802 @@
1
+ "use strict";
2
+ var MiniProfiler = (function ($) {
3
+
4
+ var options,
5
+ container,
6
+ controls,
7
+ fetchedIds = [],
8
+ fetchingIds = [] // so we never pull down a profiler twice
9
+ ;
10
+
11
+ var hasLocalStorage = function () {
12
+ try {
13
+ return 'localStorage' in window && window['localStorage'] !== null;
14
+ } catch (e) {
15
+ return false;
16
+ }
17
+ };
18
+
19
+ var getVersionedKey = function (keyPrefix) {
20
+ return keyPrefix + '-' + options.version;
21
+ }
22
+
23
+ var save = function (keyPrefix, value) {
24
+ if (!hasLocalStorage()) { return; }
25
+
26
+ // clear old keys with this prefix, if any
27
+ for (var i = 0; i < localStorage.length; i++) {
28
+ if ((localStorage.key(i) || '').indexOf(keyPrefix) > -1) {
29
+ localStorage.removeItem(localStorage.key(i));
30
+ }
31
+ }
32
+
33
+ // save under this version
34
+ localStorage[getVersionedKey(keyPrefix)] = value;
35
+ };
36
+
37
+ var load = function (keyPrefix) {
38
+ if (!hasLocalStorage()) { return null; }
39
+
40
+ return localStorage[getVersionedKey(keyPrefix)];
41
+ };
42
+
43
+ var fetchTemplates = function (success) {
44
+ var key = 'templates',
45
+ cached = load(key);
46
+
47
+ if (cached) {
48
+ $('body').append(cached);
49
+ success();
50
+ }
51
+ else {
52
+ $.get(options.path + 'includes.tmpl?v=' + options.version, function (data) {
53
+ if (data) {
54
+ save(key, data);
55
+ $('body').append(data);
56
+ success();
57
+ }
58
+ });
59
+ }
60
+ };
61
+
62
+ var getClientPerformance = function () {
63
+ return window.performance == null ? null : window.performance;
64
+ }
65
+
66
+ var waitedForEnd = 0;
67
+ var fetchResults = function (ids) {
68
+ var clientPerformance, clientProbes, i, j, p, id, idx;
69
+
70
+ for (i = 0; i < ids.length; i++) {
71
+ id = ids[i];
72
+
73
+ clientPerformance = null;
74
+ clientProbes = null;
75
+
76
+ if (id == options.currentId) {
77
+
78
+ if (window.mPt) {
79
+ clientProbes = mPt.t;
80
+ for (j = 0; j < clientProbes.length; j++) {
81
+ clientProbes[j].d = clientProbes[j].d.getTime();
82
+ }
83
+ mPt.t = [];
84
+ }
85
+
86
+ clientPerformance = getClientPerformance();
87
+
88
+ if (clientPerformance != null) {
89
+ // ie is buggy strip out functions
90
+ var copy = { navigation: {}, timing: {} };
91
+
92
+ var timing = $.extend({}, clientPerformance.timing);
93
+
94
+ for (p in timing) {
95
+ if (timing.hasOwnProperty(p) && !$.isFunction(timing[p])) {
96
+ copy.timing[p] = timing[p];
97
+ }
98
+ }
99
+ if (clientPerformance.navigation) {
100
+ copy.navigation.redirectCount = clientPerformance.navigation.redirectCount;
101
+ }
102
+ clientPerformance = copy;
103
+ }
104
+ }
105
+
106
+ if ($.inArray(id, fetchedIds) < 0 && $.inArray(id, fetchingIds) < 0) {
107
+ idx = fetchingIds.push(id) - 1;
108
+
109
+ $.ajax({
110
+ url: options.path + 'results',
111
+ data: { id: id, clientPerformance: clientPerformance, clientProbes: clientProbes, popup: 1 },
112
+ dataType: 'json',
113
+ type: 'POST',
114
+ success: function (json) {
115
+ fetchedIds.push(id);
116
+ if (json != "hidden") {
117
+ buttonShow(json);
118
+ }
119
+ },
120
+ complete: function () {
121
+ fetchingIds.splice(idx, 1);
122
+ }
123
+ });
124
+ }
125
+ }
126
+ };
127
+
128
+ var renderTemplate = function (json) {
129
+ return $('#profilerTemplate').tmpl(json);
130
+ };
131
+
132
+ var buttonShow = function (json) {
133
+ var result = renderTemplate(json);
134
+
135
+ if (controls)
136
+ result.insertBefore(controls);
137
+ else
138
+ result.appendTo(container);
139
+
140
+ var button = result.find('.profiler-button'),
141
+ popup = result.find('.profiler-popup');
142
+
143
+ // button will appear in corner with the total profiling duration - click to show details
144
+ button.click(function () { buttonClick(button, popup); });
145
+
146
+ // small duration steps and the column with aggregate durations are hidden by default; allow toggling
147
+ toggleHidden(popup);
148
+
149
+ // lightbox in the queries
150
+ popup.find('.profiler-queries-show').click(function () { queriesShow($(this), result); });
151
+
152
+ // limit count
153
+ if (container.find('.profiler-result').length > options.maxTracesToShow)
154
+ container.find('.profiler-result').first().remove();
155
+ button.show();
156
+ };
157
+
158
+ var toggleHidden = function (popup) {
159
+ var trivial = popup.find('.profiler-toggle-trivial');
160
+ var childrenTime = popup.find('.profiler-toggle-duration-with-children');
161
+ var trivialGaps = popup.parent().find('.profiler-toggle-trivial-gaps');
162
+
163
+ var toggleIt = function (node) {
164
+ var link = $(node),
165
+ klass = "profiler-" + link.attr('class').substr('profiler-toggle-'.length),
166
+ isHidden = link.text().indexOf('show') > -1;
167
+
168
+ popup.parent().find('.' + klass).toggle(isHidden);
169
+ link.text(link.text().replace(isHidden ? 'show' : 'hide', isHidden ? 'hide' : 'show'));
170
+
171
+ popupPreventHorizontalScroll(popup);
172
+ };
173
+
174
+ childrenTime.add(trivial).add(trivialGaps).click(function () {
175
+ toggleIt(this);
176
+ });
177
+
178
+ // if option is set or all our timings are trivial, go ahead and show them
179
+ if (options.showTrivial || trivial.data('show-on-load')) {
180
+ toggleIt(trivial);
181
+ }
182
+ // if option is set, go ahead and show time with children
183
+ if (options.showChildrenTime) {
184
+ toggleIt(childrenTime);
185
+ }
186
+ };
187
+
188
+ var buttonClick = function (button, popup) {
189
+ // we're toggling this button/popup
190
+ if (popup.is(':visible')) {
191
+ popupHide(button, popup);
192
+ }
193
+ else {
194
+ var visiblePopups = container.find('.profiler-popup:visible'),
195
+ theirButtons = visiblePopups.siblings('.profiler-button');
196
+
197
+ // hide any other popups
198
+ popupHide(theirButtons, visiblePopups);
199
+
200
+ // before showing the one we clicked
201
+ popupShow(button, popup);
202
+ }
203
+ };
204
+
205
+ var popupShow = function (button, popup) {
206
+ button.addClass('profiler-button-active');
207
+
208
+ popupSetDimensions(button, popup);
209
+
210
+ popup.show();
211
+
212
+ popupPreventHorizontalScroll(popup);
213
+ };
214
+
215
+ var popupSetDimensions = function (button, popup) {
216
+ var top = button.position().top - 1, // position next to the button we clicked
217
+ windowHeight = $(window).height(),
218
+ maxHeight = windowHeight - top - 40; // make sure the popup doesn't extend below the fold
219
+
220
+ popup
221
+ .css({ 'top': top, 'max-height': maxHeight })
222
+ .css(options.renderPosition, button.outerWidth() - 3); // move left or right, based on config
223
+ };
224
+
225
+ var popupPreventHorizontalScroll = function (popup) {
226
+ var childrenHeight = 0;
227
+
228
+ popup.children().each(function () { childrenHeight += $(this).height(); });
229
+
230
+ popup.css({ 'padding-right': childrenHeight > popup.height() ? 40 : 10 });
231
+ }
232
+
233
+ var popupHide = function (button, popup) {
234
+ button.removeClass('profiler-button-active');
235
+ popup.hide();
236
+ };
237
+
238
+ var queriesShow = function (link, result) {
239
+
240
+ var px = 30,
241
+ win = $(window),
242
+ width = win.width() - 2 * px,
243
+ height = win.height() - 2 * px,
244
+ queries = result.find('.profiler-queries');
245
+
246
+ // opaque background
247
+ $('<div class="profiler-queries-bg"/>').appendTo('body').css({ 'height': $(document).height() }).show();
248
+
249
+ // center the queries and ensure long content is scrolled
250
+ queries.css({ 'top': px, 'max-height': height, 'width': width }).css(options.renderPosition, px)
251
+ .find('table').css({ 'width': width });
252
+
253
+ // have to show everything before we can get a position for the first query
254
+ queries.show();
255
+
256
+ queriesScrollIntoView(link, queries, queries);
257
+
258
+ // syntax highlighting
259
+ prettyPrint();
260
+ };
261
+
262
+ var queriesScrollIntoView = function (link, queries, whatToScroll) {
263
+ var id = link.closest('tr').attr('data-timing-id'),
264
+ cells = queries.find('tr[data-timing-id="' + id + '"] td');
265
+
266
+ // ensure they're in view
267
+ whatToScroll.scrollTop(whatToScroll.scrollTop() + cells.first().position().top - 100);
268
+
269
+ // highlight and then fade back to original bg color; do it ourselves to prevent any conflicts w/ jquery.UI or other implementations of Resig's color plugin
270
+ cells.each(function () {
271
+ var cell = $(this),
272
+ highlightHex = '#FFFFBB',
273
+ highlightRgb = getRGB(highlightHex),
274
+ originalRgb = getRGB(cell.css('background-color')),
275
+ getColorDiff = function (fx, i) {
276
+ // adapted from John Resig's color plugin: http://plugins.jquery.com/project/color
277
+ return Math.max(Math.min(parseInt((fx.pos * (originalRgb[i] - highlightRgb[i])) + highlightRgb[i]), 255), 0);
278
+ };
279
+
280
+ // we need to animate some other property to piggy-back on the step function, so I choose you, opacity!
281
+ cell.css({ 'opacity': 1, 'background-color': highlightHex })
282
+ .animate({ 'opacity': 1 }, { duration: 2000, step: function (now, fx) {
283
+ fx.elem.style['backgroundColor'] = "rgb(" + [getColorDiff(fx, 0), getColorDiff(fx, 1), getColorDiff(fx, 2)].join(",") + ")";
284
+ }
285
+ });
286
+ });
287
+ };
288
+
289
+ // Color Conversion functions from highlightFade
290
+ // By Blair Mitchelmore
291
+ // http://jquery.offput.ca/highlightFade/
292
+ // Parse strings looking for color tuples [255,255,255]
293
+ var getRGB = function (color) {
294
+ var result;
295
+
296
+ // Check if we're already dealing with an array of colors
297
+ if (color && color.constructor == Array && color.length == 3) return color;
298
+
299
+ // Look for rgb(num,num,num)
300
+ if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color)) return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];
301
+
302
+ // Look for rgb(num%,num%,num%)
303
+ if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color)) return [parseFloat(result[1]) * 2.55, parseFloat(result[2]) * 2.55, parseFloat(result[3]) * 2.55];
304
+
305
+ // Look for #a0b1c2
306
+ if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color)) return [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)];
307
+
308
+ // Look for #fff
309
+ if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color)) return [parseInt(result[1] + result[1], 16), parseInt(result[2] + result[2], 16), parseInt(result[3] + result[3], 16)];
310
+
311
+ // Look for rgba(0, 0, 0, 0) == transparent in Safari 3
312
+ if (result = /rgba\(0, 0, 0, 0\)/.exec(color)) return colors['transparent'];
313
+
314
+ return null;
315
+ };
316
+
317
+ var bindDocumentEvents = function () {
318
+ $(document).bind('click keyup', function (e) {
319
+
320
+ // this happens on every keystroke, and :visible is crazy expensive in IE <9
321
+ // and in this case, the display:none check is sufficient.
322
+ var popup = $('.profiler-popup').filter(function () { return $(this).css("display") !== "none"; });
323
+
324
+ if (!popup.length) {
325
+ return;
326
+ }
327
+
328
+ var button = popup.siblings('.profiler-button'),
329
+ queries = popup.closest('.profiler-result').find('.profiler-queries'),
330
+ bg = $('.profiler-queries-bg'),
331
+ isEscPress = e.type == 'keyup' && e.which == 27,
332
+ hidePopup = false,
333
+ hideQueries = false;
334
+
335
+ if (bg.is(':visible')) {
336
+ hideQueries = isEscPress || (e.type == 'click' && !$.contains(queries[0], e.target) && !$.contains(popup[0], e.target));
337
+ }
338
+ else if (popup.is(':visible')) {
339
+ hidePopup = isEscPress || (e.type == 'click' && !$.contains(popup[0], e.target) && !$.contains(button[0], e.target) && button[0] != e.target);
340
+ }
341
+
342
+ if (hideQueries) {
343
+ bg.remove();
344
+ queries.hide();
345
+ }
346
+
347
+ if (hidePopup) {
348
+ popupHide(button, popup);
349
+ }
350
+ });
351
+ };
352
+
353
+ var initFullView = function () {
354
+
355
+ // first, get jquery tmpl, then render and bind handlers
356
+ fetchTemplates(function () {
357
+
358
+ // profiler will be defined in the full page's head
359
+ renderTemplate(profiler).appendTo(container);
360
+
361
+ var popup = $('.profiler-popup');
362
+
363
+ toggleHidden(popup);
364
+
365
+ prettyPrint();
366
+
367
+ // since queries are already shown, just highlight and scroll when clicking a "1 sql" link
368
+ popup.find('.profiler-queries-show').click(function () {
369
+ queriesScrollIntoView($(this), $('.profiler-queries'), $(document));
370
+ });
371
+ });
372
+ };
373
+
374
+ var initControls = function (container) {
375
+ if (options.showControls) {
376
+ controls = $('<div class="profiler-controls"><span class="profiler-min-max">m</span><span class="profiler-clear">c</span></div>').appendTo(container);
377
+
378
+ $('.profiler-controls .profiler-min-max').click(function () {
379
+ container.toggleClass('profiler-min');
380
+ });
381
+
382
+ container.hover(function () {
383
+ if ($(this).hasClass('profiler-min')) {
384
+ $(this).find('.profiler-min-max').show();
385
+ }
386
+ },
387
+ function () {
388
+ if ($(this).hasClass('profiler-min')) {
389
+ $(this).find('.profiler-min-max').hide();
390
+ }
391
+ });
392
+
393
+ $('.profiler-controls .profiler-clear').click(function () {
394
+ container.find('.profiler-result').remove();
395
+ });
396
+ }
397
+ else {
398
+ container.addClass('profiler-no-controls');
399
+ }
400
+ };
401
+
402
+ var initPopupView = function () {
403
+
404
+ if (options.authorized) {
405
+ // all fetched profilings will go in here
406
+ container = $('<div class="profiler-results"/>').appendTo('body');
407
+
408
+ // MiniProfiler.RenderIncludes() sets which corner to render in - default is upper left
409
+ container.addClass("profiler-" + options.renderPosition);
410
+
411
+ //initialize the controls
412
+ initControls(container);
413
+
414
+ // we'll render results json via a jquery.tmpl - after we get the templates, we'll fetch the initial json to populate it
415
+ fetchTemplates(function () {
416
+ // get master page profiler results
417
+ fetchResults(options.ids);
418
+ });
419
+ }
420
+ else {
421
+ fetchResults(options.ids);
422
+ }
423
+
424
+ var jQueryAjaxComplete = function (e, xhr, settings) {
425
+ if (xhr) {
426
+ // should be an array of strings, e.g. ["008c4813-9bd7-443d-9376-9441ec4d6a8c","16ff377b-8b9c-4c20-a7b5-97cd9fa7eea7"]
427
+ var stringIds = xhr.getResponseHeader('X-MiniProfiler-Ids');
428
+ if (stringIds) {
429
+ var ids = typeof JSON != 'undefined' ? JSON.parse(stringIds) : eval(stringIds);
430
+ fetchResults(ids);
431
+ }
432
+ }
433
+ };
434
+
435
+ // fetch profile results for any ajax calls
436
+ if (jQuery && jQuery(document) && jQuery(document).ajaxComplete) {
437
+ jQuery(document).ajaxComplete(jQueryAjaxComplete);
438
+ }
439
+
440
+ // fetch results after ASP Ajax calls
441
+ if (typeof (Sys) != 'undefined' && typeof (Sys.WebForms) != 'undefined' && typeof (Sys.WebForms.PageRequestManager) != 'undefined') {
442
+ // Get the instance of PageRequestManager.
443
+ var PageRequestManager = Sys.WebForms.PageRequestManager.getInstance();
444
+
445
+ PageRequestManager.add_endRequest(function (sender, args) {
446
+ if (args) {
447
+ var response = args.get_response();
448
+ if (response.get_responseAvailable() && response._xmlHttpRequest != null) {
449
+ var stringIds = args.get_response().getResponseHeader('X-MiniProfiler-Ids');
450
+ if (stringIds) {
451
+ var ids = typeof JSON != 'undefined' ? JSON.parse(stringIds) : eval(stringIds);
452
+ fetchResults(ids);
453
+ }
454
+ }
455
+ }
456
+ });
457
+ }
458
+
459
+ // more Asp.Net callbacks
460
+ if (typeof (WebForm_ExecuteCallback) == "function") {
461
+ WebForm_ExecuteCallback = (function (callbackObject) {
462
+ // Store original function
463
+ var original = WebForm_ExecuteCallback;
464
+
465
+ return function (callbackObject) {
466
+ original(callbackObject);
467
+
468
+ var stringIds = callbackObject.xmlRequest.getResponseHeader('X-MiniProfiler-Ids');
469
+ if (stringIds) {
470
+ var ids = typeof JSON != 'undefined' ? JSON.parse(stringIds) : eval(stringIds);
471
+ fetchResults(ids);
472
+ }
473
+ }
474
+
475
+ })();
476
+ }
477
+
478
+ // some elements want to be hidden on certain doc events
479
+ bindDocumentEvents();
480
+ };
481
+
482
+ return {
483
+
484
+ init: function (opt) {
485
+
486
+ options = opt || {};
487
+
488
+ var doInit = function () {
489
+ // when rendering a shared, full page, this div will exist
490
+ container = $('.profiler-result-full');
491
+
492
+ if (container.length) {
493
+ if (window.location.href.indexOf("&trivial=1") > 0) {
494
+ options.showTrivial = true
495
+ }
496
+ initFullView();
497
+ }
498
+ else {
499
+ initPopupView();
500
+ }
501
+ };
502
+
503
+ // this preserves debugging
504
+ var load = function (s, f) {
505
+ var sc = document.createElement("script");
506
+ sc.async = "async";
507
+ sc.type = "text/javascript";
508
+ sc.src = s;
509
+ var done = false;
510
+ sc.onload = sc.onreadystatechange = function (_, abort) {
511
+ if (!sc.readyState || /loaded|complete/.test(sc.readyState)) {
512
+ if (!abort && !done) { done = true; f(); }
513
+ }
514
+ };
515
+ document.getElementsByTagName('head')[0].appendChild(sc);
516
+ };
517
+
518
+ if (options.authorized) {
519
+ var url = options.path + "includes.css?v=" + options.version;
520
+ if (document.createStyleSheet) {
521
+ document.createStyleSheet(url);
522
+ } else {
523
+ $('head').append($('<link rel="stylesheet" type="text/css" href="' + url + '" />'));
524
+ }
525
+
526
+ if (!$.tmpl) {
527
+ load(options.path + 'jquery.tmpl.js?v=' + options.version, doInit);
528
+ } else {
529
+ doInit();
530
+ }
531
+ }
532
+ else {
533
+ doInit();
534
+ }
535
+
536
+ },
537
+
538
+ getClientTimingByName: function (clientTiming, name) {
539
+
540
+ for (var i = 0; i < clientTiming.Timings.length; i++) {
541
+ if (clientTiming.Timings[i].Name == name) {
542
+ return clientTiming.Timings[i];
543
+ }
544
+ }
545
+ return { Name: name, Duration: "", Start: "" };
546
+ },
547
+
548
+ renderDate: function (jsonDate) { // JavaScriptSerializer sends dates as /Date(1308024322065)/
549
+ if (jsonDate) {
550
+ return (typeof jsonDate === 'string') ? new Date(parseInt(jsonDate.replace("/Date(", "").replace(")/", ""), 10)).toUTCString() : jsonDate;
551
+ }
552
+ },
553
+
554
+ renderIndent: function (depth) {
555
+ var result = '';
556
+ for (var i = 0; i < depth; i++) {
557
+ result += '&nbsp;';
558
+ }
559
+ return result;
560
+ },
561
+
562
+ renderExecuteType: function (typeId) {
563
+ // see StackExchange.Profiling.ExecuteType enum
564
+ switch (typeId) {
565
+ case 0: return 'None';
566
+ case 1: return 'NonQuery';
567
+ case 2: return 'Scalar';
568
+ case 3: return 'Reader';
569
+ }
570
+ },
571
+
572
+ shareUrl: function (id) {
573
+ return options.path + 'results?id=' + id;
574
+ },
575
+
576
+ getClientTimings: function (clientTimings) {
577
+ var list = [];
578
+ var t;
579
+
580
+ if (!clientTimings.Timings) return [];
581
+
582
+ for (var i = 0; i < clientTimings.Timings.length; i++) {
583
+ t = clientTimings.Timings[i];
584
+ var trivial = t.Name != "Dom Complete" && t.Name != "Response";
585
+ trivial = t.Duration < 2 ? trivial : false;
586
+ list.push(
587
+ {
588
+ isTrivial: trivial,
589
+ name: t.Name,
590
+ duration: t.Duration,
591
+ start: t.Start
592
+ });
593
+ }
594
+
595
+ list.sort(function (a, b) { return a.start - b.start; });
596
+ return list;
597
+ },
598
+
599
+ getSqlTimings: function (root) {
600
+ var result = [],
601
+ addToResults = function (timing) {
602
+ if (timing.SqlTimings) {
603
+ for (var i = 0, sqlTiming; i < timing.SqlTimings.length; i++) {
604
+ sqlTiming = timing.SqlTimings[i];
605
+
606
+ // HACK: add info about the parent Timing to each SqlTiming so UI can render
607
+ sqlTiming.ParentTimingName = timing.Name;
608
+ result.push(sqlTiming);
609
+ }
610
+ }
611
+
612
+ if (timing.Children) {
613
+ for (var i = 0; i < timing.Children.length; i++) {
614
+ addToResults(timing.Children[i]);
615
+ }
616
+ }
617
+ };
618
+
619
+ // start adding at the root and recurse down
620
+ addToResults(root);
621
+
622
+ var removeDuration = function (list, duration) {
623
+
624
+ var newList = [];
625
+ for (var i = 0; i < list.length; i++) {
626
+
627
+ var item = list[i];
628
+ if (duration.start > item.start) {
629
+ if (duration.start > item.finish) {
630
+ newList.push(item);
631
+ continue;
632
+ }
633
+ newList.push({ start: item.start, finish: duration.start });
634
+ }
635
+
636
+ if (duration.finish < item.finish) {
637
+ if (duration.finish < item.start) {
638
+ newList.push(item);
639
+ continue;
640
+ }
641
+ newList.push({ start: duration.finish, finish: item.finish });
642
+ }
643
+ }
644
+
645
+ return newList;
646
+ }
647
+
648
+ var processTimes = function (elem, parent) {
649
+ var duration = { start: elem.StartMilliseconds, finish: (elem.StartMilliseconds + elem.DurationMilliseconds) };
650
+ elem.richTiming = [duration];
651
+ if (parent != null) {
652
+ elem.parent = parent;
653
+ elem.parent.richTiming = removeDuration(elem.parent.richTiming, duration);
654
+ }
655
+
656
+ if (elem.Children) {
657
+ for (var i = 0; i < elem.Children.length; i++) {
658
+ processTimes(elem.Children[i], elem);
659
+ }
660
+ }
661
+ };
662
+
663
+ processTimes(root, null);
664
+
665
+ // sort results by time
666
+ result.sort(function (a, b) { return a.StartMilliseconds - b.StartMilliseconds; });
667
+
668
+ var determineOverlap = function (gap, node) {
669
+ var overlap = 0;
670
+ for (var i = 0; i < node.richTiming.length; i++) {
671
+ var current = node.richTiming[i];
672
+ if (current.start > gap.finish) {
673
+ break;
674
+ }
675
+ if (current.finish < gap.start) {
676
+ continue;
677
+ }
678
+
679
+ overlap += Math.min(gap.finish, current.finish) - Math.max(gap.start, current.start);
680
+ }
681
+ return overlap;
682
+ }
683
+
684
+ var determineGap = function (gap, node, match) {
685
+ var overlap = determineOverlap(gap, node);
686
+ if (match == null || overlap > match.duration) {
687
+ match = { name: node.Name, duration: overlap };
688
+ }
689
+ else if (match.name == node.Name) {
690
+ match.duration += overlap;
691
+ }
692
+
693
+ if (node.Children) {
694
+ for (var i = 0; i < node.Children.length; i++) {
695
+ match = determineGap(gap, node.Children[i], match);
696
+ }
697
+ }
698
+ return match;
699
+ };
700
+
701
+ var time = 0;
702
+ var prev = null;
703
+ $.each(result, function () {
704
+ this.prevGap = {
705
+ duration: (this.StartMilliseconds - time).toFixed(2),
706
+ start: time,
707
+ finish: this.StartMilliseconds
708
+ };
709
+
710
+ this.prevGap.topReason = determineGap(this.prevGap, root, null);
711
+
712
+ time = this.StartMilliseconds + this.DurationMilliseconds;
713
+ prev = this;
714
+ });
715
+
716
+
717
+ if (result.length > 0) {
718
+ var me = result[result.length - 1];
719
+ me.nextGap = {
720
+ duration: (root.DurationMilliseconds - time).toFixed(2),
721
+ start: time,
722
+ finish: root.DurationMilliseconds
723
+ };
724
+ me.nextGap.topReason = determineGap(me.nextGap, root, null);
725
+ }
726
+
727
+ return result;
728
+ },
729
+
730
+ getSqlTimingsCount: function (root) {
731
+ var result = 0,
732
+ countSql = function (timing) {
733
+ if (timing.SqlTimings) {
734
+ result += timing.SqlTimings.length;
735
+ }
736
+
737
+ if (timing.Children) {
738
+ for (var i = 0; i < timing.Children.length; i++) {
739
+ countSql(timing.Children[i]);
740
+ }
741
+ }
742
+ };
743
+ countSql(root);
744
+ return result;
745
+ },
746
+
747
+ fetchResultsExposed: function (ids) {
748
+ return fetchResults(ids);
749
+ },
750
+
751
+ formatDuration: function (duration) {
752
+ return (duration || 0).toFixed(1);
753
+ }
754
+ };
755
+ })(jQueryMP);
756
+
757
+ // prettify.js
758
+ // http://code.google.com/p/google-code-prettify/
759
+
760
+ window.PR_SHOULD_USE_CONTINUATION=true;window.PR_TAB_WIDTH=8;window.PR_normalizedHtml=window.PR=window.prettyPrintOne=window.prettyPrint=void 0;window._pr_isIE6=function(){var y=navigator&&navigator.userAgent&&navigator.userAgent.match(/\bMSIE ([678])\./);y=y?+y[1]:false;window._pr_isIE6=function(){return y};return y};
761
+ (function(){function y(b){return b.replace(L,"&amp;").replace(M,"&lt;").replace(N,"&gt;")}function H(b,f,i){switch(b.nodeType){case 1:var o=b.tagName.toLowerCase();f.push("<",o);var l=b.attributes,n=l.length;if(n){if(i){for(var r=[],j=n;--j>=0;)r[j]=l[j];r.sort(function(q,m){return q.name<m.name?-1:q.name===m.name?0:1});l=r}for(j=0;j<n;++j){r=l[j];r.specified&&f.push(" ",r.name.toLowerCase(),'="',r.value.replace(L,"&amp;").replace(M,"&lt;").replace(N,"&gt;").replace(X,"&quot;"),'"')}}f.push(">");
762
+ for(l=b.firstChild;l;l=l.nextSibling)H(l,f,i);if(b.firstChild||!/^(?:br|link|img)$/.test(o))f.push("</",o,">");break;case 3:case 4:f.push(y(b.nodeValue));break}}function O(b){function f(c){if(c.charAt(0)!=="\\")return c.charCodeAt(0);switch(c.charAt(1)){case "b":return 8;case "t":return 9;case "n":return 10;case "v":return 11;case "f":return 12;case "r":return 13;case "u":case "x":return parseInt(c.substring(2),16)||c.charCodeAt(1);case "0":case "1":case "2":case "3":case "4":case "5":case "6":case "7":return parseInt(c.substring(1),
763
+ 8);default:return c.charCodeAt(1)}}function i(c){if(c<32)return(c<16?"\\x0":"\\x")+c.toString(16);c=String.fromCharCode(c);if(c==="\\"||c==="-"||c==="["||c==="]")c="\\"+c;return c}function o(c){var d=c.substring(1,c.length-1).match(RegExp("\\\\u[0-9A-Fa-f]{4}|\\\\x[0-9A-Fa-f]{2}|\\\\[0-3][0-7]{0,2}|\\\\[0-7]{1,2}|\\\\[\\s\\S]|-|[^-\\\\]","g"));c=[];for(var a=[],k=d[0]==="^",e=k?1:0,h=d.length;e<h;++e){var g=d[e];switch(g){case "\\B":case "\\b":case "\\D":case "\\d":case "\\S":case "\\s":case "\\W":case "\\w":c.push(g);
764
+ continue}g=f(g);var s;if(e+2<h&&"-"===d[e+1]){s=f(d[e+2]);e+=2}else s=g;a.push([g,s]);if(!(s<65||g>122)){s<65||g>90||a.push([Math.max(65,g)|32,Math.min(s,90)|32]);s<97||g>122||a.push([Math.max(97,g)&-33,Math.min(s,122)&-33])}}a.sort(function(v,w){return v[0]-w[0]||w[1]-v[1]});d=[];g=[NaN,NaN];for(e=0;e<a.length;++e){h=a[e];if(h[0]<=g[1]+1)g[1]=Math.max(g[1],h[1]);else d.push(g=h)}a=["["];k&&a.push("^");a.push.apply(a,c);for(e=0;e<d.length;++e){h=d[e];a.push(i(h[0]));if(h[1]>h[0]){h[1]+1>h[0]&&a.push("-");
765
+ a.push(i(h[1]))}}a.push("]");return a.join("")}function l(c){for(var d=c.source.match(RegExp("(?:\\[(?:[^\\x5C\\x5D]|\\\\[\\s\\S])*\\]|\\\\u[A-Fa-f0-9]{4}|\\\\x[A-Fa-f0-9]{2}|\\\\[0-9]+|\\\\[^ux0-9]|\\(\\?[:!=]|[\\(\\)\\^]|[^\\x5B\\x5C\\(\\)\\^]+)","g")),a=d.length,k=[],e=0,h=0;e<a;++e){var g=d[e];if(g==="(")++h;else if("\\"===g.charAt(0))if((g=+g.substring(1))&&g<=h)k[g]=-1}for(e=1;e<k.length;++e)if(-1===k[e])k[e]=++n;for(h=e=0;e<a;++e){g=d[e];if(g==="("){++h;if(k[h]===undefined)d[e]="(?:"}else if("\\"===
766
+ g.charAt(0))if((g=+g.substring(1))&&g<=h)d[e]="\\"+k[h]}for(h=e=0;e<a;++e)if("^"===d[e]&&"^"!==d[e+1])d[e]="";if(c.ignoreCase&&r)for(e=0;e<a;++e){g=d[e];c=g.charAt(0);if(g.length>=2&&c==="[")d[e]=o(g);else if(c!=="\\")d[e]=g.replace(/[a-zA-Z]/g,function(s){s=s.charCodeAt(0);return"["+String.fromCharCode(s&-33,s|32)+"]"})}return d.join("")}for(var n=0,r=false,j=false,q=0,m=b.length;q<m;++q){var t=b[q];if(t.ignoreCase)j=true;else if(/[a-z]/i.test(t.source.replace(/\\u[0-9a-f]{4}|\\x[0-9a-f]{2}|\\[^ux]/gi,
767
+ ""))){r=true;j=false;break}}var p=[];q=0;for(m=b.length;q<m;++q){t=b[q];if(t.global||t.multiline)throw Error(""+t);p.push("(?:"+l(t)+")")}return RegExp(p.join("|"),j?"gi":"g")}function Y(b){var f=0;return function(i){for(var o=null,l=0,n=0,r=i.length;n<r;++n)switch(i.charAt(n)){case "\t":o||(o=[]);o.push(i.substring(l,n));l=b-f%b;for(f+=l;l>=0;l-=16)o.push(" ".substring(0,l));l=n+1;break;case "\n":f=0;break;default:++f}if(!o)return i;o.push(i.substring(l));return o.join("")}}function I(b,
768
+ f,i,o){if(f){b={source:f,c:b};i(b);o.push.apply(o,b.d)}}function B(b,f){var i={},o;(function(){for(var r=b.concat(f),j=[],q={},m=0,t=r.length;m<t;++m){var p=r[m],c=p[3];if(c)for(var d=c.length;--d>=0;)i[c.charAt(d)]=p;p=p[1];c=""+p;if(!q.hasOwnProperty(c)){j.push(p);q[c]=null}}j.push(/[\0-\uffff]/);o=O(j)})();var l=f.length;function n(r){for(var j=r.c,q=[j,z],m=0,t=r.source.match(o)||[],p={},c=0,d=t.length;c<d;++c){var a=t[c],k=p[a],e=void 0,h;if(typeof k==="string")h=false;else{var g=i[a.charAt(0)];
769
+ if(g){e=a.match(g[1]);k=g[0]}else{for(h=0;h<l;++h){g=f[h];if(e=a.match(g[1])){k=g[0];break}}e||(k=z)}if((h=k.length>=5&&"lang-"===k.substring(0,5))&&!(e&&typeof e[1]==="string")){h=false;k=P}h||(p[a]=k)}g=m;m+=a.length;if(h){h=e[1];var s=a.indexOf(h),v=s+h.length;if(e[2]){v=a.length-e[2].length;s=v-h.length}k=k.substring(5);I(j+g,a.substring(0,s),n,q);I(j+g+s,h,Q(k,h),q);I(j+g+v,a.substring(v),n,q)}else q.push(j+g,k)}r.d=q}return n}function x(b){var f=[],i=[];if(b.tripleQuotedStrings)f.push([A,/^(?:\'\'\'(?:[^\'\\]|\\[\s\S]|\'{1,2}(?=[^\']))*(?:\'\'\'|$)|\"\"\"(?:[^\"\\]|\\[\s\S]|\"{1,2}(?=[^\"]))*(?:\"\"\"|$)|\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$))/,
770
+ null,"'\""]);else b.multiLineStrings?f.push([A,/^(?:\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$)|\`(?:[^\\\`]|\\[\s\S])*(?:\`|$))/,null,"'\"`"]):f.push([A,/^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$)|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/,null,"\"'"]);b.verbatimStrings&&i.push([A,/^@\"(?:[^\"]|\"\")*(?:\"|$)/,null]);if(b.hashComments)if(b.cStyleComments){f.push([C,/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\r\n]*)/,null,"#"]);i.push([A,/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,
771
+ null])}else f.push([C,/^#[^\r\n]*/,null,"#"]);if(b.cStyleComments){i.push([C,/^\/\/[^\r\n]*/,null]);i.push([C,/^\/\*[\s\S]*?(?:\*\/|$)/,null])}b.regexLiterals&&i.push(["lang-regex",RegExp("^"+Z+"(/(?=[^/*])(?:[^/\\x5B\\x5C]|\\x5C[\\s\\S]|\\x5B(?:[^\\x5C\\x5D]|\\x5C[\\s\\S])*(?:\\x5D|$))+/)")]);b=b.keywords.replace(/^\s+|\s+$/g,"");b.length&&i.push([R,RegExp("^(?:"+b.replace(/\s+/g,"|")+")\\b"),null]);f.push([z,/^\s+/,null," \r\n\t\u00a0"]);i.push([J,/^@[a-z_$][a-z_$@0-9]*/i,null],[S,/^@?[A-Z]+[a-z][A-Za-z_$@0-9]*/,
772
+ null],[z,/^[a-z_$][a-z_$@0-9]*/i,null],[J,/^(?:0x[a-f0-9]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+\-]?\d+)?)[a-z]*/i,null,"0123456789"],[E,/^.[^\s\w\.$@\'\"\`\/\#]*/,null]);return B(f,i)}function $(b){function f(D){if(D>r){if(j&&j!==q){n.push("</span>");j=null}if(!j&&q){j=q;n.push('<span class="',j,'">')}var T=y(p(i.substring(r,D))).replace(e?d:c,"$1&#160;");e=k.test(T);n.push(T.replace(a,s));r=D}}var i=b.source,o=b.g,l=b.d,n=[],r=0,j=null,q=null,m=0,t=0,p=Y(window.PR_TAB_WIDTH),c=/([\r\n ]) /g,
773
+ d=/(^| ) /gm,a=/\r\n?|\n/g,k=/[ \r\n]$/,e=true,h=window._pr_isIE6();h=h?b.b.tagName==="PRE"?h===6?"&#160;\r\n":h===7?"&#160;<br>\r":"&#160;\r":"&#160;<br />":"<br />";var g=b.b.className.match(/\blinenums\b(?::(\d+))?/),s;if(g){for(var v=[],w=0;w<10;++w)v[w]=h+'</li><li class="L'+w+'">';var F=g[1]&&g[1].length?g[1]-1:0;n.push('<ol class="linenums"><li class="L',F%10,'"');F&&n.push(' value="',F+1,'"');n.push(">");s=function(){var D=v[++F%10];return j?"</span>"+D+'<span class="'+j+'">':D}}else s=h;
774
+ for(;;)if(m<o.length?t<l.length?o[m]<=l[t]:true:false){f(o[m]);if(j){n.push("</span>");j=null}n.push(o[m+1]);m+=2}else if(t<l.length){f(l[t]);q=l[t+1];t+=2}else break;f(i.length);j&&n.push("</span>");g&&n.push("</li></ol>");b.a=n.join("")}function u(b,f){for(var i=f.length;--i>=0;){var o=f[i];if(G.hasOwnProperty(o))"console"in window&&console.warn("cannot override language handler %s",o);else G[o]=b}}function Q(b,f){b&&G.hasOwnProperty(b)||(b=/^\s*</.test(f)?"default-markup":"default-code");return G[b]}
775
+ function U(b){var f=b.f,i=b.e;b.a=f;try{var o,l=f.match(aa);f=[];var n=0,r=[];if(l)for(var j=0,q=l.length;j<q;++j){var m=l[j];if(m.length>1&&m.charAt(0)==="<"){if(!ba.test(m))if(ca.test(m)){f.push(m.substring(9,m.length-3));n+=m.length-12}else if(da.test(m)){f.push("\n");++n}else if(m.indexOf(V)>=0&&m.replace(/\s(\w+)\s*=\s*(?:\"([^\"]*)\"|'([^\']*)'|(\S+))/g,' $1="$2$3$4"').match(/[cC][lL][aA][sS][sS]=\"[^\"]*\bnocode\b/)){var t=m.match(W)[2],p=1,c;c=j+1;a:for(;c<q;++c){var d=l[c].match(W);if(d&&
776
+ d[2]===t)if(d[1]==="/"){if(--p===0)break a}else++p}if(c<q){r.push(n,l.slice(j,c+1).join(""));j=c}else r.push(n,m)}else r.push(n,m)}else{var a;p=m;var k=p.indexOf("&");if(k<0)a=p;else{for(--k;(k=p.indexOf("&#",k+1))>=0;){var e=p.indexOf(";",k);if(e>=0){var h=p.substring(k+3,e),g=10;if(h&&h.charAt(0)==="x"){h=h.substring(1);g=16}var s=parseInt(h,g);isNaN(s)||(p=p.substring(0,k)+String.fromCharCode(s)+p.substring(e+1))}}a=p.replace(ea,"<").replace(fa,">").replace(ga,"'").replace(ha,'"').replace(ia," ").replace(ja,
777
+ "&")}f.push(a);n+=a.length}}o={source:f.join(""),h:r};var v=o.source;b.source=v;b.c=0;b.g=o.h;Q(i,v)(b);$(b)}catch(w){if("console"in window)console.log(w&&w.stack?w.stack:w)}}var A="str",R="kwd",C="com",S="typ",J="lit",E="pun",z="pln",P="src",V="nocode",Z=function(){for(var b=["!","!=","!==","#","%","%=","&","&&","&&=","&=","(","*","*=","+=",",","-=","->","/","/=",":","::",";","<","<<","<<=","<=","=","==","===",">",">=",">>",">>=",">>>",">>>=","?","@","[","^","^=","^^","^^=","{","|","|=","||","||=",
778
+ "~","break","case","continue","delete","do","else","finally","instanceof","return","throw","try","typeof"],f="(?:^^|[+-]",i=0;i<b.length;++i)f+="|"+b[i].replace(/([^=<>:&a-z])/g,"\\$1");f+=")\\s*";return f}(),L=/&/g,M=/</g,N=/>/g,X=/\"/g,ea=/&lt;/g,fa=/&gt;/g,ga=/&apos;/g,ha=/&quot;/g,ja=/&amp;/g,ia=/&nbsp;/g,ka=/[\r\n]/g,K=null,aa=RegExp("[^<]+|<!--[\\s\\S]*?--\>|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>|</?[a-zA-Z](?:[^>\"']|'[^']*'|\"[^\"]*\")*>|<","g"),ba=/^<\!--/,ca=/^<!\[CDATA\[/,da=/^<br\b/i,W=/^<(\/?)([a-zA-Z][a-zA-Z0-9]*)/,
779
+ la=x({keywords:"break continue do else for if return while auto case char const default double enum extern float goto int long register short signed sizeof static struct switch typedef union unsigned void volatile catch class delete false import new operator private protected public this throw true try typeof alignof align_union asm axiom bool concept concept_map const_cast constexpr decltype dynamic_cast explicit export friend inline late_check mutable namespace nullptr reinterpret_cast static_assert static_cast template typeid typename using virtual wchar_t where break continue do else for if return while auto case char const default double enum extern float goto int long register short signed sizeof static struct switch typedef union unsigned void volatile catch class delete false import new operator private protected public this throw true try typeof abstract boolean byte extends final finally implements import instanceof null native package strictfp super synchronized throws transient as base by checked decimal delegate descending event fixed foreach from group implicit in interface internal into is lock object out override orderby params partial readonly ref sbyte sealed stackalloc string select uint ulong unchecked unsafe ushort var break continue do else for if return while auto case char const default double enum extern float goto int long register short signed sizeof static struct switch typedef union unsigned void volatile catch class delete false import new operator private protected public this throw true try typeof debugger eval export function get null set undefined var with Infinity NaN caller delete die do dump elsif eval exit foreach for goto if import last local my next no our print package redo require sub undef unless until use wantarray while BEGIN END break continue do else for if return while and as assert class def del elif except exec finally from global import in is lambda nonlocal not or pass print raise try with yield False True None break continue do else for if return while alias and begin case class def defined elsif end ensure false in module next nil not or redo rescue retry self super then true undef unless until when yield BEGIN END break continue do else for if return while case done elif esac eval fi function in local set then until ",
780
+ hashComments:true,cStyleComments:true,multiLineStrings:true,regexLiterals:true}),G={};u(la,["default-code"]);u(B([],[[z,/^[^<?]+/],["dec",/^<!\w[^>]*(?:>|$)/],[C,/^<\!--[\s\S]*?(?:-\->|$)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],[E,/^(?:<[%?]|[%?]>)/],["lang-",/^<xmp\b[^>]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-js",/^<script\b[^>]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^<style\b[^>]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),["default-markup",
781
+ "htm","html","mxml","xhtml","xml","xsl"]);u(B([[z,/^[\s]+/,null," \t\r\n"],["atv",/^(?:\"[^\"]*\"?|\'[^\']*\'?)/,null,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w.:-]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^>\'\"\s]*(?:[^>\'\"\s\/]|\/(?=\s)))/],[E,/^[=<>\/]+/],["lang-js",/^on\w+\s*=\s*\"([^\"]+)\"/i],["lang-js",/^on\w+\s*=\s*\'([^\']+)\'/i],["lang-js",/^on\w+\s*=\s*([^\"\'>\s]+)/i],["lang-css",/^style\s*=\s*\"([^\"]+)\"/i],["lang-css",/^style\s*=\s*\'([^\']+)\'/i],
782
+ ["lang-css",/^style\s*=\s*([^\"\'>\s]+)/i]]),["in.tag"]);u(B([],[["atv",/^[\s\S]+/]]),["uq.val"]);u(x({keywords:"break continue do else for if return while auto case char const default double enum extern float goto int long register short signed sizeof static struct switch typedef union unsigned void volatile catch class delete false import new operator private protected public this throw true try typeof alignof align_union asm axiom bool concept concept_map const_cast constexpr decltype dynamic_cast explicit export friend inline late_check mutable namespace nullptr reinterpret_cast static_assert static_cast template typeid typename using virtual wchar_t where ",
783
+ hashComments:true,cStyleComments:true}),["c","cc","cpp","cxx","cyc","m"]);u(x({keywords:"null true false"}),["json"]);u(x({keywords:"break continue do else for if return while auto case char const default double enum extern float goto int long register short signed sizeof static struct switch typedef union unsigned void volatile catch class delete false import new operator private protected public this throw true try typeof abstract boolean byte extends final finally implements import instanceof null native package strictfp super synchronized throws transient as base by checked decimal delegate descending event fixed foreach from group implicit in interface internal into is lock object out override orderby params partial readonly ref sbyte sealed stackalloc string select uint ulong unchecked unsafe ushort var ",
784
+ hashComments:true,cStyleComments:true,verbatimStrings:true}),["cs"]);u(x({keywords:"break continue do else for if return while auto case char const default double enum extern float goto int long register short signed sizeof static struct switch typedef union unsigned void volatile catch class delete false import new operator private protected public this throw true try typeof abstract boolean byte extends final finally implements import instanceof null native package strictfp super synchronized throws transient ",
785
+ cStyleComments:true}),["java"]);u(x({keywords:"break continue do else for if return while case done elif esac eval fi function in local set then until ",hashComments:true,multiLineStrings:true}),["bsh","csh","sh"]);u(x({keywords:"break continue do else for if return while and as assert class def del elif except exec finally from global import in is lambda nonlocal not or pass print raise try with yield False True None ",hashComments:true,multiLineStrings:true,tripleQuotedStrings:true}),["cv","py"]);
786
+ u(x({keywords:"caller delete die do dump elsif eval exit foreach for goto if import last local my next no our print package redo require sub undef unless until use wantarray while BEGIN END ",hashComments:true,multiLineStrings:true,regexLiterals:true}),["perl","pl","pm"]);u(x({keywords:"break continue do else for if return while alias and begin case class def defined elsif end ensure false in module next nil not or redo rescue retry self super then true undef unless until when yield BEGIN END ",hashComments:true,
787
+ multiLineStrings:true,regexLiterals:true}),["rb"]);u(x({keywords:"break continue do else for if return while auto case char const default double enum extern float goto int long register short signed sizeof static struct switch typedef union unsigned void volatile catch class delete false import new operator private protected public this throw true try typeof debugger eval export function get null set undefined var with Infinity NaN ",cStyleComments:true,regexLiterals:true}),["js"]);u(B([],[[A,/^[\s\S]+/]]),
788
+ ["regex"]);window.PR_normalizedHtml=H;window.prettyPrintOne=function(b,f){var i={f:b,e:f};U(i);return i.a};window.prettyPrint=function(b){function f(){for(var t=window.PR_SHOULD_USE_CONTINUATION?j.now()+250:Infinity;q<o.length&&j.now()<t;q++){var p=o[q];if(p.className&&p.className.indexOf("prettyprint")>=0){var c=p.className.match(/\blang-(\w+)\b/);if(c)c=c[1];for(var d=false,a=p.parentNode;a;a=a.parentNode)if((a.tagName==="pre"||a.tagName==="code"||a.tagName==="xmp")&&a.className&&a.className.indexOf("prettyprint")>=
789
+ 0){d=true;break}if(!d){a=p;if(null===K){d=document.createElement("PRE");d.appendChild(document.createTextNode('<!DOCTYPE foo PUBLIC "foo bar">\n<foo />'));K=!/</.test(d.innerHTML)}if(K){d=a.innerHTML;if("XMP"===a.tagName)d=y(d);else{a=a;if("PRE"===a.tagName)a=true;else if(ka.test(d)){var k="";if(a.currentStyle)k=a.currentStyle.whiteSpace;else if(window.getComputedStyle)k=window.getComputedStyle(a,null).whiteSpace;a=!k||k==="pre"}else a=true;a||(d=d.replace(/(<br\s*\/?>)[\r\n]+/g,"$1").replace(/(?:[\r\n]+[ \t]*)+/g,
790
+ " "))}d=d}else{d=[];for(a=a.firstChild;a;a=a.nextSibling)H(a,d);d=d.join("")}d=d.replace(/(?:\r\n?|\n)$/,"");m={f:d,e:c,b:p};U(m);if(p=m.a){c=m.b;if("XMP"===c.tagName){d=document.createElement("PRE");for(a=0;a<c.attributes.length;++a){k=c.attributes[a];if(k.specified)if(k.name.toLowerCase()==="class")d.className=k.value;else d.setAttribute(k.name,k.value)}d.innerHTML=p;c.parentNode.replaceChild(d,c)}else c.innerHTML=p}}}}if(q<o.length)setTimeout(f,250);else b&&b()}for(var i=[document.getElementsByTagName("pre"),
791
+ document.getElementsByTagName("code"),document.getElementsByTagName("xmp")],o=[],l=0;l<i.length;++l)for(var n=0,r=i[l].length;n<r;++n)o.push(i[l][n]);i=null;var j=Date;j.now||(j={now:function(){return(new Date).getTime()}});var q=0,m;f()};window.PR={combinePrefixPatterns:O,createSimpleLexer:B,registerLangHandler:u,sourceDecorator:x,PR_ATTRIB_NAME:"atn",PR_ATTRIB_VALUE:"atv",PR_COMMENT:C,PR_DECLARATION:"dec",PR_KEYWORD:R,PR_LITERAL:J,PR_NOCODE:V,PR_PLAIN:z,PR_PUNCTUATION:E,PR_SOURCE:P,PR_STRING:A,
792
+ PR_TAG:"tag",PR_TYPE:S}})()
793
+
794
+ ;
795
+
796
+ // lang-sql.js
797
+ // http://code.google.com/p/google-code-prettify/
798
+
799
+ PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\r \xA0]+/,null,"\t\n\r \u00a0"],["str",/^(?:"(?:[^\"\\]|\\.)*"|'(?:[^\'\\]|\\.)*')/,null,"\"'"]],[["com",/^(?:--[^\r\n]*|\/\*[\s\S]*?(?:\*\/|$))/],["kwd",/^(?:ADD|ALL|ALTER|AND|ANY|AS|ASC|AUTHORIZATION|BACKUP|BEGIN|BETWEEN|BREAK|BROWSE|BULK|BY|CASCADE|CASE|CHECK|CHECKPOINT|CLOSE|CLUSTERED|COALESCE|COLLATE|COLUMN|COMMIT|COMPUTE|CONSTRAINT|CONTAINS|CONTAINSTABLE|CONTINUE|CONVERT|CREATE|CROSS|CURRENT|CURRENT_DATE|CURRENT_TIME|CURRENT_TIMESTAMP|CURRENT_USER|CURSOR|DATABASE|DBCC|DEALLOCATE|DECLARE|DEFAULT|DELETE|DENY|DESC|DISK|DISTINCT|DISTRIBUTED|DOUBLE|DROP|DUMMY|DUMP|ELSE|END|ERRLVL|ESCAPE|EXCEPT|EXEC|EXECUTE|EXISTS|EXIT|FETCH|FILE|FILLFACTOR|FOR|FOREIGN|FREETEXT|FREETEXTTABLE|FROM|FULL|FUNCTION|GOTO|GRANT|GROUP|HAVING|HOLDLOCK|IDENTITY|IDENTITYCOL|IDENTITY_INSERT|IF|IN|INDEX|INNER|INSERT|INTERSECT|INTO|IS|JOIN|KEY|KILL|LEFT|LIKE|LINENO|LOAD|NATIONAL|NOCHECK|NONCLUSTERED|NOT|NULL|NULLIF|OF|OFF|OFFSETS|ON|OPEN|OPENDATASOURCE|OPENQUERY|OPENROWSET|OPENXML|OPTION|OR|ORDER|OUTER|OVER|PERCENT|PLAN|PRECISION|PRIMARY|PRINT|PROC|PROCEDURE|PUBLIC|RAISERROR|READ|READTEXT|RECONFIGURE|REFERENCES|REPLICATION|RESTORE|RESTRICT|RETURN|REVOKE|RIGHT|ROLLBACK|ROWCOUNT|ROWGUIDCOL|RULE|SAVE|SCHEMA|SELECT|SESSION_USER|SET|SETUSER|SHUTDOWN|SOME|STATISTICS|SYSTEM_USER|TABLE|TEXTSIZE|THEN|TO|TOP|TRAN|TRANSACTION|TRIGGER|TRUNCATE|TSEQUAL|UNION|UNIQUE|UPDATE|UPDATETEXT|USE|USER|VALUES|VARYING|VIEW|WAITFOR|WHEN|WHERE|WHILE|WITH|WRITETEXT)(?=[^\w-]|$)/i,
800
+ null],["lit",/^[+-]?(?:0x[\da-f]+|(?:(?:\.\d+|\d+(?:\.\d*)?)(?:e[+\-]?\d+)?))/i],["pln",/^[a-z_][\w-]*/i],["pun",/^[^\w\t\n\r \xA0\"\'][^\w\t\n\r \xA0+\-\"\']*/]]),["sql"])
801
+
802
+ ;