diff --git a/demo/src/app/app.component.ts b/demo/src/app/app.component.ts index 796df47cc4..f0c732b8ec 100644 --- a/demo/src/app/app.component.ts +++ b/demo/src/app/app.component.ts @@ -1,28 +1,24 @@ -import { AfterContentInit, Component, ViewContainerRef } from '@angular/core'; +import { AfterContentInit, Component } from '@angular/core'; import { NavigationEnd, Router } from '@angular/router'; - -import { Ng2BootstrapConfig, Ng2BootstrapTheme } from 'ng2-bootstrap'; - -let w:any = window; - -if (w && w.__theme === 'bs4') { - Ng2BootstrapConfig.theme = Ng2BootstrapTheme.BS4; -} +import { isBs3 } from 'ng2-bootstrap'; @Component({ selector: 'bs-demo', templateUrl: './app.component.html' }) export class AppComponent implements AfterContentInit { - public isBs3:boolean = Ng2BootstrapConfig.theme === Ng2BootstrapTheme.BS3; + public get isBs3(): boolean { + return isBs3(); + } + + private router: Router; - private router:Router; - public constructor(router:Router) { + public constructor(router: Router) { this.router = router; } - public ngAfterContentInit():any { - this.router.events.subscribe((event:any) => { + public ngAfterContentInit(): any { + this.router.events.subscribe((event: any) => { if (event instanceof NavigationEnd) { if (typeof PR !== 'undefined') { // google code-prettify diff --git a/demo/src/app/common/main-menu/main-menu.component.ts b/demo/src/app/common/main-menu/main-menu.component.ts index 601a5faefe..f319107548 100644 --- a/demo/src/app/common/main-menu/main-menu.component.ts +++ b/demo/src/app/common/main-menu/main-menu.component.ts @@ -1,7 +1,6 @@ import { Component } from '@angular/core'; import { NavigationEnd, Router } from '@angular/router'; - -import { Ng2BootstrapConfig, Ng2BootstrapTheme } from 'ng2-bootstrap'; +import { isBs3 } from 'ng2-bootstrap'; import { routes } from '../../app.routing'; @Component({ @@ -9,16 +8,20 @@ import { routes } from '../../app.routing'; templateUrl: './main-menu.component.html' }) export class MainMenuComponent { - public isBs3:boolean = Ng2BootstrapConfig.theme === Ng2BootstrapTheme.BS3; - public routes:any = routes; - public search:any = {}; - public hash:string = ''; + public get isBs3(): boolean { + return isBs3(); + } + + public routes: any = routes; + public search: any = {}; + public hash: string = ''; private router: Router; - public constructor(router:Router) { + + public constructor(router: Router) { this.router = router; - this.routes = this.routes.filter((v:any) => v.path !== '**'); - this.router.events.subscribe((event:any) => { + this.routes = this.routes.filter((v: any) => v.path !== '**'); + this.router.events.subscribe((event: any) => { if (event instanceof NavigationEnd) { this.hash = event.url; } diff --git a/demo/src/app/components/progressbar/demos/progressbar-demo.component.ts b/demo/src/app/components/progressbar/demos/progressbar-demo.component.ts index 00ec1a0c6d..1c01deb4f5 100644 --- a/demo/src/app/components/progressbar/demos/progressbar-demo.component.ts +++ b/demo/src/app/components/progressbar/demos/progressbar-demo.component.ts @@ -1,6 +1,6 @@ import { Component } from '@angular/core'; -import { Ng2BootstrapConfig, Ng2BootstrapTheme } from 'ng2-bootstrap'; +import { isBs3 } from 'ng2-bootstrap'; @Component({ selector: 'progressbar-demo', @@ -13,7 +13,7 @@ export class ProgressbarDemoComponent { public type: string; public stacked: any[] = []; public get isBs3(): boolean { - return Ng2BootstrapConfig.theme === Ng2BootstrapTheme.BS3; + return isBs3(); } public constructor() { diff --git a/demo/src/app/components/progressbar/progressbar-section.component.ts b/demo/src/app/components/progressbar/progressbar-section.component.ts index f8f0bb8f07..a4ef6dba93 100644 --- a/demo/src/app/components/progressbar/progressbar-section.component.ts +++ b/demo/src/app/components/progressbar/progressbar-section.component.ts @@ -1,6 +1,5 @@ import { Component } from '@angular/core'; - -import { Ng2BootstrapConfig, Ng2BootstrapTheme } from 'ng2-bootstrap'; +import { isBs3 } from 'ng2-bootstrap'; // webpack html imports let doc = require('html!markdown!./docs/readme.md'); @@ -8,13 +7,11 @@ let titleDoc = require('html!markdown!./docs/title.md'); let ts = require('!!raw?lang=typescript!./demos/progressbar-demo.component.ts'); -let templates:any = { - [Ng2BootstrapTheme.BS3]: require('!!raw?lang=markup!./demos/progressbar-demo-bs3.component.html'), - [Ng2BootstrapTheme.BS4]: require('!!raw?lang=markup!./demos/progressbar-demo-bs4.component.html') +let templates: any = { + 'bs3': require('!!raw?lang=markup!./demos/progressbar-demo-bs3.component.html'), + 'bs4': require('!!raw?lang=markup!./demos/progressbar-demo-bs4.component.html') }; -let html = templates[Ng2BootstrapConfig.theme]; - @Component({ selector: 'progressbar-section', template: ` @@ -23,10 +20,12 @@ let html = templates[Ng2BootstrapConfig.theme]; ` }) export class ProgressbarSectionComponent { - public name:string = 'Progressbar'; - public src:string = 'https://github.com/valor-software/ng2-bootstrap/blob/master/components/progressbar'; - public html:string = html; - public ts:string = ts; - public titleDoc:string = titleDoc; - public doc:string = doc; + public name: string = 'Progressbar'; + public src: string = 'https://github.com/valor-software/ng2-bootstrap/blob/master/components/progressbar'; + public get html(): string { + return isBs3() ? templates.bs3 : templates.bs4; + } + public ts: string = ts; + public titleDoc: string = titleDoc; + public doc: string = doc; } diff --git a/package.json b/package.json index 8324b1fb91..d2f6093b2d 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "chokidar-cli": "1.2.0", "classlist-polyfill": "1.0.3", "codecov": "1.0.1", - "codelyzer": "^2.0.0-beta.1", + "codelyzer": "^2.0.0-beta.3", "conventional-changelog-cli": "1.2.0", "conventional-github-releaser": "1.1.3", "core-js": "2.4.1", diff --git a/src/carousel/carousel.component.ts b/src/carousel/carousel.component.ts index 40bbca54ef..15f686889c 100644 --- a/src/carousel/carousel.component.ts +++ b/src/carousel/carousel.component.ts @@ -2,7 +2,7 @@ import { Component, Input, OnDestroy } from '@angular/core'; -import { Ng2BootstrapConfig, Ng2BootstrapTheme } from '../utils/ng2-bootstrap-config'; +import { isBs3 } from '../utils/ng2-bootstrap-config'; import { SlideComponent } from './slide.component'; export enum Direction {UNKNOWN, NEXT, PREV} @@ -58,7 +58,7 @@ export class CarouselComponent implements OnDestroy { protected _interval:number; public get isBS4():boolean { - return Ng2BootstrapConfig.theme === Ng2BootstrapTheme.BS4; + return !isBs3(); } public ngOnDestroy():void { diff --git a/src/datepicker/daypicker.component.ts b/src/datepicker/daypicker.component.ts index f87cbd6d41..4af68982b6 100644 --- a/src/datepicker/daypicker.component.ts +++ b/src/datepicker/daypicker.component.ts @@ -1,15 +1,14 @@ import { Component, OnInit } from '@angular/core'; - -import { Ng2BootstrapConfig, Ng2BootstrapTheme } from '../utils/ng2-bootstrap-config'; +import { isBs3 } from '../utils/ng2-bootstrap-config'; import { DatePickerInnerComponent } from './datepicker-inner.component'; // write an interface for template options -const TEMPLATE_OPTIONS:any = { - [Ng2BootstrapTheme.BS4]: { +const TEMPLATE_OPTIONS: any = { + 'bs4': { ARROW_LEFT: '<', ARROW_RIGHT: '>' }, - [Ng2BootstrapTheme.BS3]: { + 'bs3': { ARROW_LEFT: ` `, @@ -81,31 +80,34 @@ const TEMPLATE_OPTIONS:any = { }) export class DayPickerComponent implements OnInit { - public labels:any[] = []; - public title:string; - public rows:any[] = []; - public weekNumbers:number[] = []; - public datePicker:DatePickerInnerComponent; - public CURRENT_THEME_TEMPLATE:any = TEMPLATE_OPTIONS[Ng2BootstrapConfig.theme || Ng2BootstrapTheme.BS3]; - - public constructor(datePicker:DatePickerInnerComponent) { + public labels: any[] = []; + public title: string; + public rows: any[] = []; + public weekNumbers: number[] = []; + public datePicker: DatePickerInnerComponent; + public CURRENT_THEME_TEMPLATE: any; + + public constructor(datePicker: DatePickerInnerComponent) { + this.CURRENT_THEME_TEMPLATE = isBs3() + ? TEMPLATE_OPTIONS.bs3 + : TEMPLATE_OPTIONS.bs4; this.datePicker = datePicker; } - public get isBS4():boolean { - return Ng2BootstrapConfig.theme === Ng2BootstrapTheme.BS4; + public get isBS4(): boolean { + return !isBs3(); } /*protected getDaysInMonth(year:number, month:number) { return ((month === 1) && (year % 4 === 0) && ((year % 100 !== 0) || (year % 400 === 0))) ? 29 : DAYS_IN_MONTH[month]; }*/ - public ngOnInit():void { + public ngOnInit(): void { let self = this; this.datePicker.stepDay = {months: 1}; - this.datePicker.setRefreshViewHandler(function ():void { + this.datePicker.setRefreshViewHandler(function (): void { let year = this.activeDate.getFullYear(); let month = this.activeDate.getMonth(); let firstDayOfMonth = new Date(year, month, 1); @@ -120,8 +122,8 @@ export class DayPickerComponent implements OnInit { } // 42 is the number of days on a six-week calendar - let _days:Date[] = self.getDates(firstDate, 42); - let days:any[] = []; + let _days: Date[] = self.getDates(firstDate, 42); + let days: any[] = []; for (let i = 0; i < 42; i++) { let _dateObject = this.createDateObject(_days[i], this.formatDay); _dateObject.secondary = _days[i].getMonth() !== month; @@ -149,7 +151,7 @@ export class DayPickerComponent implements OnInit { } }, 'day'); - this.datePicker.setCompareHandler(function (date1:Date, date2:Date):number { + this.datePicker.setCompareHandler(function (date1: Date, date2: Date): number { let d1 = new Date(date1.getFullYear(), date1.getMonth(), date1.getDate()); let d2 = new Date(date2.getFullYear(), date2.getMonth(), date2.getDate()); return d1.getTime() - d2.getTime(); @@ -158,11 +160,11 @@ export class DayPickerComponent implements OnInit { this.datePicker.refreshView(); } - protected getDates(startDate:Date, n:number):Date[] { - let dates:Date[] = new Array(n); + protected getDates(startDate: Date, n: number): Date[] { + let dates: Date[] = new Array(n); let current = new Date(startDate.getTime()); let i = 0; - let date:Date; + let date: Date; while (i < n) { date = new Date(current.getTime()); date = this.datePicker.fixTimeZone(date); @@ -172,7 +174,7 @@ export class DayPickerComponent implements OnInit { return dates; } - protected getISO8601WeekNumber(date:Date):number { + protected getISO8601WeekNumber(date: Date): number { let checkDate = new Date(date.getTime()); // Thursday checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7)); diff --git a/src/datepicker/monthpicker.component.ts b/src/datepicker/monthpicker.component.ts index 7e8d557b62..a1f9293558 100644 --- a/src/datepicker/monthpicker.component.ts +++ b/src/datepicker/monthpicker.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; -import { Ng2BootstrapConfig, Ng2BootstrapTheme } from '../utils/ng2-bootstrap-config'; +import { isBs3 } from '../utils/ng2-bootstrap-config'; import { DatePickerInnerComponent } from './datepicker-inner.component'; @Component({ @@ -57,7 +57,7 @@ export class MonthPickerComponent implements OnInit { } public get isBS4():boolean { - return Ng2BootstrapConfig.theme === Ng2BootstrapTheme.BS4; + return !isBs3(); } public ngOnInit():void { diff --git a/src/datepicker/yearpicker.component.ts b/src/datepicker/yearpicker.component.ts index cf1866b24b..a0a72b901b 100644 --- a/src/datepicker/yearpicker.component.ts +++ b/src/datepicker/yearpicker.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; -import { Ng2BootstrapConfig, Ng2BootstrapTheme } from '../utils/ng2-bootstrap-config'; +import { isBs3 } from '../utils/ng2-bootstrap-config'; import { DatePickerInnerComponent } from './datepicker-inner.component'; @Component({ @@ -57,7 +57,7 @@ export class YearPickerComponent implements OnInit { } public get isBS4():boolean { - return Ng2BootstrapConfig.theme === Ng2BootstrapTheme.BS4; + return !isBs3(); } public ngOnInit():void { diff --git a/src/typeahead/typeahead-container.component.ts b/src/typeahead/typeahead-container.component.ts index de08a15fdd..16fabb6ced 100644 --- a/src/typeahead/typeahead-container.component.ts +++ b/src/typeahead/typeahead-container.component.ts @@ -1,12 +1,39 @@ -import { Component, ElementRef, TemplateRef, ViewEncapsulation } from '@angular/core'; - -import { Ng2BootstrapConfig, Ng2BootstrapTheme } from '../utils/ng2-bootstrap-config'; +import { + Component, ElementRef, TemplateRef, ViewEncapsulation +} from '@angular/core'; +import { isBs3 } from '../utils/ng2-bootstrap-config'; import { TypeaheadUtils } from './typeahead-utils'; import { TypeaheadDirective } from './typeahead.directive'; import { TypeaheadMatch } from './typeahead-match.class'; -const bs4 = ` -