Skip to content

Commit

Permalink
adding resize ability
Browse files Browse the repository at this point in the history
fixes issue #2
  • Loading branch information
tcarlsen committed Feb 10, 2015
1 parent a5f97ac commit 9424b24
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .jslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"indent": 2,
"node": true,
"predef": {
"atom": true
"atom": true,
"document": true
}
}
40 changes: 40 additions & 0 deletions lib/MessagePanelView.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";

var
$ = require('space-pen').$,
View = require('space-pen').View,
inherits = require('./utils').inherits;

Expand All @@ -22,6 +23,10 @@ MessagePanelView.content = function () {
class: 'am-panel tool-panel panel-bottom native-key-bindings',
tabindex: '-1'
}, function () {
this.div({
class: 'panel-resize-handle',
style: 'position: absolute; top: 0; left: 0; right: 0; height: 10px; cursor: row-resize; z-index: 3'
});
this.div({
class: 'panel-heading'
}, function () {
Expand Down Expand Up @@ -63,6 +68,11 @@ MessagePanelView.content = function () {
MessagePanelView.prototype.attach = function () {
if (this.panel === undefined) {
this.panel = atom.workspace.addBottomPanel({item: this});

var that = this;
this.panel.item.on("mousedown", ".panel-resize-handle", function () {
that.resizeStarted();
});
} else {
this.panel.show();
}
Expand All @@ -73,6 +83,7 @@ MessagePanelView.prototype.close = function () {
this.panel[this.closeMethod].call(this.panel);
if (this.closeMethod === 'destroy') {
this.panel = undefined;
this.resizeStopped();
}
}
};
Expand Down Expand Up @@ -140,4 +151,33 @@ MessagePanelView.prototype.add = function (view) {
this.body.append(view);
};

MessagePanelView.prototype.resizeStarted = function () {
$(this).css({
WebkitUserSelect: 'none'
});

$(document).on('mousemove', {that: this}, this.resizePanel);
$(document).on('mouseup', {that: this}, this.resizeStopped);
};

MessagePanelView.prototype.resizeStopped = function (e) {
$(e.data.that).css({
WebkitUserSelect: ''
});

$(document).off('mousemove', this.resizePanel);
$(document).off('mouseup', this.resizeStopped);
};

MessagePanelView.prototype.resizePanel = function (e) {
var
panelBody = $(".panel-body", e.data.that),
panelHeadingHeight = $(".panel-heading", e.data.that).height(),
newHeight = $(document.body).height() - e.pageY - panelHeadingHeight - 30;

panelBody.css({
maxHeight: newHeight
});
};

module.exports = MessagePanelView;

0 comments on commit 9424b24

Please sign in to comment.