<commit_before>/*
---
 
script: Sortable.js
 
description: Reorder widgets as you please
 
license: Public domain (http://unlicense.org).

authors: <NAME>
 
requires:
  - More/Sortables
  - LSD.Mixin
 
provides:
  - LSD.Mixin.Sortable
 
...
*/

LSD.Mixin.Sortable = new Class({
  options: {
    sortables: {
      clone: true,
      snap: 5,
      constrain: true,
      revert: true
    },
    pseudos: Array.object('activatable'),
    events: {
      self: {
        mousedown: 'onBeforeSortStart'
      }
    }
  },
  
  getSortables: function() {
    if (this.sortables) return this.sortables;
    var options = Object.append({}, this.options.sortables);
    if (options.clone === true) options.clone = function(event, element){
      var widget = element.uid && element.retrieve('widget');
      var clone = element.cloneNode(true);
      document.id(clone).addEvent('mousedown', function(event){
        element.fireEvent('mousedown', event);
      }).addClass('clone').store('origin', widget).setStyles({
        margin: 0,
        position: 'absolute',
        visibility: 'hidden',
        width: element.getStyle('width')
      }).setPosition(element.getPosition(element.getOffsetParent()));
      return clone.inject(this.list);
    };
    delete options.snap;
    this.sortables = new Sortables([], options);
    this.properties.set('sortables', this.sortables);
    this.sortables.addEvents(this.bind({
      start: 'onSortStart',
      complete: 'onSortComplete',
      sort: 'onSort'
    }))
    var self = this;
    this.sortables.insert = function(dragging, element) {
      if (self.onBeforeSort.apply(self, arguments)) {
        (dragging.retrieve('origin') || dragging).fireEvent('beforeMove', element);
        var where = 'inside';
        if (this.lists.contains(element)){
          this.list = element;
          this.drag.droppables = this.getDroppables();
        } else {
          where = this.element.getAllPrevious().contains(element) ? 'before' : 'after';
        };
        (this.element.uid && this.element.retrieve('widget') || this.element).inject(element, where);
        this.fireEvent('sort', [this.element, this.clone]);
      }
    };
    return this.sortables;
  },
  
  onBeforeSort: function(dragging, element) {
    return true;
  },
  
  onBeforeSortStart: function(event) {
    for (var target = event.target, widget; target && target.tagName; target = target.parentNode) {
      if (target == this.element) break;
      widget = target.uid && Element.retrieve(target, 'widget');
      if (widget && widget.pseudos.reorderable) {
        if (widget.getHandle) {
          var handle = widget.getHandle();
          if (!(handle == event.target || handle.contains(event.target))) return;
        }
        var snap = widget.options.snap || this.options.sortables.snap || 0;
        var start = event.page, self = this;
        if (snap > 0) {<commit_msg>Dont start sorting if the clicked element is a form field<commit_after>/*
---
 
script: Sortable.js
 
description: Reorder widgets as you please
 
license: Public domain (http://unlicense.org).

authors: <NAME>
 
requires:
  - More/Sortables
  - LSD.Mixin
 
provides:
  - LSD.Mixin.Sortable
 
...
*/

LSD.Mixin.Sortable = new Class({
  options: {
    sortables: {
      clone: true,
      snap: 5,
      constrain: true,
      revert: true
    },
    pseudos: Array.object('activatable'),
    events: {
      self: {
        mousedown: 'onBeforeSortStart'
      }
    }
  },
  
  getSortables: function() {
    if (this.sortables) return this.sortables;
    var options = Object.append({}, this.options.sortables);
    if (options.clone === true) options.clone = function(event, element){
      var widget = element.uid && element.retrieve('widget');
      var clone = element.cloneNode(true);
      document.id(clone).addEvent('mousedown', function(event){
        element.fireEvent('mousedown', event);
      }).addClass('clone').store('origin', widget).setStyles({
        margin: 0,
        position: 'absolute',
        visibility: 'hidden',
        width: element.getStyle('width')
      }).setPosition(element.getPosition(element.getOffsetParent()));
      return clone.inject(this.list);
    };
    delete options.snap;
    this.sortables = new Sortables([], options);
    this.properties.set('sortables', this.sortables);
    this.sortables.addEvents(this.bind({
      start: 'onSortStart',
      complete: 'onSortComplete',
      sort: 'onSort'
    }))
    var self = this;
    this.sortables.insert = function(dragging, element) {
      if (self.onBeforeSort.apply(self, arguments)) {
        (dragging.retrieve('origin') || dragging).fireEvent('beforeMove', element);
        var where = 'inside';
        if (this.lists.contains(element)){
          this.list = element;
          this.drag.droppables = this.getDroppables();
        } else {
          where = this.element.getAllPrevious().contains(element) ? 'before' : 'after';
        };
        (this.element.uid && this.element.retrieve('widget') || this.element).inject(element, where);
        this.fireEvent('sort', [this.element, this.clone]);
      }
    };
    return this.sortables;
  },
  
  onBeforeSort: function(dragging, element) {
    return true;
  },
  
  onBeforeSortStart: function(event) {
    for (var target = event.target, widget; target && target.tagName; target = target.parentNode) {
      if (target == this.element) break;
      switch (LSD.toLowerCase(target.tagName)) {
        case "select": case "input": case "textarea":
          return;
      }
      widget = target.uid && Element.retrieve(target, 'widget');
      if (widget && widget.pseudos.reorderable) {
        if (widget.getHandle) {
          var handle = widget.getHandle();
          if (!(handle == event.target || handle.contains(event.target))) return;
        }
        var snap = widget.options.snap || this.options.sortables.snap || 0;
        var start = event.page, self = this;
        if (snap > 0) {
{'fraction_non_alphanumeric': 0.14766449020592667, 'fraction_numerical': 0.0013393604553825547, 'mean_word_length': 2.701363073110285, 'pattern_counts': {'":': 3, '<': 5, '<?xml version=': 0, '>': 7, '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': '4477512', 'n_tokens_mistral': 1830, 'n_tokens_neox': 1791, 'n_words': 377}