aboutsummaryrefslogtreecommitdiffstats
path: root/debug_toolbar/media/toolbar.js
blob: 9cbda92aeef6bd3b23985f7c813942419de62998 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
var _$ = window.$;
$j = jQuery.noConflict();
jQuery(function() {
	var COOKIE_NAME = 'dj_debug_panel';
	$j.djDebug = function(data, klass) {
		$j.djDebug.init();
	}
	$j.extend($j.djDebug, {
		init: function() {
			var current = null;
			$j('#djDebugPanelList li a').click(function() {
				current = $j('#djDebug #' + this.className);
				if (current.is(':visible')) {
					$j(document).trigger('close.djDebug');
				} else {
					$j('.panelContent').hide();
					current.show();
					$j.djDebug.open();
				}
				return false;
			});
			$j('#djDebug a.close').click(function() {
				$j(document).trigger('close.djDebug');
				return false;
			});
			$j('#djDebug a.remoteCall').click(function() {
				$j('#djDebugWindow').load(this.href, {}, function() {
					$j('#djDebugWindow a.back').click(function() {
						$j(this).parent().hide();
						return false;
					});
				});
				$j('#djDebugWindow').show();
				return false;
			});
			$j('#djDebugTemplatePanel a.djTemplateShowContext').click(function() {
				$j.djDebug.toggle_content($j(this).parent().next());
			});
			$j('#djHideToolBarButton').click(function() {
				$j.djDebug.hide_toolbar(true);
			});
			$j('#djShowToolBarButton').click(function() {
				$j.djDebug.show_toolbar();
			});
			if ($j.cookie(COOKIE_NAME)) {
				$j.djDebug.hide_toolbar(false);
			} else {
				$j('#djDebugToolbar').show();
			}
			$j(window).load($j.djDebug.format_panels);
			$j(window).resize($j.djDebug.format_panels);
		},
		open: function() {
			$j(document).bind('keydown.djDebug', function(e) {
				if (e.keyCode == 27) {
					$j.djDebug.close();
				}
			});
		},
		toggle_content: function(elem) {
			if (elem.is(':visible')) {
				elem.hide();
			} else {
				elem.show();
			}
		},
		close: function() {
			$j(document).trigger('close.djDebug');
			return false;
		},
		hide_toolbar: function(setCookie) {
			$j('#djDebugToolbar').hide("fast");
			$j('#djDebugToolbarHandle').show();
			if (setCookie) {
				$j.cookie(COOKIE_NAME, 'hide', {
					path: '/',
					expires: 10
				});
			}
		},
		show_toolbar: function() {
			$j('#djDebugToolbarHandle').hide();
			$j('#djDebugToolbar').show("fast");
			$j.cookie(COOKIE_NAME, null, {
				path: '/',
				expires: -1
			});
		},
		/* Make sure that panel layout doesn't overflow the screen
		 * width. Any panel that would otherwise wrap to the next line
		 * are pushed into a "more..." vertical display in the final
		 * panel position. */
		format_panels: function () {
			// If we've already done some overflow-avoidance, undo the
			// effect before recomputing (needed, for example, after a
			// window resize).
			$j("#djDebugMore > ul > li").appendTo("#djDebugPanelList");
			$j("#djDebugMore").remove();

			// Check for wrapping by examing the position of the last
			// element.
			var row_top = $j("#djDebugPanelList > li").position().top;
			var final_pos = $j("#djDebugPanelList > li:last").position();

			if (final_pos.top == row_top && final_pos.left != 0) {
				return;
			}

			function overflow_check(idx) {
				pos = $j(this).position();
				return pos.top > row_top || (idx > 1 && pos.left == 0);
			};

			var more = $j("<li id='djDebugMore'>More...<ul></ul></li>");
			more.prependTo("#djDebugPanelList");
			overflows = $j("#djDebugPanelList > li").filter(overflow_check);
			more.appendTo("#djDebugPanelList");
			$j("#djDebugMore > ul").append(overflows);
		}
	});
	$j(document).bind('close.djDebug', function() {
		$j(document).unbind('keydown.djDebug');
		$j('.panelContent').hide();
	});
});
jQuery(function() {
	jQuery.djDebug();
});

$ = _$;