Sha256: 31be20ce618832c2c671f1b0027626ee03582b7db82ff45ad8e5fe3eabfc4d6c

Contents?: true

Size: 1.01 KB

Versions: 12

Compression:

Stored size: 1.01 KB

Contents

document.addEventListener("spree:load", function() {
  var parentEl = document.getElementsByClassName('sortable')[0];
  if (parentEl) {
    var element = parentEl.querySelector('tbody')
  }

  if (element) {
    Sortable.create(element, {
      handle: '.move-handle',
      animation: 550,
      ghostClass: 'bg-light',
      dragClass: 'sortable-drag-v',
      easing: 'cubic-bezier(1, 0, 0, 1)',
      swapThreshold: 0.9,
      forceFallback: true,
      onEnd: function(evt) {
        var itemEl = evt.item
        var positions = { authenticity_token: AUTH_TOKEN }
        $.each($('tr', element), function(position, obj) {
          var reg = /spree_(\w+_?)+_(.*)/
          var parts = reg.exec($(obj).prop('id'))
          if (parts) {
            positions['positions[' + parts[2] + ']'] = position + 1
          }
        })
        $.ajax({
          type: 'POST',
          dataType: 'json',
          url: $(itemEl).closest('table.sortable').data('sortable-link'),
          data: positions
        })
      }
    })
  }
})

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
spree_backend-4.8.4 app/assets/javascripts/spree/backend/global/sortable.es6
spree_backend-4.8.3 app/assets/javascripts/spree/backend/global/sortable.es6
spree_backend-4.8.2 app/assets/javascripts/spree/backend/global/sortable.es6
spree_backend-4.8.1 app/assets/javascripts/spree/backend/global/sortable.es6
spree_backend-4.7.2 app/assets/javascripts/spree/backend/global/sortable.es6
spree_backend-4.6.2 app/assets/javascripts/spree/backend/global/sortable.es6
spree_backend-4.7.1 app/assets/javascripts/spree/backend/global/sortable.es6
spree_backend-4.7.0 app/assets/javascripts/spree/backend/global/sortable.es6
spree_backend-4.6.1 app/assets/javascripts/spree/backend/global/sortable.es6
spree_backend-4.6.0 app/assets/javascripts/spree/backend/global/sortable.es6
spree_backend-4.5.1 app/assets/javascripts/spree/backend/global/sortable.es6
spree_backend-4.5.0 app/assets/javascripts/spree/backend/global/sortable.es6