-
-
Notifications
You must be signed in to change notification settings - Fork 205
Expand file tree
/
Copy pathPanelView.js
More file actions
151 lines (132 loc) · 4.27 KB
/
Copy pathPanelView.js
File metadata and controls
151 lines (132 loc) · 4.27 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
/*
* GNU AGPL-3.0 License
*
* Copyright (c) 2021 - present core.ai . All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License along
* with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
*
*/
// @INCLUDE_IN_API_DOCS
/*global fs, Phoenix, process*/
/*eslint no-console: 0*/
/*eslint strict: ["error", "global"]*/
/* jshint ignore:start */
define(function (require, exports, module) {
const EventDispatcher = require("utils/EventDispatcher"),
Resizer = require("utils/Resizer");
/**
* Event when panel is hidden
* @type {string}
* @constant
*/
const EVENT_PANEL_HIDDEN = 'panelHidden';
/**
* Event when panel is shown
* @type {string}
* @constant
*/
const EVENT_PANEL_SHOWN = 'panelShown';
/**
* type for bottom panel
* @type {string}
* @constant
*/
const PANEL_TYPE_BOTTOM_PANEL = 'bottomPanel';
/**
* Represents a panel below the editor area (a child of ".content").
* @constructor
* @param {!jQueryObject} $panel The entire panel, including any chrome, already in the DOM.
*/
function Panel($panel, id) {
this.$panel = $panel;
this.panelID = id;
}
/**
* Dom node holding the rendered panel
* @type {jQueryObject}
*/
Panel.prototype.$panel = null;
/**
* Determines if the panel is visible
* @return {boolean} true if visible, false if not
*/
Panel.prototype.isVisible = function () {
return this.$panel.is(":visible");
};
/**
* Registers a call back function that will be called just before panel is shown. The handler should return true
* if the panel can be shown, else return false and the panel will not be shown.
* @param {function|null} canShowHandlerFn function that should return true of false if the panel can be shown/not.
* or null to clear the handler.
* @return {boolean} true if visible, false if not
*/
Panel.prototype.registerCanBeShownHandler = function (canShowHandlerFn) {
if(this.canBeShownHandler && canShowHandlerFn){
console.warn(`canBeShownHandler already registered for panel: ${this.panelID}. will be overwritten`);
}
this.canBeShownHandler = canShowHandlerFn;
};
/**
* Returns true if th panel can be shown, else false.
* @return {boolean}
*/
Panel.prototype.canBeShown = function () {
let self = this;
if(self.canBeShownHandler){
return self.canBeShownHandler();
}
return true;
};
/**
* Shows the panel
*/
Panel.prototype.show = function () {
if(!this.isVisible() && this.canBeShown()){
Resizer.show(this.$panel[0]);
exports.trigger(EVENT_PANEL_SHOWN, this.panelID);
}
};
/**
* Hides the panel
*/
Panel.prototype.hide = function () {
if(this.isVisible()){
Resizer.hide(this.$panel[0]);
exports.trigger(EVENT_PANEL_HIDDEN, this.panelID);
}
};
/**
* Sets the panel's visibility state
* @param {boolean} visible true to show, false to hide
*/
Panel.prototype.setVisible = function (visible) {
if (visible) {
this.show();
} else {
this.hide();
}
};
/**
* gets the Panel's type
* @return {string}
*/
Panel.prototype.getPanelType = function () {
return PANEL_TYPE_BOTTOM_PANEL;
};
EventDispatcher.makeEventDispatcher(exports);
// Public API
exports.Panel = Panel;
//events
exports.EVENT_PANEL_HIDDEN = EVENT_PANEL_HIDDEN;
exports.EVENT_PANEL_SHOWN = EVENT_PANEL_SHOWN;
exports.PANEL_TYPE_BOTTOM_PANEL = PANEL_TYPE_BOTTOM_PANEL;
});