Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @inheritdoc #2943

Merged
merged 17 commits into from
Dec 6, 2018
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions projects/igniteui-angular/src/lib/services/overlay/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class IgxOverlayService implements OnDestroy {
*/
// tslint:disable-next-line:unified-signatures
show(component: ElementRef | Type<{}>, settings?: OverlaySettings): string;
show(compOrId: string | ElementRef | Type<{}> , settings?: OverlaySettings): string {
show(compOrId: string | ElementRef | Type<{}>, settings?: OverlaySettings): string {
let info: OverlayInfo;
let id: string;
if (typeof compOrId === 'string') {
Expand Down Expand Up @@ -155,7 +155,8 @@ export class IgxOverlayService implements OnDestroy {
// opening. Otherwise, if there is close animation player playing animation now we should not setup
// overlay this is already done
if (!info.closeAnimationPlayer || (info.closeAnimationPlayer && !info.closeAnimationPlayer.hasStarted())) {
info.initialSize = info.elementRef.nativeElement.getBoundingClientRect();
const elementRect = info.elementRef.nativeElement.getBoundingClientRect();
info.initialSize = { width: elementRect.width, height: elementRect.height };
info.hook = this.placeElementHook(info.elementRef.nativeElement);

this.moveElementToOverlay(info);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { PositionSettings } from './../utilities';
* Position strategies determine where to display the component in the provided IgxOverlayService.
*/
export interface IPositionStrategy {
/**
* PositionSettings to use when position the component in the overlay
*/
settings: PositionSettings;

/**
Expand All @@ -17,5 +20,5 @@ export interface IPositionStrategy {
* settings.positionStrategy.position(content, size, document, true);
* ```
*/
position(contentElement: HTMLElement, size?: {}, document?: Document, initialCall?: boolean): void;
position(contentElement: HTMLElement, size?: { width: number, height: number }, document?: Document, initialCall?: boolean): void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work because the size parameter is a object and when the comparison between the parameters came the objects would have different references which respectively means that the parameters are not equal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Now we have Size interface and position method accepts Size parameter.

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ enum Axis {
export class AutoPositionStrategy extends ConnectedPositioningStrategy implements IPositionStrategy {
public offsetPadding = 16;
private _initialSettings;

getViewPort(document) { // Material Design implementation
const clientRect = document.documentElement.getBoundingClientRect();
const scrollPosition = {
Expand All @@ -29,9 +30,9 @@ export class AutoPositionStrategy extends ConnectedPositioningStrategy implement

}


// The position method should return a <div> container that will host the component
position(contentElement: HTMLElement, size: { width: number, height: number }, document?: Document, initialCall?: boolean): void {
/** @inheritdoc */
position(contentElement: HTMLElement, size?: { width: number, height: number }, document?: Document, initialCall?: boolean): void {
if (!initialCall) {
super.position(contentElement, size);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ export class ConnectedPositioningStrategy implements IPositionStrategy {
closeAnimation: scaleOutVerTop
};

/** @inheritdoc */
public settings: PositionSettings;

constructor(settings?: PositionSettings) {
this.settings = Object.assign({}, this._defaultSettings, settings);
}

// we no longer use the element inside the position() as its dimensions are cached in rect
position(contentElement: HTMLElement, size: { width: number, height: number}, document?: Document, initialCall?: boolean): void {
/** @inheritdoc */
position(contentElement: HTMLElement, size?: { width: number, height: number }, document?: Document, initialCall?: boolean): void {
const startPoint = getPointFromPositionsSettings(this.settings, contentElement.parentElement);

contentElement.style.top = startPoint.y + this.settings.verticalDirection * size.height + 'px';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ export class GlobalPositionStrategy implements IPositionStrategy {
closeAnimation: fadeOut
};

/** @inheritdoc */
public settings: PositionSettings;

constructor(settings?: PositionSettings) {
this.settings = Object.assign({}, this._defaultSettings, settings);
}

position(contentElement: HTMLElement, size?: { width: number, height: number}, document?: Document, initialCall?: boolean): void {
/** @inheritdoc */
position(contentElement: HTMLElement, size?: { width: number, height: number }, document?: Document, initialCall?: boolean): void {
switch (this.settings.horizontalDirection) {
case HorizontalAlignment.Left:
contentElement.parentElement.style.justifyContent = 'flex-start';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { IgxOverlayService } from '../overlay';
* [Documentation](https://www.infragistics.com/products/ignite-ui-angular/angular/components/overlay_scroll.html).
* Scroll strategies determines how the scrolling will be handled in the provided IgxOverlayService.
*/
export class IScrollStrategy {
constructor(scrollContainer?: HTMLElement) { }

export interface IScrollStrategy {
/**
* Initializes the strategy. Should be called once
* @param document reference to Document object.
Expand All @@ -15,21 +13,21 @@ export class IScrollStrategy {
* settings.scrollStrategy.initialize(document, overlay, id);
* ```
*/
initialize(document: Document, overlayService: IgxOverlayService, id: string) { }
initialize(document: Document, overlayService: IgxOverlayService, id: string);

/**
* Attaches the strategy
* ```typescript
* settings.scrollStrategy.attach();
* ```
*/
attach(): void { }
attach(): void;

/**
* Detaches the strategy
* ```typescript
* settings.scrollStrategy.detach();
* ```
*/
detach(): void { }
detach(): void;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { IScrollStrategy } from './IScrollStrategy';
import { IgxOverlayService } from '../overlay';
import { ScrollStrategy } from './scroll-strategy';

export class NoOpScrollStrategy implements IScrollStrategy {
constructor(scrollContainer?: HTMLElement) { }
initialize(document: Document, overlayService: IgxOverlayService, id: string) {}
export class NoOpScrollStrategy extends ScrollStrategy {
constructor(scrollContainer?: HTMLElement) {
super(scrollContainer);
}
/** @inheritdoc */
public initialize(document: Document, overlayService: IgxOverlayService, id: string) { }

/** @inheritdoc */
attach(): void { }

/** @inheritdoc */
detach(): void { }
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { IScrollStrategy } from './IScrollStrategy';
import { IgxOverlayService } from '../overlay';
import { ScrollStrategy } from './scroll-strategy';

export class AbsoluteScrollStrategy implements IScrollStrategy {
export class AbsoluteScrollStrategy extends ScrollStrategy {
private _initialized = false;
private _document: Document;
private _overlayService: IgxOverlayService;
private _id: string;
private _scrollContainer: HTMLElement;

constructor(scrollContainer?: HTMLElement) {
super(scrollContainer);
this._scrollContainer = scrollContainer;
}

initialize(document: Document, overlayService: IgxOverlayService, id: string) {
/** @inheritdoc */
public initialize(document: Document, overlayService: IgxOverlayService, id: string) {
if (this._initialized) {
return;
}
Expand All @@ -22,15 +24,17 @@ export class AbsoluteScrollStrategy implements IScrollStrategy {
this._initialized = true;
}

attach(): void {
/** @inheritdoc */
public attach(): void {
if (this._scrollContainer) {
this._scrollContainer.addEventListener('scroll', this.onScroll, true);
} else {
this._document.addEventListener('scroll', this.onScroll, true);
}
}

detach(): void {
/** @inheritdoc */
public detach(): void {
if (this._scrollContainer) {
this._scrollContainer.removeEventListener('scroll', this.onScroll, true);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { IScrollStrategy } from './IScrollStrategy';
import { IgxOverlayService } from '../overlay';
import { ScrollStrategy } from './scroll-strategy';

export class BlockScrollStrategy implements IScrollStrategy {
export class BlockScrollStrategy extends ScrollStrategy {
private _initialized = false;
private _document: Document;
private _initialScrollTop: number;
private _initialScrollLeft: number;
private _sourceElement: Element;

constructor(scrollContainer?: HTMLElement) { }
constructor(scrollContainer?: HTMLElement) {
super(scrollContainer);
}

initialize(document: Document, overlayService: IgxOverlayService, id: string) {
/** @inheritdoc */
public initialize(document: Document, overlayService: IgxOverlayService, id: string) {
if (this._initialized) {
return;
}
Expand All @@ -19,11 +22,13 @@ export class BlockScrollStrategy implements IScrollStrategy {
this._initialized = true;
}

/** @inheritdoc */
public attach(): void {
this._document.addEventListener('scroll', this.onScroll, true);
this._document.addEventListener('wheel', this.onWheel, true);
}

/** @inheritdoc */
public detach(): void {
this._document.removeEventListener('scroll', this.onScroll, true);
this._document.removeEventListener('wheel', this.onWheel, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IScrollStrategy } from './IScrollStrategy';
import { IgxOverlayService } from '../overlay';
import { ScrollStrategy } from './scroll-strategy';

export class CloseScrollStrategy implements IScrollStrategy {
export class CloseScrollStrategy extends ScrollStrategy {
private _document: Document;
private _overlayService: IgxOverlayService;
private _id: string;
Expand All @@ -15,13 +15,15 @@ export class CloseScrollStrategy implements IScrollStrategy {
private _scrollContainer: HTMLElement;

constructor(scrollContainer?: HTMLElement) {
super(scrollContainer);
this._scrollContainer = scrollContainer;
this._threshold = 10;
this.cumulativeScrollTop = 0;
this.cumulativeScrollLeft = 0;
}

initialize(document: Document, overlayService: IgxOverlayService, id: string) {
/** @inheritdoc */
public initialize(document: Document, overlayService: IgxOverlayService, id: string) {
if (this._initialized) {
return;
}
Expand All @@ -31,7 +33,8 @@ export class CloseScrollStrategy implements IScrollStrategy {
this._initialized = true;
}

attach(): void {
/** @inheritdoc */
public attach(): void {
if (this._scrollContainer) {
this._scrollContainer.addEventListener('scroll', this.onScroll);
this._sourceElement = this._scrollContainer;
Expand All @@ -54,7 +57,8 @@ export class CloseScrollStrategy implements IScrollStrategy {
this.initialScrollLeft = this._sourceElement.scrollLeft;
}

detach(): void {
/** @inheritdoc */
public detach(): void {
// TODO: check why event listener removes only on first call and remains on each next!!!
if (this._scrollContainer) {
this._scrollContainer.removeEventListener('scroll', this.onScroll);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

// Export scroll strategies
export * from './scroll-strategy';
export * from './IScrollStrategy';
export * from './absolute-scroll-strategy';
export * from './block-scroll-strategy';
export * from './close-scroll-strategy';
export * from './IScrollStrategy';
export * from './NoOpScrollStrategy';

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { IScrollStrategy } from './IScrollStrategy';
import { IgxOverlayService } from '../overlay';

export abstract class ScrollStrategy implements IScrollStrategy {
constructor(scrollContainer?: HTMLElement) { }
/** @inheritdoc */
abstract initialize(document: Document, overlayService: IgxOverlayService, id: string);

/** @inheritdoc */
abstract attach(): void;

/** @inheritdoc */
abstract detach(): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export interface OverlayInfo {
elementRef?: ElementRef;
componentRef?: ComponentRef<{}>;
settings?: OverlaySettings;
initialSize?: { width?: number, height?: number, x?: number, y?: number };
initialSize?: { width: number, height: number };
hook?: HTMLElement;
openAnimationPlayer?: AnimationPlayer;
closeAnimationPlayer?: AnimationPlayer;
Expand Down
Loading