profiler.js 4.59 KB
Newer Older
1 2 3 4 5 6 7
var anbu = {

	// BOUND ELEMENTS
	// -------------------------------------------------------------
	// Binding these elements early, stops jQuery from "querying"
	// the DOM every time they are used.

8
	el: {
9 10 11 12 13 14 15 16 17 18 19 20 21 22
		main: $('.anbu'),
		close: $('#anbu-close'),
		zoom: $('#anbu-zoom'),
		hide: $('#anbu-hide'),
		show: $('#anbu-show'),
		tab_pane: $('.anbu-tab-pane'),
		hidden_tab_pane: $('.anbu-tab-pane:visible'),
		tab: $('.anbu-tab'),
		tabs: $('.anbu-tabs'),
		tab_links: $('.anbu-tabs a'),
		window: $('.anbu-window'),
		closed_tabs: $('#anbu-closed-tabs'),
		open_tabs: $('#anbu-open-tabs'),
		content_area: $('.anbu-content-area')
23 24 25 26 27 28
	},

	// CLASS ATTRIBUTES
	// -------------------------------------------------------------
	// Useful variable for Anbu.

29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
	// is anbu in full screen mode
	is_zoomed: false,

	// initial height of content area
	small_height: $('.anbu-content-area').height(),

	// the name of the active tab css
	active_tab: 'anbu-active-tab',

	// the data attribute of the tab link
	tab_data: 'data-anbu-tab',

	// size of anbu when compact
	mini_button_width: '2.6em',

	// is the top window open?
	window_open: false,

	// current active pane
	active_pane: '',
49 50 51 52 53

	// START()
	// -------------------------------------------------------------
	// Sets up all the binds for Anbu!

54
	start: function() {
55

56 57 58 59
		// hide initial elements
		anbu.el.close.css('visibility', 'visible').hide();
		anbu.el.zoom.css('visibility', 'visible').hide();
		anbu.el.tab_pane.css('visibility', 'visible').hide();
60 61

		// bind all click events
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
		anbu.el.close.click(function(event) {
			anbu.close_window();
			event.preventDefault();
		});
		anbu.el.hide.click(function(event) {
			anbu.hide();
			event.preventDefault();
		});
		anbu.el.show.click(function(event) {
			anbu.show();
			event.preventDefault();
		});
		anbu.el.zoom.click(function(event) {
			anbu.zoom();
			event.preventDefault();
		});
		anbu.el.tab.click(function(event) {
			anbu.clicked_tab($(this));
			event.preventDefault();
		});

83 84 85 86 87 88
	},

	// CLICKED_TAB()
	// -------------------------------------------------------------
	// A tab has been clicked, decide what to do.

89 90
	clicked_tab: function(tab) {

91
		// if the tab is closed
92
		if (anbu.window_open && anbu.active_pane == tab.attr(anbu.tab_data)) {
93
			anbu.close_window();
94
		} else {
95 96
			anbu.open_window(tab);
		}
97

98 99 100 101 102 103
	},

	// OPEN_WINDOW()
	// -------------------------------------------------------------
	// Animate open the top window to the appropriate tab.

104 105
	open_window: function(tab) {

106 107 108 109 110 111 112 113 114 115 116
		// can't directly assign this line, but it works
		$('.anbu-tab-pane:visible').fadeOut(200);
		$('.' + tab.attr(anbu.tab_data)).delay(220).fadeIn(300);
		anbu.el.tab_links.removeClass(anbu.active_tab);
		tab.addClass(anbu.active_tab);
		anbu.el.window.slideDown(300);
		anbu.el.close.fadeIn(300);
		anbu.el.zoom.fadeIn(300);
		anbu.active_pane = tab.attr(anbu.tab_data);
		anbu.window_open = true;

117
	},
118 119 120 121 122

	// CLOSE_WINDOW()
	// -------------------------------------------------------------
	// Animate closed the top window hiding all tabs.

123 124
	close_window: function() {

125 126 127 128 129 130 131 132
		anbu.el.tab_pane.fadeOut(100);
		anbu.el.window.slideUp(300);
		anbu.el.close.fadeOut(300);
		anbu.el.zoom.fadeOut(300);
		anbu.el.tab_links.removeClass(anbu.active_tab);
		anbu.active_pane = '';
		anbu.window_open = false;

133
	},
134 135 136 137 138

	// SHOW()
	// -------------------------------------------------------------
	// Show the Anbu toolbar when it has been compacted.

139 140 141
	show: function() {

		anbu.el.closed_tabs.fadeOut(600, function () {
142
			anbu.el.main.removeClass('anbu-hidden');
143 144 145 146
			anbu.el.open_tabs.fadeIn(200);
		});
		anbu.el.main.animate({width: '100%'}, 700);

147 148 149 150 151 152
	},

	// HIDE()
	// -------------------------------------------------------------
	// Hide the anbu toolbar, show a tiny re-open button.

153 154
	hide: function() {

155
		anbu.close_window();
156 157 158 159 160 161 162 163 164

		setTimeout(function() {
			anbu.el.window.slideUp(400, function () {
				anbu.close_window();
				anbu.el.main.addClass('anbu-hidden');
				anbu.el.open_tabs.fadeOut(200, function () {
					anbu.el.closed_tabs.fadeIn(200);
				});
				anbu.el.main.animate({width: anbu.mini_button_width}, 700);
165
			});
166
		}, 100);
167 168 169 170 171 172 173

	},

	// TOGGLEZOOM()
	// -------------------------------------------------------------
	// Toggle the zoomed mode of the top window.

174 175 176
	zoom: function() {

		if (anbu.is_zoomed) {
177
			height = anbu.small_height;
178 179
			anbu.is_zoomed = false;
		} else {
180 181
			// the 6px is padding on the top of the window
			height = ($(window).height() - anbu.el.tabs.height() - 6) + 'px';
182
			anbu.is_zoomed = true;
183 184 185 186
		}

		anbu.el.content_area.animate({height: height}, 700);

187
	}
188

189
};
190

191 192
// launch anbu on jquery dom ready
jQuery(document).ready(function() {
193
	anbu.start();
Taylor Otwell committed
194
});