-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor offsetHeight use float-compat API
- Loading branch information
Showing
4 changed files
with
72 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,3 @@ | ||
export function getScale(element) { | ||
let rect = element.getBoundingClientRect(); | ||
import { getScale } from 'ember-table/-private/utils/element'; | ||
|
||
if (element.offsetHeight === rect.height || rect.height === 0) { | ||
return 1; | ||
} else { | ||
return element.offsetHeight / rect.height; | ||
} | ||
} | ||
export { getScale }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { module, test } from 'qunit'; | ||
import { getScale } from 'ember-table/-private/utils/element'; | ||
|
||
module('Unit | Private | element', function(hooks) { | ||
hooks.beforeEach(function() { | ||
/* | ||
* Use an element outside the normal test harness as that harness | ||
* uses scale() on the test container. | ||
*/ | ||
this.element = document.createElement('div'); | ||
document.body.append(this.element); | ||
}); | ||
|
||
hooks.afterEach(function() { | ||
this.element.remove(); | ||
}); | ||
|
||
test('can get the scale of a transformed element', function(assert) { | ||
let div = document.createElement('div'); | ||
div.style.height = '4px'; | ||
this.element.append(div); | ||
|
||
assert.equal(getScale(div), 1, 'scale on a simple element is correct'); | ||
|
||
div.style.transform = 'scale(0.5)'; | ||
|
||
assert.equal(getScale(div), 2, 'scale on a scaled element is correct'); | ||
|
||
div.style.height = '1.5px'; | ||
|
||
assert.equal(getScale(div), 2, 'scale on a scaled element is correct'); | ||
}); | ||
}); |