Skip to content

Commit cea9174

Browse files
committed
move parseHeight to Utils
1 parent 781776e commit cea9174

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/gridstack.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,20 @@
9898

9999
_isAddNodeIntercepted: function(n) {
100100
return Utils.isIntercepted({x: this.x, y: this.y, width: this.node.width, height: this.node.height}, n);
101+
},
102+
103+
parseHeight: function(val) {
104+
var height = val;
105+
var heightUnit = 'px';
106+
if (height && _.isString(height)) {
107+
var match = height.match(/^([0-9]*\.[0-9]+|[0-9]+)(px|em|rem|vh|vw)?$/);
108+
if (!match) {
109+
throw new Error('Invalid height');
110+
}
111+
heightUnit = match[2];
112+
height = parseFloat(match[1]);
113+
}
114+
return {height: height, unit: heightUnit};
101115
}
102116
};
103117

@@ -1125,26 +1139,12 @@
11251139
});
11261140
};
11271141

1128-
function parseHeight(val) {
1129-
var height = val;
1130-
var heightUnit = 'px';
1131-
if (height && _.isString(height)) {
1132-
var match = height.match(/^([0-9]*\.[0-9]+|[0-9]+)(px|em|rem|vh|vw)?$/);
1133-
if (!match) {
1134-
throw new Error('Invalid height');
1135-
}
1136-
heightUnit = match[2];
1137-
height = parseFloat(match[1]);
1138-
}
1139-
return {height: height, unit: heightUnit};
1140-
}
1141-
11421142
GridStack.prototype.verticalMargin = function(val, noUpdate) {
11431143
if (typeof val == 'undefined') {
11441144
return this.opts.verticalMargin;
11451145
}
11461146

1147-
var heightData = parseHeight(val);
1147+
var heightData = Utils.parseHeight(val);
11481148

11491149
if (this.opts.verticalMarginUnit === heightData.unit && this.opts.height === heightData.height) {
11501150
return ;
@@ -1165,7 +1165,7 @@
11651165
var o = this.container.children('.' + this.opts.itemClass).first();
11661166
return Math.ceil(o.outerHeight() / o.attr('data-gs-height'));
11671167
}
1168-
var heightData = parseHeight(val);
1168+
var heightData = Utils.parseHeight(val);
11691169

11701170
if (this.opts.cellHeightUnit === heightData.heightUnit && this.opts.height === heightData.height) {
11711171
return ;

0 commit comments

Comments
 (0)