All files / src/angular directive-lottie-button.ts

0% Statements 0/12
0% Branches 0/4
0% Functions 0/5
0% Lines 0/12

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                                                                                                                                                         
import {LottieButton, type LottieButtonRange} from '../dom/lottie-button';
 
class LottieButtonController {
  static get $inject() {
    return ['$scope', '$element'];
  }
  private el: HTMLElement;
  private $scope: ng.IScope;
  private lottieButton: LottieButton;
 
  constructor($scope: ng.IScope, $element: ng.IAugmentedJQuery) {
    this.$scope = $scope;
    this.el = $element[0];
 
    const playSettings = JSON.parse(
      this.el.getAttribute('lottie-play-settings')!
    ) as Record<string, LottieButtonRange | boolean>;
 
    this.lottieButton = new LottieButton({
      rootElement: this.el,
      lottieElement: this.el.querySelector('[lottie-element]')!,
      lottieJson: this.el.getAttribute('lottie-json-path')!,
      inview: playSettings.inview as LottieButtonRange,
      click: playSettings.click as LottieButtonRange,
      mouseleave: playSettings.mouseleave as LottieButtonRange,
      mouseenter: playSettings.mouseenter as LottieButtonRange,
      noListeners: (playSettings.noListeners as boolean) || false,
      loadImmediately: this.el.getAttribute('lottie-load-immediate') === 'true',
    });
 
    if (this.el.getAttribute('lottie-enable-play-queue')) {
      this.lottieButton.enablePlayQueue(true);
    }
 
    $scope.$on('$destroy', () => {
      this.dispose();
    });
  }
 
  private dispose(): void {
    this.lottieButton.dispose();
  }
}
 
/**
 * ```
 *   import { lottieButtonDirective } from 'degu/lib/angular/directive-lottie-button';
 *   app.directive('lottieButton', lottieButtonDirective);
 *
 *
 * {% set playSettings = {
 *    'mouseover': {
 *       'start': 72,
 *       'end': 96,
 *    },
 *    'mouseleave': {
 *       'start': 156,
 *       'end': 180,
 *   },
 *    'click': {
 *       'start': 196,
 *       'end': 216,
 *   },
 * }
 * %}
 * <div lottie-button lottie-json-path="{{lottie_json_path}}" lottie-play-settings="{{playSettings|jsonify}}">
 *        <div lottie-element></div>
 * </div>
 * ```
 */
export const lottieButtonDirective = () => {
  return {
    restrict: 'A',
    controller: LottieButtonController,
  };
};