<commit_before>/*!
 * angular-masonry <%= pkg.version %>
 * <NAME>, weluse GmbH, http://weluse.de/
 * License: MIT
 */
(function () {
  'use strict';

  angular.module('wu.masonry', [])
    .controller('MasonryCtrl', function controller($scope, $element, $timeout) {
      var bricks = {};
      var reloadScheduled = false;
      var destroyed = false;

      // Make sure it's only executed once within a reasonable time-frame in
      // case multiple elements are removed or added at once.
      function scheduleReload() {
        if (!reloadScheduled) {
          reloadScheduled = true;

          $timeout(function relayout() {
            reloadScheduled = false;
            if (!destroyed) {
              $element.masonry('layout');
            }
          }, 30);
        }
      }

      function defaultLoaded($element) {
        $element.addClass('loaded');
      }

      this.appendBrick = function appendBrick(element, id) {
        if (destroyed) {
          return;
        }

        function _append() {
          if (Object.keys(bricks).length === 0) {
            // Call masonry asynchronously on initialization.
            $timeout(function () {
              $element.masonry('resize');
            });
          }

          if (bricks[id] === undefined) {
            // I wanted to make this dynamic but ran into huuuge memory leaks
            // that I couldn't fix. If you know how to dynamically add a
            // callback so one could say <masonry loaded="callback($element)">
            // please submit a pull request!
            defaultLoaded(element);

            // Keep track of added elements.
            bricks[id] = true;
            $element.masonry('appended', element, true);
            scheduleReload();
          }
        }

        element.imagesLoaded(_append);
      };

      this.removeBrick = function removeBrick(id, element) {
        if (destroyed) {
          return;
        }

        delete bricks[id];
        $element.masonry('remove', element);

        scheduleReload();
      };

      this.destroy = function destroy() {
        destroyed = true;

        if ($element.data('masonry')) {
          // Gently uninitialize if still present
          $element.masonry('destroy');
        }

        bricks = [];
      };

    }).directive('masonry', function () {
      return {
        restrict: 'AE',
        controller: 'MasonryCtrl',
        link: function postLink(scope, element, attrs, ctrl) {
          var attrOptions = scope.$eval(attrs.options);
          var options = angular.extend(attrOptions || {}, {
            itemSelector: attrs.itemSelector || '.masonry-brick',
            columnWidth: attrs.columnWidth
          });
          element.masonry(options);

          scope.$on('$destroy', ctrl.destroy);
        }
      };
    }).directive('masonryBrick', function () {
      return {
        restrict: 'AC',
        require: '^masonry',
        link: function postLink(scope, element, attrs, ctrl) {
          var id = scope.$id;

          ctrl.appendBrick(element, id);
          element.on('$destroy', function () {
            ctrl.removeBrick(id, element);
          });
        }
      };
    });
}());
<commit_msg>fix(app): more careful relayout scheduling<commit_after>/*!
 * angular-masonry <%= pkg.version %>
 * <NAME>, weluse GmbH, http://weluse.de/
 * License: MIT
 */
(function () {
  'use strict';

  angular.module('wu.masonry', [])
    .controller('MasonryCtrl', function controller($scope, $element, $timeout) {
      var bricks = {};
      var schedule = [];
      var destroyed = false;
      var timeout = null;

      function scheduleMasonryOnce() {
        var args = arguments;
        var found = schedule.filter(function (item) {
          return item[0] === args[0];
        }).length > 0;

        if (!found) {
          scheduleMasonry.apply(null, arguments);
        }
      }

      // Make sure it's only executed once within a reasonable time-frame in
      // case multiple elements are removed or added at once.
      function scheduleMasonry() {
        if (timeout) {
          $timeout.cancel(timeout);
        }

        schedule.push([].slice.call(arguments));

        timeout = $timeout(function runMasonry() {
          if (destroyed) {
            return;
          }
          schedule.forEach(function (args) {
            $element.masonry.apply($element, args);
          });
          schedule = [];
        }, 30);
      }

      function defaultLoaded($element) {
        $element.addClass('loaded');
      }

      this.appendBrick = function appendBrick(element, id) {
        if (destroyed) {
          return;
        }

        function _append() {
          if (Object.keys(bricks).length === 0) {
            $element.masonry('resize');
          }

          if (bricks[id] === undefined) {
            // I wanted to make this dynamic but ran into huuuge memory leaks
            // that I couldn't fix. If you know how to dynamically add a
            // callback so one could say <masonry loaded="callback($element)">
            // please submit a pull request!
            defaultLoaded(element);

            // Keep track of added elements.
            bricks[id] = true;
            $element.masonry('appended', element, true);
            scheduleMasonryOnce('layout');
          }
        }

        element.imagesLoaded(_append);
      };

      this.removeBrick = function removeBrick(id, element) {
        if (destroyed) {
          return;
        }

        delete bricks[id];
        $element.masonry('remove', element);
        scheduleMasonryOnce('layout');
      };

      this.destroy = function destroy() {
        destroyed = true;

        if ($element.data('masonry')) {
          // Gently uninitialize if still present
          $element.masonry('destroy');
        }

        bricks = [];
      };

    }).directive('masonry', function () {
      return {
        restrict: 'AE',
        controller: 'MasonryCtrl',
        link: function postLink(scope, element, attrs, ctrl) {
          var attrOptions = scope.$eval(attrs.options);
          var options = angular.extend(attrOptions || {}, {
            itemSelector: attrs.itemSelector || '.masonry-brick',
            columnWidth: attrs.columnWidth
          });
          element.masonry(options);

          scope.$on('$destroy', ctrl.destroy);
        }
      };
    }).directive('masonryBrick', function () {
      return {
        restrict: 'AC',
        require: '^masonry',
        link: function postLink(scope, element, attrs, ctrl) {
          var id = scope.$id;

          ctrl.appendBrick(element, id);
          element.on('$destroy', function () {
            ctrl.removeBrick(id, element);
          });
        }
      };
    });
}());

{'fraction_non_alphanumeric': 0.13061404800471213, 'fraction_numerical': 0.001325283463407451, 'mean_word_length': 1.7916152897657214, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1167607', 'n_tokens_mistral': 1888, 'n_tokens_neox': 1823, 'n_words': 440}