This repository was archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Expand file tree
/
Copy pathStatusBar.js
More file actions
222 lines (187 loc) · 7.4 KB
/
StatusBar.js
File metadata and controls
222 lines (187 loc) · 7.4 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, $, brackets, window, document, Mustache */
/**
* A status bar with support for file information and busy and status indicators. This is a semi-generic
* container; for the code that decides what content appears in the status bar, see client modules like
* EditorStatusBar. (Although in practice StatusBar's HTML structure and initialization
* assume it's only used for this one purpose, and all the APIs are on a singleton).
*/
define(function (require, exports, module) {
'use strict';
var AppInit = require("utils/AppInit"),
StatusBarHTML = require("text!widgets/StatusBar.html"),
EditorManager = require("editor/EditorManager"),
Strings = require("strings");
var _init = false;
// Indicates if the busy cursor is active to avoid unnecesary operations
var _busyCursor = false;
// A simple regexp to sanitize indicator ids
var _indicatorIDRegexp = new RegExp("[^a-zA-Z 0-9]+", "g");
// These vars are initialized by the AppInit.htmlReady handler
// below since they refer to DOM elements
var $editorContainer,
$statusBar,
$indicators,
$busyIndicator;
/**
* Shows the 'busy' indicator
* @param {boolean} updateCursor Sets the cursor to "wait"
*/
function showBusyIndicator(updateCursor) {
if (!_init) {
console.error("StatusBar API invoked before status bar created");
return;
}
if (updateCursor) {
_busyCursor = true;
$("*").addClass("busyCursor");
}
$busyIndicator.addClass("spin");
}
/**
* Hides the 'busy' indicator
*/
function hideBusyIndicator() {
if (!_init) {
console.error("StatusBar API invoked before status bar created");
return;
}
// Check if we are using the busyCursor class to avoid
// unnecesary calls to $('*').removeClass()
if (_busyCursor) {
_busyCursor = false;
$("*").removeClass("busyCursor");
}
$busyIndicator.removeClass("spin");
}
/**
* Registers a new status indicator
* @param {string} id Registration id of the indicator to be updated.
* @param {(DOMNode|jQueryObject)=} indicator Optional DOMNode for the indicator
* @param {boolean=} visible Shows or hides the indicator over the statusbar.
* @param {string=} style Sets the attribute "class" of the indicator.
* @param {string=} tooltip Sets the attribute "title" of the indicator.
* @param {string=} _beforeID For internal use by CodeInspection module.
*/
function addIndicator(id, indicator, visible, style, tooltip, _beforeID) {
if (!_init) {
console.error("StatusBar API invoked before status bar created");
return;
}
indicator = indicator || document.createElement("div");
tooltip = tooltip || "";
style = style || "";
id = id.replace(_indicatorIDRegexp, "-") || "";
var $indicator = $(indicator);
$indicator.attr("id", id);
$indicator.attr("title", tooltip);
$indicator.addClass("indicator");
$indicator.addClass(style);
if (!visible) {
$indicator.hide();
}
if (_beforeID) {
$indicator.insertBefore("#" + _beforeID);
} else {
// The "busy" spinner should always be leftmost
var $busyIndicator = $("#status-bar .spinner");
$indicator.insertBefore($busyIndicator);
}
}
/**
* Updates a status indicator
* @param {string} id Registration id of the indicator to be updated.
* @param {boolean} visible Shows or hides the indicator over the statusbar.
* @param {string=} style Sets the attribute "class" of the indicator.
* @param {string=} tooltip Sets the attribute "title" of the indicator.
*/
function updateIndicator(id, visible, style, tooltip) {
if (!_init) {
console.error("StatusBar API invoked before status bar created");
return;
}
var $indicator = $("#" + id.replace(_indicatorIDRegexp, "-"));
if ($indicator) {
if (visible) {
$indicator.show();
} else {
$indicator.hide();
}
if (style) {
$indicator.removeClass();
$indicator.addClass(style);
} else {
$indicator.removeClass();
$indicator.addClass("indicator");
}
if (tooltip) {
$indicator.attr("title", tooltip);
}
}
}
/**
* Hide the statusbar
*/
function hide() {
if (!_init) {
console.error("StatusBar API invoked before status bar created");
return;
}
if ($statusBar.is(":visible")) {
$statusBar.hide();
EditorManager.resizeEditor(); // changes available ht for editor area
}
}
/**
* Show the statusbar
*/
function show() {
if (!_init) {
console.error("StatusBar API invoked before status bar created");
return;
}
if (!$statusBar.is(":visible")) {
$statusBar.show();
EditorManager.resizeEditor(); // changes available ht for editor area
}
}
AppInit.htmlReady(function () {
var $parent = $(".main-view .content");
$parent.append(Mustache.render(StatusBarHTML, Strings));
// Initialize items dependent on HTML DOM
$statusBar = $("#status-bar");
$indicators = $("#status-indicators");
$busyIndicator = $("#status-bar .spinner");
_init = true;
// hide on init
hide();
});
exports.showBusyIndicator = showBusyIndicator;
exports.hideBusyIndicator = hideBusyIndicator;
exports.addIndicator = addIndicator;
exports.updateIndicator = updateIndicator;
exports.hide = hide;
exports.show = show;
});