All files / src/angular directive-inview.ts

0% Statements 0/8
0% Branches 0/8
0% Functions 0/5
0% Lines 0/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79                                                                                                                                                             
import {Inview} from '../dom/inview';
 
export class InviewController {
  // The root element to determine visibility.
  private element: HTMLElement;
  private inview: Inview;
  static get $inject() {
    return ['$scope', '$element'];
  }
 
  constructor($scope: ng.IScope, $element: ng.IAugmentedJQuery) {
    this.element = $element[0];
 
    this.inview = new Inview({
      element: this.element,
      childSelector: this.element.getAttribute('inview-selector') || undefined,
      elementBaseline:
        +this.element.getAttribute('inview-element-baseline')! || undefined,
      viewportOffset:
        +this.element.getAttribute('inview-viewport-offset')! || undefined,
      // outviewOnlyOnElementExit: true
      downOnlyMode: true,
    });
 
    $scope.$on('$destroy', () => {
      this.dispose();
    });
  }
 
  dispose() {
    this.inview && this.inview.dispose();
  }
}
 
/**
 * A simple inview directive.  This is based on dom/Inview.
 *
 *
 * # Basic inview
 * ```
 * <div inview></div>
 *
 * when inview:
 * <div inview class="in"></div>
 * ```
 *
 *
 * # Settings
 * Shifting position.
 * <div inview inview-element-baseline="0" inview-viewport-offset="0.25"></div>
 *
 *
 * # Child Selectors
 * Use target selectors to add inview to child elements.
 * Note that the element used to determine inview state is still
 * the root inview directive element.
 * ```
 * <div inview inview-selector="[add-inview]">
 *   <div add-inview>my title</div>
 *   <div add-inview>body</div>
 * </div>
 *
 * when inview:
 *
 * <div inview inview-selector="[add-inview]">
 *   <div add-inview class="in" inview-number="0">my title</div>
 *   <div add-inview class="in" inview-number="1">body</div>
 * </div>
 * ```
 *
 *
 */
export const inviewDirective = function () {
  return {
    restrict: 'A',
    controller: InviewController,
  };
};