mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-21 04:53:58 +08:00
chore(): add types
This commit is contained in:
@ -3,6 +3,7 @@ import {Config} from '../config/config';
|
|||||||
import {isArray} from '../util';
|
import {isArray} from '../util';
|
||||||
import * as dom from '../util/dom';
|
import * as dom from '../util/dom';
|
||||||
|
|
||||||
|
let ids:number = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for all Ionic components. Exposes some common functionality
|
* Base class for all Ionic components. Exposes some common functionality
|
||||||
@ -10,8 +11,10 @@ import * as dom from '../util/dom';
|
|||||||
* sending/receiving app-level events.
|
* sending/receiving app-level events.
|
||||||
*/
|
*/
|
||||||
export class Ion {
|
export class Ion {
|
||||||
constructor(elementRef: ElementRef) {
|
private _id: string;
|
||||||
this.elementRef = elementRef;
|
|
||||||
|
constructor(protected elementRef: ElementRef) {
|
||||||
|
this._id = 'i-' + ids++;
|
||||||
}
|
}
|
||||||
|
|
||||||
getElementRef() {
|
getElementRef() {
|
||||||
@ -23,15 +26,15 @@ export class Ion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getDimensions() {
|
getDimensions() {
|
||||||
return dom.getDimensions(this);
|
return dom.getDimensions(this.elementRef.nativeElement, this._id);
|
||||||
}
|
}
|
||||||
|
|
||||||
width() {
|
width() {
|
||||||
return dom.getDimensions(this).width;
|
return dom.getDimensions(this.elementRef.nativeElement, this._id).width;
|
||||||
}
|
}
|
||||||
|
|
||||||
height() {
|
height() {
|
||||||
return dom.getDimensions(this).height;
|
return dom.getDimensions(this.elementRef.nativeElement, this._id).height;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -234,21 +234,14 @@ export function removeElement(ele) {
|
|||||||
* to reduce DOM reads. Cache is cleared on a window resize.
|
* to reduce DOM reads. Cache is cleared on a window resize.
|
||||||
* @param {TODO} ele TODO
|
* @param {TODO} ele TODO
|
||||||
*/
|
*/
|
||||||
export function getDimensions(ion, ele) {
|
export function getDimensions(ele: HTMLElement, id: string): {
|
||||||
if (!ion._dimId) {
|
width: number, height: number, left: number, top: number
|
||||||
ion._dimId = ++dimensionIds;
|
} {
|
||||||
if (ion._dimId % 1000 === 0) {
|
let dimensions = dimensionCache[id];
|
||||||
// periodically flush dimensions
|
|
||||||
flushDimensionCache();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let dimensions = dimensionCache[ion._dimId];
|
|
||||||
if (!dimensions) {
|
if (!dimensions) {
|
||||||
let ele = ion.getNativeElement();
|
|
||||||
// make sure we got good values before caching
|
// make sure we got good values before caching
|
||||||
if (ele.offsetWidth && ele.offsetHeight) {
|
if (ele.offsetWidth && ele.offsetHeight) {
|
||||||
dimensions = dimensionCache[ion._dimId] = {
|
dimensions = dimensionCache[id] = {
|
||||||
width: ele.offsetWidth,
|
width: ele.offsetWidth,
|
||||||
height: ele.offsetHeight,
|
height: ele.offsetHeight,
|
||||||
left: ele.offsetLeft,
|
left: ele.offsetLeft,
|
||||||
@ -285,7 +278,6 @@ export function flushDimensionCache() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let dimensionCache:any = {};
|
let dimensionCache:any = {};
|
||||||
let dimensionIds = 0;
|
|
||||||
|
|
||||||
function isStaticPositioned(element) {
|
function isStaticPositioned(element) {
|
||||||
return (element.style.position || 'static') === 'static';
|
return (element.style.position || 'static') === 'static';
|
||||||
|
Reference in New Issue
Block a user