/* The frame is a container for a panel, and can contain multiple panels inside it, each appearing as a tabbed item. All docking panels have a frame, but the frame can change any time the panel is moved. */ function wcFrame(container, parent, isFloating) { this.$container = $(container); this._parent = parent; this._isFloating = isFloating; this.$frame = null; this.$title = null; this.$tabScroll = null; this.$center = null; this.$tabLeft = null; this.$tabRight = null; this.$close = null; this.$top = null; this.$bottom = null; this.$left = null; this.$right = null; this.$corner1 = null; this.$corner2 = null; this.$corner3 = null; this.$corner4 = null; this.$shadower = null; this.$modalBlocker = null; this._canScrollTabs = false; this._tabScrollPos = 0; this._curTab = -1; this._panelList = []; this._buttonList = []; this._resizeData = { time: -1, timeout: false, delta: 150, }; this._pos = { x: 0.5, y: 0.5, }; this._size = { x: 400, y: 400, }; this._lastSize = { x: 400, y: 400, }; this._anchorMouse = { x: 0, y: 0, }; this.__init(); }; wcFrame.prototype = { LEFT_TAB_BUFFER: 15, /////////////////////////////////////////////////////////////////////////////////////////////////////// // Public Functions /////////////////////////////////////////////////////////////////////////////////////////////////////// // Gets, or Sets the position of the frame. // Params: // x, y If supplied, assigns the new position. // pixels If true, the coordinates given will be treated as a // pixel position rather than a percentage. pos: function(x, y, pixels) { var width = this.$container.width(); var height = this.$container.height(); if (typeof x === 'undefined') { if (pixels) { return {x: this._pos.x*width, y: this._pos.y*height}; } else { return {x: this._pos.x, y: this._pos.y}; } } if (pixels) { this._pos.x = x/width; this._pos.y = y/height; } else { this._pos.x = x; this._pos.y = y; } }, // Gets the desired size of the panel. initSize: function() { var size = { x: -1, y: -1, }; for (var i = 0; i < this._panelList.length; ++i) { if (size.x < this._panelList[i].initSize().x) { size.x = this._panelList[i].initSize().x; } if (size.y < this._panelList[i].initSize().y) { size.y = this._panelList[i].initSize().y; } } if (size.x < 0 || size.y < 0) { return false; } return size; }, // Gets the minimum size of the panel. minSize: function() { var size = { x: 0, y: 0, }; for (var i = 0; i < this._panelList.length; ++i) { size.x = Math.max(size.x, this._panelList[i].minSize().x); size.y = Math.max(size.y, this._panelList[i].minSize().y); } return size; }, // Gets the minimum size of the panel. maxSize: function() { var size = { x: Infinity, y: Infinity, }; for (var i = 0; i < this._panelList.length; ++i) { size.x = Math.min(size.x, this._panelList[i].maxSize().x); size.y = Math.min(size.y, this._panelList[i].maxSize().y); } return size; }, // Adds a given panel as a new tab item. // Params: // panel The panel to add. // index An optional index to insert the tab at. addPanel: function(panel, index) { var found = this._panelList.indexOf(panel); if (found !== -1) { this._panelList.splice(found, 1); } if (typeof index === 'undefined') { this._panelList.push(panel); } else { this._panelList.splice(index, 0, panel); } if (this._curTab === -1 && this._panelList.length) { this._curTab = 0; this._size = this.initSize(); } this.__updateTabs(); }, // Removes a given panel from the tab item. // Params: // panel The panel to remove. // Returns: // bool Returns whether or not any panels still remain. removePanel: function(panel) { for (var i = 0; i < this._panelList.length; ++i) { if (this._panelList[i] === panel) { if (this._curTab >= i) { this._curTab--; } this._panelList[i].__container(null); this._panelList[i]._parent = null; this._panelList.splice(i, 1); break; } } if (this._curTab === -1 && this._panelList.length) { this._curTab = 0; } this.__updateTabs(); return this._panelList.length > 0; }, // Gets, or Sets the currently visible panel. // Params: // tabIndex If supplied, sets the current tab. // Returns: // wcPanel The currently visible panel. panel: function(tabIndex, autoFocus) { if (typeof tabIndex !== 'undefined') { if (tabIndex > -1 && tabIndex < this._panelList.length) { this.$title.find('> .wcTabScroller > .wcPanelTab[id="' + this._curTab + '"]').removeClass('wcPanelTabActive'); this.$center.children('.wcPanelTabContent[id="' + this._curTab + '"]').addClass('wcPanelTabContentHidden'); this._curTab = tabIndex; this.$title.find('> .wcTabScroller > .wcPanelTab[id="' + tabIndex + '"]').addClass('wcPanelTabActive'); this.$center.children('.wcPanelTabContent[id="' + tabIndex + '"]').removeClass('wcPanelTabContentHidden'); this.__updateTabs(autoFocus); } } if (this._curTab > -1 && this._curTab < this._panelList.length) { return this._panelList[this._curTab]; } return false; }, /////////////////////////////////////////////////////////////////////////////////////////////////////// // Private Functions /////////////////////////////////////////////////////////////////////////////////////////////////////// // Initialize __init: function() { this.$frame = $('