forked from phcode-dev/staging.phcode.dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPluginPanelView.js
More file actions
1 lines (1 loc) · 1.94 KB
/
PluginPanelView.js
File metadata and controls
1 lines (1 loc) · 1.94 KB
1
define(function(require,exports,module){const EventDispatcher=require("utils/EventDispatcher"),EVENT_PANEL_HIDDEN="panelHidden",EVENT_PANEL_SHOWN="panelShown",PANEL_TYPE_PLUGIN_PANEL="pluginPanel";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}Panel.prototype.$panel=null,Panel.prototype.isVisible=function(){return this.$panel.is(":visible")},Panel.prototype.registerCanBeShownHandler=function(canShowHandlerFn){this.canBeShownHandler&&canShowHandlerFn&&console.warn(`canBeShownHandler already registered for panel: ${this.panelID}. will be overwritten`),this.canBeShownHandler=canShowHandlerFn},Panel.prototype.canBeShown=function(){let self=this;return!self.canBeShownHandler||self.canBeShownHandler()},Panel.prototype.registerOnCloseRequestedHandler=function(handler){this._onCloseRequestedHandler&&handler&&console.warn(`onCloseRequestedHandler already registered for panel: ${this.panelID}. will be overwritten`),this._onCloseRequestedHandler=handler},Panel.prototype.requestClose=async function(){if(this._onCloseRequestedHandler){const allowed=await this._onCloseRequestedHandler();if(!allowed)return!1}return this.hide(),!0},Panel.prototype.show=function(){!this.isVisible()&&this.canBeShown()&&(this.$toolbarIcon.addClass("selected-button"),this.$panel.show(),exports.trigger("panelShown",this.panelID))},Panel.prototype.hide=function(){this.isVisible()&&(this.$toolbarIcon.removeClass("selected-button"),this.$panel.hide(),exports.trigger("panelHidden",this.panelID))},Panel.prototype.setVisible=function(visible){visible?this.show():this.hide()},Panel.prototype.getPanelType=function(){return"pluginPanel"},EventDispatcher.makeEventDispatcher(exports),exports.Panel=Panel,exports.EVENT_PANEL_HIDDEN="panelHidden",exports.EVENT_PANEL_SHOWN="panelShown",exports.PANEL_TYPE_PLUGIN_PANEL="pluginPanel"});