{"size": 1741, "ext": "js", "max_stars_repo_path": "spec/e2e/drag_and_drop_helper.js", "max_stars_repo_name": "Zae/sir-trevor-js", "max_stars_repo_stars_event_min_datetime": "2015-01-03T09:26:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T23:34:27.000Z", "max_issues_repo_path": "spec/e2e/drag_and_drop_helper.js", "max_issues_repo_name": "Zae/sir-trevor-js", "max_issues_repo_issues_event_min_datetime": "2015-01-07T21:19:14.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-10T08:06:42.000Z", "max_forks_repo_path": "spec/e2e/drag_and_drop_helper.js", "max_forks_repo_name": "irishdistillers/sir-trevor-js", "max_forks_repo_forks_event_min_datetime": "2015-01-03T13:31:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-07T19:33:40.000Z"}
{"max_stars_count": 1401, "max_issues_count": 302, "max_forks_count": 294, "avg_line_length": 26.7846153846, "max_line_length": 74, "alphanum_fraction": 0.6329695577}
'use strict';

(function() {
  
  var SimulateDragDrop = function(elem, options) {
    this.options = options || {};
    this.options.dataTransfer = Object.assign({
      data: {},
      setData: function(type, val) {
        this.data[type] = val;
      },
      getData: function(type) {
        return this.data[type];
      },
      setDragImage: function(el, x, y) {}
    }, this.options.dataTransfer || {});

    this.simulateEvent(elem);
  };

  SimulateDragDrop.prototype.simulateEvent = function(elem) {
    var type, event;

    if (elem) {
      /*Simulating drag start*/
      type = 'dragstart';
      event = this.createEvent(type, this.options.dataTransfer);
      this.dispatchEvent(elem, type, event);
    } else {
      event = this.createEvent('custom', this.options.dataTransfer);
    }

    /*Simulating drop*/
    type = 'drop';
    var dropEvent = this.createEvent(type);
    this.dispatchEvent(this.options.dropTarget, type, dropEvent);

    if (elem) {
      /*Simulating drag end*/
      type = 'dragend';
      var dragEndEvent = this.createEvent(type);
      this.dispatchEvent(elem, type, dragEndEvent);
    }
  };

  SimulateDragDrop.prototype.createEvent = function(type) {
    var event = document.createEvent("CustomEvent");
    event.initCustomEvent(type, true, true, null);
    event.dataTransfer = this.options.dataTransfer;
    return event;
  };

  SimulateDragDrop.prototype.dispatchEvent = function(elem, type, event) {
    if (elem.dispatchEvent) {
      elem.dispatchEvent(event);
    } else if(elem.fireEvent) {
      elem.fireEvent("on"+type, event);
    }
  };

  window.simulateDragDrop = function(element, options) {
    new SimulateDragDrop(element, options); // jshint ignore:line
  };

})();