# all files / app/components/malarkey/ malarkey.directive.js

100% Statements 27/27
100% Branches 0/0
100% Functions 12/12
100% Lines 27/27

    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
    761×

    1×

    1×
    3×

    3×

    1×
    3×
    3×

    3×

    3×
    6×

    3×
    3×
    18×

    3×
    3×

    1×
    3×

    3×

    3×

    1×
    3×
    3×

    1×
    3×
    3×

    3×

     (function() {
      'use strict';

      angular
        .module('avalikjoodik')
        .directive('acmeMalarkey', acmeMalarkey);

      /** @ngInject */
      function acmeMalarkey(malarkey) {
        var directive = {
          restrict: 'E',
          scope: {
            extraValues: '='
          },
          template: '&nbsp;',
          link: linkFunc,
          controller: MalarkeyController,
          controllerAs: 'vm'
        };

        return directive;

        function linkFunc(scope, el, attr, vm) {
          var watcher;
          var typist = malarkey(el[0], {
            typeSpeed: 40,
            deleteSpeed: 40,
            pauseDelay: 800,
            loop: true,
            postfix: ' '
          });

          el.addClass('acme-malarkey');

          angular.forEach(scope.extraValues, function(value) {
            typist.type(value).pause().delete();
          });

          watcher = scope.$watch('vm.contributors', function() {
            angular.forEach(vm.contributors, function(contributor) {
              typist.type(contributor.login).pause().delete();
            });
          });

          scope.$on('$destroy', function () {
            watcher();
          });
        }

        /** @ngInject */
        function MalarkeyController($log, githubContributor) {
          var vm = this;

          vm.contributors = [];

          activate();

          function activate() {
            return getContributors().then(function() {
              $log.info('Activated Contributors View');
            });
          }

          function getContributors() {
            return githubContributor.getContributors(10).then(function(data) {
              vm.contributors = data;

              return vm.contributors;
            });
          }
        }

      }

    })();