chore(build): rename ionic directory to src and update all references in the build process.

This commit is contained in:
Josh Thomas
2016-05-19 13:20:59 -05:00
parent 8470ae04ac
commit c8f760f080
595 changed files with 73 additions and 87 deletions

169
src/config/bootstrap.ts Normal file
View File

@@ -0,0 +1,169 @@
import {provide, Provider, ComponentRef, NgZone} from '@angular/core';
import {ROUTER_PROVIDERS} from '@angular/router';
import {LocationStrategy, HashLocationStrategy} from '@angular/common';
import {HTTP_PROVIDERS} from '@angular/http';
import {ClickBlock} from '../util/click-block';
import {Config} from './config';
import {Events} from '../util/events';
import {FeatureDetect} from '../util/feature-detect';
import {Form} from '../util/form';
import {IonicApp} from '../components/app/app';
import {Keyboard} from '../util/keyboard';
import {MenuController} from '../components/menu/menu-controller';
import {NavRegistry} from '../components/nav/nav-registry';
import {Platform} from '../platform/platform';
import {ready, closest} from '../util/dom';
import {ScrollView} from '../util/scroll-view';
import {TapClick} from '../components/tap-click/tap-click';
import {Translate} from '../translation/translate';
/**
* @private
*/
export function ionicProviders(args: any = {}) {
let platform = new Platform();
let navRegistry = new NavRegistry(args.pages);
var config = args.config;
if (!(config instanceof Config)) {
config = new Config(config);
}
platform.setUrl(window.location.href);
platform.setUserAgent(window.navigator.userAgent);
platform.setNavigatorPlatform(window.navigator.platform);
platform.load(config);
config.setPlatform(platform);
let clickBlock = new ClickBlock();
let events = new Events();
let featureDetect = new FeatureDetect();
setupDom(window, document, config, platform, clickBlock, featureDetect);
bindEvents(window, document, platform, events);
return [
IonicApp,
provide(ClickBlock, {useValue: clickBlock}),
provide(Config, {useValue: config}),
provide(Platform, {useValue: platform}),
provide(FeatureDetect, {useValue: featureDetect}),
provide(Events, {useValue: events}),
provide(NavRegistry, {useValue: navRegistry}),
TapClick,
Form,
Keyboard,
MenuController,
Translate,
ROUTER_PROVIDERS,
provide(LocationStrategy, {useClass: HashLocationStrategy}),
HTTP_PROVIDERS,
];
}
/**
* @private
*/
export function postBootstrap(appRef: ComponentRef<any>, prodMode: boolean) {
appRef.injector.get(TapClick);
let app: IonicApp = appRef.injector.get(IonicApp);
let platform: Platform = appRef.injector.get(Platform);
platform.setZone(appRef.injector.get(NgZone));
platform.prepareReady();
app.setProd(prodMode);
app.setAppInjector(appRef.injector);
}
function setupDom(window, document, config, platform, clickBlock, featureDetect) {
let bodyEle = document.body;
let mode = config.get('mode');
// if dynamic mode links have been added the fire up the correct one
let modeLinkAttr = mode + '-href';
let linkEle = document.head.querySelector('link[' + modeLinkAttr + ']');
if (linkEle) {
let href = linkEle.getAttribute(modeLinkAttr);
linkEle.removeAttribute(modeLinkAttr);
linkEle.href = href;
}
// set the mode class name
// ios/md/wp
bodyEle.classList.add(mode);
// language and direction
platform.setDir(document.documentElement.dir, false);
platform.setLang(document.documentElement.lang, false);
let versions = platform.versions();
platform.platforms().forEach(platformName => {
// platform-ios
let platformClass = 'platform-' + platformName;
bodyEle.classList.add(platformClass);
let platformVersion = versions[platformName];
if (platformVersion) {
// platform-ios9
platformClass += platformVersion.major;
bodyEle.classList.add(platformClass);
// platform-ios9_3
bodyEle.classList.add(platformClass + '_' + platformVersion.minor);
}
});
// touch devices should not use :hover CSS pseudo
// enable :hover CSS when the "hoverCSS" setting is not false
if (config.get('hoverCSS') !== false) {
bodyEle.classList.add('enable-hover');
}
if (config.get('clickBlock')) {
clickBlock.enable();
}
// run feature detection tests
featureDetect.run(window, document);
}
/**
* Bind some global events and publish on the 'app' channel
*/
function bindEvents(window, document, platform, events) {
window.addEventListener('online', (ev) => {
events.publish('app:online', ev);
}, false);
window.addEventListener('offline', (ev) => {
events.publish('app:offline', ev);
}, false);
window.addEventListener('orientationchange', (ev) => {
events.publish('app:rotated', ev);
});
// When that status taps, we respond
window.addEventListener('statusTap', (ev) => {
// TODO: Make this more better
var el = document.elementFromPoint(platform.width() / 2, platform.height() / 2);
if (!el) { return; }
var content = closest(el, 'scroll-content');
if (content) {
var scroll = new ScrollView(content);
scroll.scrollTo(0, 0, 300);
}
});
// start listening for resizes XXms after the app starts
setTimeout(function() {
window.addEventListener('resize', function() {
platform.windowResize();
});
}, 2000);
}

374
src/config/config.ts Normal file
View File

@@ -0,0 +1,374 @@
/**
* @ngdoc service
* @name Config
* @module ionic
* @description
* Config allows you to set the modes of your components
*/
import {Platform} from '../platform/platform';
import {isObject, isDefined, isFunction, isArray} from '../util/util';
/**
* @name Config
* @demo /docs/v2/demos/config/
* @description
* The Config lets you configure your entire app or specific platforms.
* You can set the tab placement, icon mode, animations, and more here.
*
* ```ts
* @App({
* template: `<ion-nav [root]="root"></ion-nav>`
* config: {
* backButtonText: 'Go Back',
* iconMode: 'ios',
* modalEnter: 'modal-slide-in',
* modalLeave: 'modal-slide-out',
* tabbarPlacement: 'bottom',
* pageTransition: 'ios',
* }
* })
* ```
*
* To change the mode to always use Material Design (md).
*
* ```ts
* @App({
* template: `<ion-nav [root]="root"></ion-nav>`
* config: {
* mode: 'md'
* }
* })
* ```
*
* Config can be overwritten at multiple levels allowing for more configuration. Taking the example from earlier, we can override any setting we want based on a platform.
* ```ts
* @App({
* template: `<ion-nav [root]="root"></ion-nav>`
* config: {
* tabbarPlacement: 'bottom',
* platforms: {
* ios: {
* tabbarPlacement: 'top',
* }
* }
* }
* })
* ```
*
* We could also configure these values at a component level. Take `tabbarPlacement`, we can configure this as a property on our `ion-tabs`.
*
* ```html
* <ion-tabs tabbarPlacement="top">
* <ion-tab tabTitle="Dash" tabIcon="pulse" [root]="tabRoot"></ion-tab>
* </ion-tabs>
* ```
*
* The last way we could configure is through URL query strings. This is useful for testing while in the browser.
* Simply add `?ionic<PROPERTYNAME>=<value>` to the url.
*
* ```bash
* http://localhost:8100/?ionicTabbarPlacement=bottom
* ```
*
* Custom values can be added to config, and looked up at a later point in time.
*
* ``` javascript
* config.set('ios', 'favoriteColor', 'green');
* // from any page in your app:
* config.get('favoriteColor'); // 'green'
* ```
*
*
* A config value can come from anywhere and be anything, but there are default
* values for each mode. The [theming](../../../theming/platform-specific-styles/)
* documentation has a chart of the default mode configuration. The following
* chart displays each property with a description of what it controls.
*
*
* | Config Property | Type | Details |
* |--------------------------|---------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|
* | `activator` | `string` | Used for buttons, changes the effect of pressing on a button. Available options: `"ripple"`, `"highlight"`. |
* | `actionSheetEnter` | `string` | The name of the transition to use while an action sheet is presented. |
* | `actionSheetLeave` | `string` | The name of the transition to use while an action sheet is dismissed. |
* | `alertEnter` | `string` | The name of the transition to use while an alert is presented. |
* | `alertLeave` | `string` | The name of the transition to use while an alert is dismissed. |
* | `backButtonText` | `string` | The text to display by the back button icon in the navbar. |
* | `backButtonIcon` | `string` | The icon to use as the back button icon. |
* | `iconMode` | `string` | The mode to use for all icons throughout the application. Available options: `"ios"`, `"md"` |
* | `loadingEnter` | `string` | The name of the transition to use while a loading indicator is presented. |
* | `loadingLeave` | `string` | The name of the transition to use while a loading indicator is dismissed. |
* | `menuType` | `string` | Type of menu to display. Available options: `"overlay"`, `"reveal"`, `"push"`. |
* | `modalEnter` | `string` | The name of the transition to use while a modal is presented. |
* | `modalLeave` | `string` | The name of the transition to use while a modal is dismiss. |
* | `pageTransition` | `string` | The name of the transition to use while changing pages. |
* | `pageTransitionDelay` | `number` | The delay in milliseconds before the transition starts while changing pages. |
* | `pickerEnter` | `string` | The name of the transition to use while a picker is presented. |
* | `pickerLeave` | `string` | The name of the transition to use while a picker is dismissed. |
* | `spinner` | `string` | The default spinner to use when a name is not defined. |
* | `tabbarHighlight` | `boolean` | Whether to show a highlight line under the tab when it is selected. |
* | `tabbarLayout` | `string` | The layout to use for all tabs. Available options: `"icon-top"`, `"icon-left"`, `"icon-right"`, `"icon-bottom"`, `"icon-hide"`, `"title-hide"`. |
* | `tabbarPlacement` | `string` | The position of the tabs. Available options: `"top"`, `"bottom"` |
* | `tabSubPages` | `boolean` | Whether to hide the tabs on child pages or not. If `true` it will not show the tabs on child pages. |
* | `toastEnter` | `string` | The name of the transition to use while a toast is presented. |
* | `toastLeave` | `string` | The name of the transition to use while a toast is dismissed. |
*
**/
export class Config {
private _c: any = {};
private _s: any = {};
/**
* @private
*/
platform: Platform;
constructor(config?) {
this._s = config && isObject(config) && !isArray(config) ? config : {};
}
/**
* @name get
* @description
* Returns a single config value, given a key.
*
* @param {string} [key] - the key for the config value
* @param {any} [fallbackValue] - a fallback value to use when the config
* value was not found, or is config value is `null`. Fallback value
* defaults to `null`.
*/
get(key: string, fallbackValue: any = null): any {
if (!isDefined(this._c[key])) {
if (!isDefined(key)) {
throw 'config key is not defined';
}
// if the value was already set this will all be skipped
// if there was no user config then it'll check each of
// the user config's platforms, which already contains
// settings from default platform configs
let userPlatformValue = undefined;
let userDefaultValue = this._s[key];
let userPlatformModeValue = undefined;
let userDefaultModeValue = undefined;
let platformValue = undefined;
let platformModeValue = undefined;
let configObj = null;
if (this.platform) {
let queryStringValue = this.platform.query('ionic' + key.toLowerCase());
if (isDefined(queryStringValue)) {
return this._c[key] = (queryStringValue === 'true' ? true : queryStringValue === 'false' ? false : queryStringValue);
}
// check the platform settings object for this value
// loop though each of the active platforms
// array of active platforms, which also knows the hierarchy,
// with the last one the most important
let activePlatformKeys = this.platform.platforms();
// loop through all of the active platforms we're on
for (let i = 0, l = activePlatformKeys.length; i < l; i++) {
// get user defined platform values
if (this._s.platforms) {
configObj = this._s.platforms[activePlatformKeys[i]];
if (configObj) {
if (isDefined(configObj[key])) {
userPlatformValue = configObj[key];
}
configObj = Config.getModeConfig(configObj.mode);
if (configObj && isDefined(configObj[key])) {
userPlatformModeValue = configObj[key];
}
}
}
// get default platform's setting
configObj = Platform.get(activePlatformKeys[i]);
if (configObj && configObj.settings) {
if (isDefined(configObj.settings[key])) {
// found a setting for this platform
platformValue = configObj.settings[key];
}
configObj = Config.getModeConfig(configObj.settings.mode);
if (configObj && isDefined(configObj[key])) {
// found setting for this platform's mode
platformModeValue = configObj[key];
}
}
}
}
configObj = Config.getModeConfig(this._s.mode);
if (configObj && isDefined(configObj[key])) {
userDefaultModeValue = configObj[key];
}
// cache the value
this._c[key] = isDefined(userPlatformValue) ? userPlatformValue :
isDefined(userDefaultValue) ? userDefaultValue :
isDefined(userPlatformModeValue) ? userPlatformModeValue :
isDefined(userDefaultModeValue) ? userDefaultModeValue :
isDefined(platformValue) ? platformValue :
isDefined(platformModeValue) ? platformModeValue :
null;
}
// return key's value
// either it came directly from the user config
// or it was from the users platform configs
// or it was from the default platform configs
// in that order
let rtnVal;
if (isFunction(this._c[key])) {
rtnVal = this._c[key](this.platform);
} else {
rtnVal = this._c[key];
}
return (rtnVal !== null ? rtnVal : fallbackValue);
}
/**
* @name getBoolean
* @description
* Same as `get()`, however always returns a boolean value. If the
* value from `get()` is `null`, then it'll return the `fallbackValue`
* which defaults to `false`. Otherwise, `getBoolean()` will return
* if the config value is truthy or not. It also returns `true` if
* the config value was the string value `"true"`.
* @param {string} [key] - the key for the config value
* @param {boolean} [fallbackValue] - a fallback value to use when the config
* value was `null`. Fallback value defaults to `false`.
*/
getBoolean(key: string, fallbackValue: boolean = false): boolean {
let val = this.get(key);
if (val === null) {
return fallbackValue;
}
if (typeof val === 'string') {
return val === 'true';
}
return !!val;
}
/**
* @name getNumber
* @description
* Same as `get()`, however always returns a number value. Uses `parseFloat()`
* on the value received from `get()`. If the result from the parse is `NaN`,
* then it will return the value passed to `fallbackValue`. If no fallback
* value was provided then it'll default to returning `NaN` when the result
* is not a valid number.
* @param {string} [key] - the key for the config value
* @param {number} [fallbackValue] - a fallback value to use when the config
* value turned out to be `NaN`. Fallback value defaults to `NaN`.
*/
getNumber(key: string, fallbackValue: number = NaN): number {
let val = parseFloat( this.get(key) );
return isNaN(val) ? fallbackValue : val;
}
/**
* @name set
* @description
* Sets a single config value.
*
* @param {string} [platform] - The platform (either 'ios' or 'android') that the config value should apply to. Leaving this blank will apply the config value to all platforms.
* @param {string} [key] - The key used to look up the value at a later point in time.
* @param {string} [value] - The config value being stored.
*/
set(...args: any[]) {
const arg0 = args[0];
const arg1 = args[1];
switch (args.length) {
case 2:
// set('key', 'value') = set key/value pair
// arg1 = value
this._s[arg0] = arg1;
delete this._c[arg0]; // clear cache
break;
case 3:
// setting('ios', 'key', 'value') = set key/value pair for platform
// arg0 = platform
// arg1 = key
// arg2 = value
this._s.platforms = this._s.platforms || {};
this._s.platforms[arg0] = this._s.platforms[arg0] || {};
this._s.platforms[arg0][arg1] = args[2];
delete this._c[arg1]; // clear cache
break;
}
return this;
}
/**
* @private
* @name settings()
* @description
*/
settings(arg0?: any, arg1?: any) {
switch (arguments.length) {
case 0:
return this._s;
case 1:
// settings({...})
this._s = arg0;
this._c = {}; // clear cache
break;
case 2:
// settings('ios', {...})
this._s.platforms = this._s.platforms || {};
this._s.platforms[arg0] = arg1;
this._c = {}; // clear cache
break;
}
return this;
}
/**
* @private
*/
setPlatform(platform) {
this.platform = platform;
}
/**
* @private
*/
static setModeConfig(mode, config) {
modeConfigs[mode] = config;
}
/**
* @private
*/
static getModeConfig(mode) {
return modeConfigs[mode] || null;
}
}
let modeConfigs = {};

219
src/config/directives.ts Normal file
View File

@@ -0,0 +1,219 @@
import {forwardRef, Type} from '@angular/core';
import {CORE_DIRECTIVES, FORM_DIRECTIVES} from '@angular/common';
import {Menu} from '../components/menu/menu';
import {MenuToggle} from '../components/menu/menu-toggle';
import {MenuClose} from '../components/menu/menu-close';
import {Badge} from '../components/badge/badge';
import {Button} from '../components/button/button';
import {Content} from '../components/content/content';
import {Img} from '../components/img/img';
import {Scroll} from '../components/scroll/scroll';
import {InfiniteScroll} from '../components/infinite-scroll/infinite-scroll';
import {InfiniteScrollContent} from '../components/infinite-scroll/infinite-scroll-content';
import {Refresher} from '../components/refresher/refresher';
import {RefresherContent} from '../components/refresher/refresher-content';
import {Slides, Slide, SlideLazy} from '../components/slides/slides';
import {Tabs} from '../components/tabs/tabs';
import {Tab} from '../components/tabs/tab';
import {List, ListHeader} from '../components/list/list';
import {Item} from '../components/item/item';
import {ItemSliding} from '../components/item/item-sliding';
import {VirtualScroll} from '../components/virtual-scroll/virtual-scroll';
import {VirtualItem, VirtualHeader, VirtualFooter} from '../components/virtual-scroll/virtual-item';
import {Toolbar, ToolbarTitle, ToolbarItem} from '../components/toolbar/toolbar';
import {Icon} from '../components/icon/icon';
import {Spinner} from '../components/spinner/spinner';
import {Checkbox} from '../components/checkbox/checkbox';
import {Select} from '../components/select/select';
import {Option} from '../components/option/option';
import {DateTime} from '../components/datetime/datetime';
import {Toggle} from '../components/toggle/toggle';
import {TextInput, TextArea} from '../components/input/input';
import {Label} from '../components/label/label';
import {Segment, SegmentButton} from '../components/segment/segment';
import {RadioButton} from '../components/radio/radio-button';
import {RadioGroup} from '../components/radio/radio-group';
import {Searchbar, SearchbarInput} from '../components/searchbar/searchbar';
import {Nav} from '../components/nav/nav';
import {NavPush, NavPop} from '../components/nav/nav-push';
import {NavRouter} from '../components/nav/nav-router';
import {NavbarTemplate, Navbar} from '../components/navbar/navbar';
import {ShowWhen, HideWhen} from '../components/show-hide-when/show-hide-when';
/**
* @name IONIC_DIRECTIVES
* @description
* The core Ionic directives as well as Angular's `CORE_DIRECTIVES` and `FORM_DIRECTIVES` are
* available automatically when you bootstrap your app with the `@App` decorator. This means
* if you are using custom components you no longer need to import `IONIC_DIRECTIVES` as they
* are part of the `@App`s default directives.
*
* If you would like to **not** have them included by default, you would need to bootstrap
* the app differently.
*
* Instead of starting your app like so:
*
* ```typescript
* @App({
* template: "<ion-nav></ion-nav>"
* })
*
* export class MyApp{
*
* }
* ```
*
* We would use Angulars default way of bootstrap an app, import `IONIC_DIRECTIVES` and `ionicProviders`, then
* declare `ionicProviders` as a dependencey.
*
* ```typescript
* import {IONIC_DIRECTIVES, ionicProviders} from 'ionic-angular';
* import {bootstrap} from '@angular/platform/browser';
*
* @Component({
* //default selector, and theme.
* directives: [IONIC_DIRECTIVES]
* })
* class App {}
*
* bootstrap(App,ionicProviders())
* ```
*
*
*
* #### Angular
* - CORE_DIRECTIVES
* - FORM_DIRECTIVES
*
* #### Ionic
* - Menu
* - MenuToggle
* - MenuClose
* - Badge
* - Button
* - Content
* - Scroll
* - InfiniteScroll
* - InfiniteScrollContent
* - Refresher
* - RefresherContent
* - Img
* - List
* - ListHeader
* - Item
* - ItemSliding
* - VirtualScroll
* - VirtualItem
* - VirtualHeader
* - VirtualFooter
* - Slides
* - Slide
* - SlideLazy
* - Tabs
* - Tab
* - Toolbar
* - ToolbarTitle
* - ToolbarItem
* - Icon
* - Spinner
* - Searchbar
* - SearchbarInput
* - Segment
* - SegmentButton
* - Checkbox
* - RadioGroup
* - RadioButton
* - Select
* - Option
* - DateTime
* - Toggle
* - TextArea
* - TextInput
* - Label
* - Nav
* - NavbarTemplate
* - Navbar
* - NavPush
* - NavPop
* - NavRouter
* - IdRef
* - ShowWhen
* - HideWhen
*/
export const IONIC_DIRECTIVES: any[] = [
// Angular
CORE_DIRECTIVES,
FORM_DIRECTIVES,
// Content
Menu,
MenuToggle,
MenuClose,
Badge,
Button,
Content,
Scroll,
InfiniteScroll,
InfiniteScrollContent,
Refresher,
RefresherContent,
Img,
// Lists
List,
ListHeader,
Item,
ItemSliding,
VirtualScroll,
VirtualItem,
VirtualHeader,
VirtualFooter,
// Slides
Slides,
Slide,
SlideLazy,
// Tabs
Tabs,
Tab,
// Toolbar
Toolbar,
ToolbarTitle,
ToolbarItem,
// Media
Icon,
Spinner,
// Forms
Searchbar,
SearchbarInput,
Segment,
SegmentButton,
Checkbox,
RadioGroup,
RadioButton,
Select,
Option,
DateTime,
Toggle,
TextArea,
TextInput,
Label,
// Nav
Nav,
NavbarTemplate,
Navbar,
NavPush,
NavPop,
NavRouter,
ShowWhen,
HideWhen
];

122
src/config/modes.ts Normal file
View File

@@ -0,0 +1,122 @@
import {Config} from './config';
// iOS Mode Settings
Config.setModeConfig('ios', {
activator: 'highlight',
actionSheetEnter: 'action-sheet-slide-in',
actionSheetLeave: 'action-sheet-slide-out',
alertEnter: 'alert-pop-in',
alertLeave: 'alert-pop-out',
backButtonText: 'Back',
backButtonIcon: 'ios-arrow-back',
iconMode: 'ios',
loadingEnter: 'loading-pop-in',
loadingLeave: 'loading-pop-out',
menuType: 'reveal',
modalEnter: 'modal-slide-in',
modalLeave: 'modal-slide-out',
pageTransition: 'ios-transition',
pageTransitionDelay: 16,
pickerEnter: 'picker-slide-in',
pickerLeave: 'picker-slide-out',
pickerRotateFactor: -0.46,
spinner: 'ios',
tabbarPlacement: 'bottom',
toastEnter: 'toast-slide-in',
toastLeave: 'toast-slide-out',
});
// Material Design Mode Settings
Config.setModeConfig('md', {
activator: 'ripple',
actionSheetEnter: 'action-sheet-md-slide-in',
actionSheetLeave: 'action-sheet-md-slide-out',
alertEnter: 'alert-md-pop-in',
alertLeave: 'alert-md-pop-out',
backButtonText: '',
backButtonIcon: 'md-arrow-back',
iconMode: 'md',
loadingEnter: 'loading-md-pop-in',
loadingLeave: 'loading-md-pop-out',
menuType: 'overlay',
modalEnter: 'modal-md-slide-in',
modalLeave: 'modal-md-slide-out',
pageTransition: 'md-transition',
pageTransitionDelay: 96,
pickerEnter: 'picker-slide-in',
pickerLeave: 'picker-slide-out',
spinner: 'crescent',
tabbarHighlight: true,
tabbarPlacement: 'top',
tabSubPages: true,
toastEnter: 'toast-md-slide-in',
toastLeave: 'toast-md-slide-out',
});
// Windows Mode Settings
Config.setModeConfig('wp', {
activator: 'highlight',
actionSheetEnter: 'action-sheet-wp-slide-in',
actionSheetLeave: 'action-sheet-wp-slide-out',
alertEnter: 'alert-wp-pop-in',
alertLeave: 'alert-wp-pop-out',
backButtonText: '',
backButtonIcon: 'ios-arrow-back',
iconMode: 'ios',
loadingEnter: 'loading-wp-pop-in',
loadingLeave: 'loading-wp-pop-out',
menuType: 'overlay',
modalEnter: 'modal-md-slide-in',
modalLeave: 'modal-md-slide-out',
pageTransition: 'wp-transition',
pageTransitionDelay: 96,
pickerEnter: 'picker-slide-in',
pickerLeave: 'picker-slide-out',
spinner: 'circles',
tabbarPlacement: 'top',
tabSubPages: true,
toastEnter: 'toast-wp-slide-in',
toastLeave: 'toast-wp-slide-out',
});

View File

@@ -0,0 +1,565 @@
import {Config, Platform, ionicProviders} from '../../../ionic';
export function run() {
it('should set activator setting to none for old Android Browser on a linux device', () => {
let config = new Config();
let platform = new Platform();
platform.setUserAgent('Mozilla/5.0 (Linux; U; Android 4.2.2; nl-nl; GT-I9505 Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30');
platform.setNavigatorPlatform('linux');
platform.load(null);
config.setPlatform(platform);
expect(config.get('activator')).toEqual('none');
});
it('should set activator setting to ripple for Android dev tools simulation on a mac', () => {
let config = new Config();
let platform = new Platform();
platform.setUserAgent('Mozilla/5.0 (Linux; U; Android 4.2.2; nl-nl; GT-I9505 Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30');
platform.setNavigatorPlatform('MacIntel');
platform.load(null);
config.setPlatform(platform);
expect(config.get('activator')).toEqual('ripple');
});
it('should set activator setting to none for Android Chrome versions below v36 on a linux device', () => {
let config = new Config();
let platform = new Platform();
platform.setUserAgent('Mozilla/5.0 (Linux; Android 4.2.2; GT-I9505 Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1650.59 Mobile Safari/537.36');
platform.setNavigatorPlatform('linux');
platform.load(null);
config.setPlatform(platform);
expect(config.get('activator')).toEqual('none');
});
it('should set activator setting to ripple for Android Chrome v36 and above on a linux device', () => {
let config = new Config();
let platform = new Platform();
platform.setUserAgent('Mozilla/5.0 (Linux; Android 4.2.2; GT-I9505 Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1650.59 Mobile Safari/537.36');
platform.setNavigatorPlatform('linux');
platform.load(null);
config.setPlatform(platform);
expect(config.get('activator')).toEqual('ripple');
});
it('should set activator setting to ripple for Android v5.0 and above on a linux device not using Chrome', () => {
let config = new Config();
let platform = new Platform();
platform.setUserAgent('Mozilla/5.0 (Android 5.0; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0');
platform.setNavigatorPlatform('linux');
platform.load(null);
config.setPlatform(platform);
expect(config.get('activator')).toEqual('ripple');
});
it('should set activator setting to none for Android versions below v5.0 on a linux device not using Chrome', () => {
let config = new Config();
let platform = new Platform();
platform.setUserAgent('Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0');
platform.setNavigatorPlatform('linux');
platform.load(null);
config.setPlatform(platform);
expect(config.get('activator')).toEqual('none');
});
it('should create a new Config instace when no confg passed in ionicProviders', () => {
let providers = ionicProviders();
let config = providers.find(provider => provider.useValue instanceof Config).useValue;
expect(config.get('mode')).toEqual('md');
});
it('should used passed in Config instance in ionicProviders', () => {
let userConfig = new Config({
mode: 'configInstance'
})
let providers = ionicProviders({config:userConfig});
let config = providers.find(provider => provider.useValue instanceof Config).useValue;
expect(config.get('mode')).toEqual('configInstance');
});
it('should create new Config instance from config object in ionicProviders', () => {
let providers = ionicProviders({config: {
mode: 'configObj'
}});
let config = providers.find(provider => provider.useValue instanceof Config).useValue;
expect(config.get('mode')).toEqual('configObj');
});
it('should override mode settings', () => {
let config = new Config({
mode: 'md'
});
let platform = new Platform(['ios']);
config.setPlatform(platform);
expect(config.get('mode')).toEqual('md');
expect(config.get('tabbarPlacement')).toEqual('top');
});
it('should override mode settings from platforms setting', () => {
let config = new Config({
platforms: {
ios: {
mode: 'md'
}
}
});
let platform = new Platform(['ios']);
config.setPlatform(platform);
expect(config.get('mode')).toEqual('md');
expect(config.get('tabbarPlacement')).toEqual('top');
});
it('should get boolean value from querystring', () => {
let config = new Config();
let platform = new Platform();
platform.setUrl('http://biff.com/?ionicanimate=true')
config.setPlatform(platform);
expect(config.get('animate')).toEqual(true);
config = new Config();
platform = new Platform();
platform.setUrl('http://biff.com/?ionicanimate=false')
config.setPlatform(platform);
expect(config.get('animate')).toEqual(false);
});
it('should get value from case insensitive querystring key', () => {
let config = new Config({
mode: 'a'
});
let platform = new Platform();
platform.setUrl('http://biff.com/?ionicConfigKey=b')
config.setPlatform(platform);
expect(config.get('configKey')).toEqual('b');
});
it('should get value from querystring', () => {
let config = new Config({
mode: 'modeA'
});
let platform = new Platform();
platform.setUrl('http://biff.com/?ionicmode=modeB')
config.setPlatform(platform);
expect(config.get('mode')).toEqual('modeB');
});
it('should override mode platform', () => {
let config = new Config({
mode: 'modeA',
platforms: {
mobile: {
mode: 'modeB'
},
ios: {
mode: 'modeC'
}
}
});
let platform = new Platform(['mobile']);
config.setPlatform(platform);
expect(config.get('mode')).toEqual('modeB');
});
it('should override mode', () => {
let config = new Config({
mode: 'modeA'
});
let platform = new Platform(['core']);
config.setPlatform(platform);
expect(config.get('mode')).toEqual('modeA');
});
it('should get user settings after user platform settings', () => {
let config = new Config({
hoverCSS: true
});
let platform = new Platform(['ios']);
config.setPlatform(platform);
expect(config.get('hoverCSS')).toEqual(true);
});
it('should get md mode for core platform', () => {
let config = new Config();
let platform = new Platform(['core']);
config.setPlatform(platform);
expect(config.get('mode')).toEqual('md');
});
it('should get ios mode for ipad platform', () => {
let config = new Config();
let platform = new Platform(['mobile', 'ios', 'ipad', 'tablet']);
config.setPlatform(platform);
expect(config.get('mode')).toEqual('ios');
});
it('should get md mode for windows platform', () => {
let config = new Config();
let platform = new Platform(['mobile', 'windows']);
config.setPlatform(platform);
expect(config.get('mode')).toEqual('wp');
});
it('should get md mode for android platform', () => {
let config = new Config();
let platform = new Platform(['mobile', 'android']);
config.setPlatform(platform);
expect(config.get('mode')).toEqual('md');
});
it('should override ios mode config with user platform setting', () => {
let config = new Config({
tabbarPlacement: 'hide',
platforms: {
ios: {
tabbarPlacement: 'top'
}
}
});
let platform = new Platform(['ios']);
config.setPlatform(platform);
expect(config.get('tabbarPlacement')).toEqual('top');
});
it('should override ios mode config with user setting', () => {
let config = new Config({
tabbarPlacement: 'top'
});
let platform = new Platform(['ios']);
config.setPlatform(platform);
expect(config.get('tabbarPlacement')).toEqual('top');
});
it('should get setting from md mode', () => {
let config = new Config();
let platform = new Platform(['android']);
config.setPlatform(platform);
expect(config.get('tabbarPlacement')).toEqual('top');
});
it('should get setting from ios mode', () => {
let config = new Config();
let platform = new Platform(['ios']);
config.setPlatform(platform);
expect(config.get('tabbarPlacement')).toEqual('bottom');
});
it('should set/get platform setting from set()', () => {
let config = new Config();
let platform = new Platform(['ios']);
config.setPlatform(platform);
config.set('tabbarPlacement', 'bottom');
config.set('ios', 'tabbarPlacement', 'top');
expect(config.get('tabbarPlacement')).toEqual('top');
});
it('should set/get setting from set()', () => {
let config = new Config();
let platform = new Platform(['ios']);
config.setPlatform(platform);
config.set('tabbarPlacement', 'top');
expect(config.get('tabbarPlacement')).toEqual('top');
});
it('should set ios platform settings from settings()', () => {
let config = new Config();
let platform = new Platform(['ios']);
config.setPlatform(platform);
config.settings('ios', {
key: 'iosValue'
});
expect(config.get('key')).toEqual('iosValue');
});
it('should set/get mobile setting even w/ higher priority ios', () => {
let config = new Config();
let platform = new Platform(['mobile', 'ios']);
config.setPlatform(platform);
config.settings({
key: 'defaultValue',
platforms: {
mobile: {
key: 'mobileValue'
}
}
});
expect(config.get('key')).toEqual('mobileValue');
});
it('should set/get mobile setting even w/ higher priority ios', () => {
let config = new Config();
let platform = new Platform(['mobile', 'ios']);
config.setPlatform(platform);
config.settings({
key: 'defaultValue',
platforms: {
mobile: {
key: 'mobileValue'
}
}
});
expect(config.get('key')).toEqual('mobileValue');
});
it('should set/get android setting w/ higher priority than mobile', () => {
let config = new Config();
let platform = new Platform(['mobile', 'android']);
config.setPlatform(platform);
config.settings({
key: 'defaultValue',
platforms: {
mobile: {
key: 'mobileValue'
},
android: {
key: 'androidValue'
}
}
});
expect(config.get('key')).toEqual('androidValue');
});
it('should set/get ios setting w/ platforms set', () => {
let config = new Config();
let platform = new Platform(['ios']);
config.setPlatform(platform);
config.settings({
key: 'defaultValue',
platforms: {
ios: {
key: 'iosValue'
},
android: {
key: 'androidValue'
}
}
});
expect(config.get('key')).toEqual('iosValue');
});
it('should set/get default setting w/ platforms set, but no platform match', () => {
let config = new Config();
config.settings({
key: 'defaultValue',
platforms: {
ios: {
key: 'iosValue'
},
android: {
key: 'androidValue'
}
}
});
expect(config.get('key')).toEqual('defaultValue');
});
it('should set setting object', () => {
let config = new Config();
config.settings({
name: 'Doc Brown',
occupation: 'Weather Man'
});
expect(config.get('name')).toEqual('Doc Brown');
expect(config.get('name')).toEqual('Doc Brown');
expect(config.get('occupation')).toEqual('Weather Man');
expect(config.get('occupation')).toEqual('Weather Man');
});
it('should get null setting', () => {
let config = new Config();
expect(config.get('name')).toEqual(null);
expect(config.get('name')).toEqual(null);
expect(config.get('occupation')).toEqual(null);
expect(config.get('occupation')).toEqual(null);
});
it('should set/get single setting', () => {
let config = new Config();
config.set('name', 'Doc Brown');
config.set('occupation', 'Weather Man');
expect(config.get('name')).toEqual('Doc Brown');
expect(config.get('name')).toEqual('Doc Brown');
expect(config.get('occupation')).toEqual('Weather Man');
expect(config.get('occupation')).toEqual('Weather Man');
});
it('should init w/ given config settings', () => {
let config = new Config({
name: 'Doc Brown',
occupation: 'Weather Man'
});
expect(config.get('name')).toEqual('Doc Brown');
expect(config.get('occupation')).toEqual('Weather Man');
});
it('should get a fallback value', () => {
let config = new Config({
name: 'Doc Brown'
});
expect(config.get('name', 'Marty')).toEqual('Doc Brown');
expect(config.get('occupation', 'Weather Man')).toEqual('Weather Man');
});
it('should get a boolean value with a boolean config value', () => {
let config = new Config({
key1: true,
key2: false
});
expect(config.getBoolean('key1')).toEqual(true);
expect(config.getBoolean('key2')).toEqual(false);
});
it('should get a boolean value with a string config value', () => {
let config = new Config({
key1: 'true',
key2: 'false',
key3: 'whatever'
});
expect(config.getBoolean('key1')).toEqual(true);
expect(config.getBoolean('key2')).toEqual(false);
expect(config.getBoolean('key3')).toEqual(false);
expect(config.getBoolean('key4')).toEqual(false);
expect(config.getBoolean('key5', true)).toEqual(true);
});
it('should get a boolean value with a number config value', () => {
let config = new Config({
key1: 0,
key2: 1,
key3: 'whatever'
});
expect(config.getBoolean('key1')).toEqual(false);
expect(config.getBoolean('key2')).toEqual(true);
});
it('should get a number value with a number config value', () => {
let config = new Config({
key: 6
});
expect(config.getNumber('key')).toEqual(6);
});
it('should get a number value with a string config value', () => {
let config = new Config({
key: '6',
numThenString: '6baymax',
stringThenNum: 'baymax6'
});
expect(config.getNumber('key', 5)).toEqual(6);
expect(config.getNumber('numThenString', 4)).toEqual(6);
expect( isNaN(config.getNumber('stringThenNum')) ).toEqual(true);
});
it('should get a number NaN value with a NaN config value', () => {
let config = new Config({
allString: 'allstring',
imNull: null,
imUndefined: undefined
});
expect( isNaN(config.getNumber('notfound'))).toEqual(true);
expect( isNaN(config.getNumber('allString'))).toEqual(true);
expect( isNaN(config.getNumber('imNull'))).toEqual(true);
expect( isNaN(config.getNumber('imUndefined'))).toEqual(true);
});
it('should get a number fallback value with a NaN config value', () => {
let config = new Config({
allString: 'allstring',
imNull: null,
imUndefined: undefined
});
expect( config.getNumber('notfound', 6)).toEqual(6);
expect( config.getNumber('allString', 6)).toEqual(6);
expect( config.getNumber('imNull', 6)).toEqual(6);
expect( config.getNumber('imUndefined', 6)).toEqual(6);
});
it('should get settings object', () => {
let config = new Config({
name: 'Doc Brown',
occupation: 'Weather Man'
});
expect(config.settings()).toEqual({
name: 'Doc Brown',
occupation: 'Weather Man'
});
});
it('should create default config w/ bad settings value', () => {
let config = new Config(null);
expect(config.settings()).toEqual({});
config = new Config(undefined);
expect(config.settings()).toEqual({});
config = new Config();
expect(config.settings()).toEqual({});
config = new Config([1,2,3]);
expect(config.settings()).toEqual({});
config = new Config('im bad, you know it');
expect(config.settings()).toEqual({});
config = new Config(8675309);
expect(config.settings()).toEqual({});
config = new Config(true);
expect(config.settings()).toEqual({});
config = new Config(false);
expect(config.settings()).toEqual({});
config = new Config(1);
expect(config.settings()).toEqual({});
config = new Config(function(){});
expect(config.settings()).toEqual({});
});
}