diff --git a/playground/main.html b/playground/main.html index 7a0fda9502..ed98f92bdb 100644 --- a/playground/main.html +++ b/playground/main.html @@ -1 +1,5 @@ + + + + diff --git a/playground/main.js b/playground/main.js index 8385f780a6..6b30f11798 100644 --- a/playground/main.js +++ b/playground/main.js @@ -2,6 +2,8 @@ import {bootstrap} from 'angular2/core'; import {Component, Template} from 'angular2/angular2'; import {Tabbar} from 'ionic/components/tabbar/tabbar'; +import 'ionic/components/tabbar/mixins/android/android-tabbar'; + @Component({ selector: 'playground-main' }) @Template({ url: 'main.html', diff --git a/src/components/ion.js b/src/components/ion.js index 3c0f9eecca..9ace4640fb 100644 --- a/src/components/ion.js +++ b/src/components/ion.js @@ -1,7 +1,18 @@ +import * as Platform from '../platform'; var ILLEGAL_ASSIGN_FIELDS = {}; export class Ion { + constructor() { + var platformName = Platform.getPlatform(); + var platformConfig = this.$config._platforms[platformName]; + if (platformConfig) { + platformConfig._mixins.forEach(mixin => { + mixin(this); + }); + } + } + assign() { for (var i = 0, ii = arguments.length; i < ii; i++) { var obj = arguments[i]; diff --git a/src/components/tabbar/mixins/android/android-tabbar.js b/src/components/tabbar/mixins/android/android-tabbar.js index 6abda7512e..96432d122e 100644 --- a/src/components/tabbar/mixins/android/android-tabbar.js +++ b/src/components/tabbar/mixins/android/android-tabbar.js @@ -1,19 +1,18 @@ -/* -import {TabbarConfig} from '/components/tabbar/tabbar'; -import {Draggable} from '/behaviors/draggable'; + +import {TabbarConfig} from '../../tabbar'; +// import {Draggable} from '/behaviors/draggable'; TabbarConfig.platform('android') - .template(require('./android-template.html')) + .template('./android-template.html') .mixin(function(tabbar) { - Draggable(tabbar); - tabbarInstance.setAsHeader(); + // Draggable(tabbar); + // tabbarInstance.setAsHeader(); tabbar.assign({ - onDragStart() {}, - onDrag() {}, - onDragEnd() {} + press() { + alert('pressing from android mixin'); + } }); }); - -*/ +export var a = 2; diff --git a/src/components/tabbar/mixins/android/android-tabbar.spec.js b/src/components/tabbar/mixins/android/android-tabbar.spec.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/components/tabbar/tabbar.js b/src/components/tabbar/tabbar.js index 70719c7b10..9a7ac063fe 100644 --- a/src/components/tabbar/tabbar.js +++ b/src/components/tabbar/tabbar.js @@ -1,23 +1,31 @@ import {Component, Template} from 'angular2/angular2'; +import {Inject} from 'angular2/di'; import {Ion} from '../ion'; +import {IonConfigService} from '../../config'; + +export var TabbarConfig = IonConfigService(); @Component({ selector: 'ion-tabbar', bind: { title: 'view-title' - } + }, + services: [TabbarConfig] }) @Template({ inline: `` }) export class Tabbar extends Ion { - constructor() { - - // Test that Ion#assign works - this.assign({ - press: () => { - alert('pressed!'); - } - }); + constructor( + // Creates a TabbarConfig instance for this specific instance of Tabbar. + // this instance is created with a cloned version of all the globally + // set config properties. + @Inject(TabbarConfig) config + ) { + debugger; + this.$config = config; + super(); } } + + diff --git a/src/config.js b/src/config.js new file mode 100644 index 0000000000..04f3f72e9f --- /dev/null +++ b/src/config.js @@ -0,0 +1,41 @@ +import * as Platform from './platform'; + +var i = 0; +export function IonConfigService() { + + function Config() { + this._platforms = {}; + for (var key in Config._platforms) { + this._platforms[key] = Config._platforms[key]._clone(); + } + } + Config._platforms = {}; + Config.platform = platformFn.bind(Config); + Config.prototype.platform = platformFn; + + function platformFn(name) { + return this._platforms[name] || (this._platforms[name] = new SubConfig(name)); + } + + return Config; +} + + +class SubConfig { + constructor(name, mixins = [], template = '') { + this._name = name; + this._mixins = mixins; + this._template = template; + } + mixin(mixinFn) { + this._mixins.push(mixinFn); + return this; + } + template(url) { + this._template = url; + return this; + } + _clone() { + return new SubConfig(this._name, this._mixins.slice(), this._template); + } +} diff --git a/src/platform.js b/src/platform.js index e69de29bb2..0689cc66fb 100644 --- a/src/platform.js +++ b/src/platform.js @@ -0,0 +1,4 @@ + +export function getPlatform() { + return 'android'; +}