Commit a7e4ffc2 authored by marc duez's avatar marc duez

view.js : auto-resize

-add an observer on view and resize on change
-use a 500ms delay
parent 3135e520
......@@ -134,7 +134,7 @@ Builder.prototype = {
var sel = window.getSelection();
sel.removeAllRanges();
this.m.resize();
//this.m.resize();
}
},
......@@ -457,7 +457,7 @@ Builder.prototype = {
val = 'flex';
}
$left.css('display', val);
this.m.resize();
//this.m.resize();
},
build_top_container: function () {
......
......@@ -74,10 +74,9 @@
* */
function Graph(id, model, database) {
//
View.call(this, model);
View.call(this, model, id);
this.useSmartUpdateElemStyle = false;
this.id = id;
this.resizeW = 1; //coeff d'agrandissement/réduction largeur
this.resizeH = 1; //coeff d'agrandissement/réduction hauteur
......
......@@ -56,7 +56,7 @@ function Model() {
this.checkBrowser();
this.germlineList = new GermlineList()
this.build();
window.onresize = function () { self.resize(); };
//window.onresize = function () { self.resize(); };
this.NORM_FALSE = "no_norm"
this.NORM_EXPECTED = "expected"
......
......@@ -35,7 +35,7 @@
function ScatterPlot(id, model, database, default_preset) {
var self = this;
View.call(this, model);
View.call(this, model, id);
this.db = database;
this.id = id; //ID of the scatterPlot div
......
......@@ -29,8 +29,10 @@
* @class View
* @constructor
* */
function View(model) {
function View(model, id) {
var self = this;
this.m = model;
this.id = id;
this.m.view.push(this); //Model's sync
//smartUpdate
......@@ -55,6 +57,12 @@ function View(model) {
this.updateElemStyleList = {};
this.updateElemStyleMinWait = 10; //update will at least wait XXX(ms) before starting
this.updateElemStyleMaxWait = 50; //update will start anyway if the wait has been more than XXX(ms)
if (typeof this.id != "undefined") {
this.autoresizeCounter=0;
this.resizeObserver = new ResizeObserver( function(){self.autoResize()} )
this.resizeObserver.observe(document.getElementById(this.id));
}
}
View.prototype = {
......@@ -243,6 +251,17 @@ View.prototype = {
return false;
},
autoResize: function() {
var self = this
this.autoresizeCounter++
setTimeout(function(){
self.autoresizeCounter--
if (self.autoresizeCounter==0)
self.resize()
}, 500)
},
/**
* resize view to match his div size <br>
* each view must be able to match the size of it's div
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment