-
-
Notifications
You must be signed in to change notification settings - Fork 204
Expand file tree
/
Copy pathPluginPanelView.js
More file actions
162 lines (144 loc) · 5.12 KB
/
Copy pathPluginPanelView.js
File metadata and controls
162 lines (144 loc) · 5.12 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
/*
* 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");
/**
* 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 plugin panel
* @type {string}
* @constant
*/
const PANEL_TYPE_PLUGIN_PANEL = 'pluginPanel';
/**
* 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.
* @param {!string} id Unique id for this panel. Use package-style naming, e.g. "myextension.panelname". will
* overwrite an existing panel id if present.
* @param {!jQueryObject} $toolbarIcon An icon that should be present in main-toolbar to associate this panel to.
* The panel will be shown only if the icon is visible on the toolbar and the user clicks on the icon.
* @param {number=} minWidth Minimum width of panel in px.
* @param {?number=} initialSize Optional Initial size of panel in px. If not given, panel will use minsize
* or current size.
*/
function Panel($panel, id, $toolbarIcon, minWidth, initialSize) {
this.$panel = $panel;
this.panelID = id;
this.$toolbarIcon = $toolbarIcon;
this.minWidth = minWidth;
this.$mainPluginPanel = $("#main-plugin-panel");
this.initialSize = initialSize;
}
/**
* 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()){
this.$toolbarIcon.addClass("selected-button");
this.$panel.show();
exports.trigger(EVENT_PANEL_SHOWN, this.panelID);
}
};
/**
* Hides the panel
*/
Panel.prototype.hide = function () {
if(this.isVisible()){
this.$toolbarIcon.removeClass("selected-button");
this.$panel.hide();
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_PLUGIN_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_PLUGIN_PANEL = PANEL_TYPE_PLUGIN_PANEL;
});