{"size": 2039, "ext": "js", "max_stars_repo_path": "src/common/arrangeable/ArrangeableDirective.js", "max_stars_repo_name": "MapStory/MapLoom", "max_stars_repo_stars_event_min_datetime": "2016-06-12T03:05:32.000Z", "max_stars_repo_stars_event_max_datetime": "2017-04-06T14:44:00.000Z", "max_issues_repo_path": "src/common/arrangeable/ArrangeableDirective.js", "max_issues_repo_name": "MapStory/MapLoom", "max_issues_repo_issues_event_min_datetime": "2016-03-15T13:18:13.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-19T15:36:10.000Z", "max_forks_repo_path": "src/common/arrangeable/ArrangeableDirective.js", "max_forks_repo_name": "MapStory/MapLoom", "max_forks_repo_forks_event_min_datetime": "2016-01-14T14:12:20.000Z", "max_forks_repo_forks_event_max_datetime": "2017-08-10T17:11:46.000Z"}
{"max_stars_count": 3, "max_issues_count": 8, "max_forks_count": 4, "avg_line_length": 31.859375, "max_line_length": 80, "alphanum_fraction": 0.5026974007}
(function() {
  var module = angular.module('loom_arrangeable_directive', []);

  module.directive('loomArrangeable', function() {
    return {
      restrict: 'C',
      link: function(scope, element, attrs) { // Unused: attrs
        $(function() {
          var containerToDrop = null;
          var startIndex = -1;
          var config = {
            // set item relative to cursor position
            onDragStart: function($item, container, _super) {
              containerToDrop = container;
              var height = $item.outerHeight();
              var width = $item.outerWidth();
              var offset = $item.offset(),
                  pointer = container.rootGroup.pointer;
              startIndex = $item.index();
              adjustment = {
                left: pointer.left - offset.left,
                top: pointer.top - offset.top
              };

              _super($item, container);

              $item.css({
                width: width,
                height: height
              });
            },
            onDrag: function($item, position) {
              $item.css({
                left: position.left - adjustment.left,
                top: position.top - adjustment.top
              });
            },
            onDrop: function($item, container, _super) {
              scope.$eval(attrs.arrangeableCallback)(startIndex, $item.index());
              _super($item, containerToDrop);
            },
            distance: 5
          };

          if (attrs.arrangeableHandle) {
            config.handle = attrs.arrangeableHandle;
          }
          if (attrs.arrangeableItemSelector) {
            config.itemSelector = attrs.arrangeableItemSelector;
          }
          if (attrs.arrangeablePlaceholder) {
            config.placeholder = attrs.arrangeablePlaceholder;
          }
          if (attrs.arrangeableDragDistance) {
            config.distance = attrs.arrangeableDragDistance;
          }

          element.sortable(config);
        });
      }
    };
  });
}());
