move parseHeight to Utils
This commit is contained in:
parent
781776e408
commit
cea9174bd3
1 changed files with 16 additions and 16 deletions
|
|
@ -98,6 +98,20 @@
|
|||
|
||||
_isAddNodeIntercepted: function(n) {
|
||||
return Utils.isIntercepted({x: this.x, y: this.y, width: this.node.width, height: this.node.height}, n);
|
||||
},
|
||||
|
||||
parseHeight: function(val) {
|
||||
var height = val;
|
||||
var heightUnit = 'px';
|
||||
if (height && _.isString(height)) {
|
||||
var match = height.match(/^([0-9]*\.[0-9]+|[0-9]+)(px|em|rem|vh|vw)?$/);
|
||||
if (!match) {
|
||||
throw new Error('Invalid height');
|
||||
}
|
||||
heightUnit = match[2];
|
||||
height = parseFloat(match[1]);
|
||||
}
|
||||
return {height: height, unit: heightUnit};
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -1125,26 +1139,12 @@
|
|||
});
|
||||
};
|
||||
|
||||
function parseHeight(val) {
|
||||
var height = val;
|
||||
var heightUnit = 'px';
|
||||
if (height && _.isString(height)) {
|
||||
var match = height.match(/^([0-9]*\.[0-9]+|[0-9]+)(px|em|rem|vh|vw)?$/);
|
||||
if (!match) {
|
||||
throw new Error('Invalid height');
|
||||
}
|
||||
heightUnit = match[2];
|
||||
height = parseFloat(match[1]);
|
||||
}
|
||||
return {height: height, unit: heightUnit};
|
||||
}
|
||||
|
||||
GridStack.prototype.verticalMargin = function(val, noUpdate) {
|
||||
if (typeof val == 'undefined') {
|
||||
return this.opts.verticalMargin;
|
||||
}
|
||||
|
||||
var heightData = parseHeight(val);
|
||||
var heightData = Utils.parseHeight(val);
|
||||
|
||||
if (this.opts.verticalMarginUnit === heightData.unit && this.opts.height === heightData.height) {
|
||||
return ;
|
||||
|
|
@ -1165,7 +1165,7 @@
|
|||
var o = this.container.children('.' + this.opts.itemClass).first();
|
||||
return Math.ceil(o.outerHeight() / o.attr('data-gs-height'));
|
||||
}
|
||||
var heightData = parseHeight(val);
|
||||
var heightData = Utils.parseHeight(val);
|
||||
|
||||
if (this.opts.cellHeightUnit === heightData.heightUnit && this.opts.height === heightData.height) {
|
||||
return ;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue