Merge pull request #5070 from thornbill/ios-12-fix
This commit is contained in:
commit
29ea7be41a
3 changed files with 49 additions and 15 deletions
|
@ -175,16 +175,7 @@ const scrollerFactory = function (frame, options) {
|
|||
requiresReflow = false;
|
||||
|
||||
// Reset global variables
|
||||
const frameStyle = window.getComputedStyle(frame);
|
||||
if (o.horizontal) {
|
||||
frameSize = frame.clientWidth;
|
||||
frameSize -= parseFloat(frameStyle.paddingLeft) + parseFloat(frameStyle.paddingRight);
|
||||
} else {
|
||||
frameSize = frame.clientHeight;
|
||||
frameSize -= parseFloat(frameStyle.paddingTop) + parseFloat(frameStyle.paddingBottom);
|
||||
}
|
||||
frameSize = Math.round(frameSize);
|
||||
|
||||
frameSize = slideeElement[o.horizontal ? 'clientWidth' : 'clientHeight'];
|
||||
slideeSize = o.scrollWidth || Math.max(slideeElement[o.horizontal ? 'offsetWidth' : 'offsetHeight'], slideeElement[o.horizontal ? 'scrollWidth' : 'scrollHeight']);
|
||||
|
||||
// Set position limits & relatives
|
||||
|
|
42
src/utils/string.test.ts
Normal file
42
src/utils/string.test.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { toBoolean, toFloat } from './string';
|
||||
|
||||
describe('toBoolean', () => {
|
||||
it('Should return the boolean represented by the string', () => {
|
||||
let bool = toBoolean('true');
|
||||
expect(bool).toBe(true);
|
||||
|
||||
bool = toBoolean('false', true);
|
||||
expect(bool).toBe(false);
|
||||
});
|
||||
|
||||
it('Should return default value for invalid values', () => {
|
||||
let bool = toBoolean('test');
|
||||
expect(bool).toBe(false);
|
||||
|
||||
bool = toBoolean(undefined);
|
||||
expect(bool).toBe(false);
|
||||
|
||||
bool = toBoolean(null, true);
|
||||
expect(bool).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('toFloat()', () => {
|
||||
it('Should return a float', () => {
|
||||
const number = toFloat('3.14159');
|
||||
expect(number).toBe(3.14159);
|
||||
});
|
||||
|
||||
it('Should return default value for NaN', () => {
|
||||
let number = toFloat('test');
|
||||
expect(number).toBe(0);
|
||||
|
||||
number = toFloat(undefined);
|
||||
expect(number).toBe(0);
|
||||
|
||||
number = toFloat(null, -1);
|
||||
expect(number).toBe(-1);
|
||||
});
|
||||
});
|
|
@ -19,9 +19,10 @@ export function toBoolean(value: string | undefined | null, defaultValue = false
|
|||
* @returns {number} The value.
|
||||
*/
|
||||
export function toFloat(value: string | null | undefined, defaultValue = 0) {
|
||||
if (!value || isNaN(value as never)) {
|
||||
return defaultValue;
|
||||
} else {
|
||||
return parseFloat(value);
|
||||
}
|
||||
if (!value) return defaultValue;
|
||||
|
||||
const number = parseFloat(value);
|
||||
if (isNaN(number)) return defaultValue;
|
||||
|
||||
return number;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue