Guest User

Untitled

a guest
Nov 19th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. // Import the core angular services.
  2. import { Component } from "@angular/core";
  3.  
  4. // Import the application components and services.
  5. import { WindowScrolling } from "./window-scrolling";
  6.  
  7. // ----------------------------------------------------------------------------------- //
  8. // ----------------------------------------------------------------------------------- //
  9.  
  10. @Component({
  11. selector: "my-app",
  12. styleUrls: [ "./app.component.less" ],
  13. template:
  14. `
  15. <p>
  16. <a (click)="toggleModal()" class="open">Open Modal Window</a>
  17. </p>
  18.  
  19. <div *ngIf="isShowingModal" class="modal">
  20. <div class="modal__content">
  21.  
  22. This is a modal &mdash; <a (click)="toggleModal()">Close the modal</a>
  23.  
  24. </div>
  25. </div>
  26.  
  27. <p *ngFor="let i of offsets">
  28. This is paragraph 1-{{ i }}.
  29. </p>
  30.  
  31. <p>
  32. <a (click)="toggleModal()" class="open">Open Modal Window</a>
  33. </p>
  34.  
  35. <p *ngFor="let i of offsets">
  36. This is paragraph 2-{{ i }}.
  37. </p>
  38.  
  39. <p>
  40. <a (click)="toggleModal()" class="open">Open Modal Window</a>
  41. </p>
  42. `
  43. })
  44. export class AppComponent {
  45.  
  46. public isShowingModal: boolean;
  47. public offsets: number[];
  48.  
  49. private windowScrolling: WindowScrolling;
  50.  
  51. // I initialize the app component.
  52. constructor( windowScrolling: WindowScrolling ) {
  53.  
  54. this.windowScrolling = windowScrolling;
  55. this.offsets = this.range( 1, 20 );
  56.  
  57. }
  58.  
  59. // ---
  60. // PUBLIC METHODS.
  61. // ---
  62.  
  63. // I open or close the modal window.
  64. public toggleModal() : void {
  65.  
  66. // When we open the modal window, we want to prevent scrolling on the main
  67. // document. This way, if the user can scroll within the modal window, the
  68. // scroll will never bleed into the body context.
  69. if ( this.isShowingModal = ! this.isShowingModal ) {
  70.  
  71. this.windowScrolling.disable();
  72.  
  73. } else {
  74.  
  75. this.windowScrolling.enable();
  76.  
  77. }
  78.  
  79. }
  80.  
  81. // ---
  82. // PRIVATE METHODS.
  83. // ---
  84.  
  85. // I build an increasing range for the given numbers, inclusive.
  86. private range( from: number, to: number ) : number[] {
  87.  
  88. var values = [];
  89.  
  90. for ( var i = from ; i <= to ; i++ ) {
  91.  
  92. values.push( i );
  93.  
  94. }
  95.  
  96. return( values );
  97.  
  98. }
  99.  
  100. }
Add Comment
Please, Sign In to add comment