Skip to content

Commit

Permalink
Add support for auto resize.
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-wu committed Jun 26, 2019
1 parent 88b1d9b commit 199b008
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 56 deletions.
79 changes: 62 additions & 17 deletions src/ui/BaseDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ var dat = require("./dat.gui.js");
require("../styles/dat-gui-swec.css");
require("../styles/jquery-ui.theme.min.css");
require("../styles/dialog.css");
var ResizeSensor = require('css-element-queries/src/ResizeSensor');

var BaseDialog = function() {
this.container = undefined;
var BaseDialog = function(parent, options) {
this.parent = parent;
this.containment = parent;
this.module = undefined;
this.parent = undefined;
this.containment = undefined;
this.content = undefined;
this.datGui = undefined;
this.UIIsReady = false;
Expand All @@ -23,6 +23,10 @@ var BaseDialog = function() {
this.resizeStopCallbacks = [];
this.snackbar = undefined;
this.title = "Default";
this.autoResize = false;
this.sensor = undefined;
this.isDocked = false;
this.processOptions(options);
}

BaseDialog.prototype.getModule = function() {
Expand Down Expand Up @@ -78,9 +82,14 @@ BaseDialog.prototype.dock = function() {
containment: this.containment,
disabled: true
});
this.setPosition(0 , 0);
this.setWidth("100%");
this.setHeight("100%");
this.setPosition(0 , 0);
this.sensor = undefined;
this.setAutoResize(false);
this.setAutoResize(true);
this.hideCloseButton();
this.isDocked = true;
}

BaseDialog.prototype.dockToContainment = function(containment) {
Expand All @@ -89,15 +98,19 @@ BaseDialog.prototype.dockToContainment = function(containment) {
}

BaseDialog.prototype.undock = function() {
this.containment = this.parent;
this.container.parent().draggable({
containment: this.containment,
disabled: false
});
this.container.parent().resizable({
containment: this.containment,
disabled: false
});
if (this.isDocked == true) {
this.containment = this.parent;
this.container.parent().draggable({
containment: this.containment,
disabled: false
});
this.container.parent().resizable({
containment: this.containment,
disabled: false
});
this.setAutoResize(false);
this.isDocked = false;
}
}

BaseDialog.prototype.getContainment = function() {
Expand Down Expand Up @@ -172,7 +185,7 @@ BaseDialog.prototype.create = function(htmlData) {
});

//this is a docked widget if the containment and parent are not the same
if (this.containment != this.parent) {
if ((this.containment != this.parent) || this.isDocked) {
this.dock();
}

Expand Down Expand Up @@ -296,9 +309,9 @@ BaseDialog.prototype.setPosition = function(leftIn, topIn) {
};

BaseDialog.prototype.showCloseButton = function() {
this.container.dialog("option",
this.container.dialog("option",
"classes.ui-dialog-titlebar-close", "displayBlock");
}
}


BaseDialog.prototype.hideCloseButton = function() {
Expand Down Expand Up @@ -326,4 +339,36 @@ BaseDialog.prototype.setTop = function(topIn) {
this.container[0].parentNode.style.top = topIn;
};

BaseDialog.prototype.maximiseCallback = function(dialogInstance) {
return function() {
dialogInstance.setPosition(0, 0);
dialogInstance.setWidth("100%");
dialogInstance.setHeight("100%");
}
}

BaseDialog.prototype.setAutoResize = function(flag) {
if (flag != this.autoResize) {
if (flag == true) {
this.sensor = new ResizeSensor(this.containment, this.maximiseCallback(this));
this.autoResize = true;
} else if (flag == false){
this.sensor = undefined;
this.autoResize = false;
} else {
return false;
}
}
return true;
}

BaseDialog.prototype.processOptions = function(options) {
if (options !== undefined) {
if (options.containment !== undefined)
this.containment = options.containment;
if (options.isDocked !== undefined)
this.isDocked = options.isDocked;
}
}

exports.BaseDialog = BaseDialog;
8 changes: 1 addition & 7 deletions src/ui/BodyViewerDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@
* A customised dialog for body viewer.
*/
var BodyViewerDialog = function(bodyViewerIn, parentIn, options) {
(require('./BaseDialog').BaseDialog).call(this);
this.parent = parentIn;
(require('./BaseDialog').BaseDialog).call(this, parentIn, options);
this.module = bodyViewerIn;
this.containment = parentIn;
if (options !== undefined) {
if (options.containment !== undefined)
this.containment = options.containment;
}
var systemGuiFolder = new Array();
var systemPartsGuiControls = new Array();
var _myInstance = this;
Expand Down
10 changes: 2 additions & 8 deletions src/ui/OrgansViewerDialog.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
require("../styles/my_styles.css");

var OrgansViewerDialog = function(organsViewerIn, parentIn, options) {
(require('./BaseDialog').BaseDialog).call(this);
this.parent = parentIn;
this.containment = parentIn;
if (options !== undefined) {
if (options.containment !== undefined)
this.containment = options.containment;
}
var sceneData = undefined;
(require('./BaseDialog').BaseDialog).call(this, parentIn, options);
this.module = organsViewerIn;
var sceneData = undefined;
var organPartsGui = undefined;
var speedSlider = undefined;
var timeSlider = undefined;
Expand Down
8 changes: 1 addition & 7 deletions src/ui/ScaffoldDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@
* A customised dialog for body viewer.
*/
var ScaffoldDialog = function(scaffoldViewerIn, parentIn, options) {
(require('./BaseDialog').BaseDialog).call(this);
this.parent = parentIn;
(require('./BaseDialog').BaseDialog).call(this, parentIn, options);
this.module = scaffoldViewerIn;
this.containment = parentIn;
if (options !== undefined) {
if (options.containment !== undefined)
this.containment = options.containment;
}
var modal = undefined;
var optionsChanged = false;
var _myInstance = this;
Expand Down
15 changes: 1 addition & 14 deletions src/ui/gridView.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require("../styles/gridView.css")
var ResizeSensor = require('css-element-queries/src/ResizeSensor');

exports.GridView = function(containerIn) {
var container = containerIn;
Expand All @@ -8,7 +7,7 @@ exports.GridView = function(containerIn) {
var template = require("../snippets/gridView.html");
var _this = this;
var dialogs = [];
var sensor = undefined;
//var sensor = undefined;
var height = "800px";
this.isEnabled = false;

Expand Down Expand Up @@ -58,15 +57,6 @@ exports.GridView = function(containerIn) {
return false;
}

var updateSize = function() {
if (_this.isEnabled) {
for (var i = 0; i < dialogs.length; i++) {
dialogs[i].setWidth("100%");
dialogs[i].setHeight("100%");
}
}
}

this.addManagerItem = function(item) {
if (_this.isEnabled) {
var dialog = item.getDialog();
Expand All @@ -79,7 +69,6 @@ exports.GridView = function(containerIn) {
}
}


var removeDialog = function(dialog) {
if (dialog && (dialogs.includes(dialog) == true)) {
var containment = dialog.getContainment();
Expand Down Expand Up @@ -109,8 +98,6 @@ exports.GridView = function(containerIn) {
parent = $(template);
rowElement = parent.find(".Row")[0];
container.appendChild(parent[0]);
parent.find(".portalGridViewContainer")[0].onscroll = resize();
sensor = new ResizeSensor(parent[0], resize());
}

setup();
Expand Down
6 changes: 3 additions & 3 deletions src/utilities/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,10 @@ exports.ModuleManager = function() {
itemChangedCallbacks.push(callback);
}

this.createDialog = function(module, parent) {
this.createDialog = function(module, parent, options) {
if (module && ready) {
if (constructors[module.typeName]) {
var dialog = constructors[module.typeName].dialog(module, parent);
var dialog = constructors[module.typeName].dialog(module, parent, options);
_this.manageDialog(dialog);
dialog.destroyModuleOnClose = true;
return dialog;
Expand Down Expand Up @@ -402,7 +402,7 @@ exports.ModuleManager = function() {
parent = document.querySelector(settings.parent);
else
parent = document.querySelector("body");
_this.createDialog(module, parent);
_this.createDialog(module, parent, settings);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/utilities/managerItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ exports.ManagerItem = function() {
var newSettings = module.exportSettings();
if (dialog) {
newSettings.parent = require("../utility").getSelector(dialog.parent);
newSettings.isDocked = dialog.isDocked;
}
return newSettings;
}
Expand Down

0 comments on commit 199b008

Please sign in to comment.