mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
72 lines
1.8 KiB
TypeScript
72 lines
1.8 KiB
TypeScript
import {ElementRef} from 'angular2/angular2';
|
|
import {Config} from '../config/config';
|
|
import {isArray} from '../util';
|
|
import * as dom from '../util/dom';
|
|
|
|
|
|
/**
|
|
* Base class for all Ionic components. Exposes some common functionality
|
|
* that all Ionic components need, such as accessing underlying native elements and
|
|
* sending/receiving app-level events.
|
|
*/
|
|
export class Ion {
|
|
constructor(elementRef: ElementRef, config: Config) {
|
|
this.elementRef = elementRef;
|
|
this.config = config;
|
|
}
|
|
|
|
ngOnInit() {
|
|
let cls = this.constructor;
|
|
|
|
if (cls.defaultInputs && this.config) {
|
|
for (let prop in cls.defaultInputs) {
|
|
// Priority:
|
|
// ---------
|
|
// 1) Value set from within constructor
|
|
// 2) Value set from the host element's attribute
|
|
// 3) Value set by the users global config
|
|
// 4) Value set by the default mode/platform config
|
|
// 5) Value set from the component's default
|
|
|
|
if (this[prop]) {
|
|
// this property has already been set on the instance
|
|
// could be from the user setting the element's attribute
|
|
// or from the user setting it within the constructor
|
|
continue;
|
|
}
|
|
|
|
// get the property values from a global user/platform config
|
|
let configVal = this.config.get(prop);
|
|
if (configVal) {
|
|
this[prop] = configVal;
|
|
continue;
|
|
}
|
|
|
|
// wasn't set yet, so go with property's default value
|
|
this[prop] = cls.defaultInputs[prop];
|
|
}
|
|
}
|
|
}
|
|
|
|
getElementRef() {
|
|
return this.elementRef;
|
|
}
|
|
|
|
getNativeElement() {
|
|
return this.elementRef.nativeElement;
|
|
}
|
|
|
|
getDimensions() {
|
|
return dom.getDimensions(this);
|
|
}
|
|
|
|
width() {
|
|
return dom.getDimensions(this).width;
|
|
}
|
|
|
|
height() {
|
|
return dom.getDimensions(this).height;
|
|
}
|
|
|
|
}
|