Sha256: 55a9a6b2a0bbbeeb168b63729b4a19320c72862307de97416051ada6553254c0

Contents?: true

Size: 1.64 KB

Versions: 151

Compression:

Stored size: 1.64 KB

Contents

$(document).ready(function () {

  if ( $(".orderable-items").length ) {
    if ($(".orderable-items").length > 1) {
      logg("There are many .orderable-items! This was only meant to work with one.")
    }
    // let slug = $( $(".orderable-items")[0] ).data('slug')
    let id = $( $(".orderable-items")[0] ).data('id')
    let token = $( $(".orderable-items")[0] ).data('token')

    $(".orderable-items .items > div").each(function (idx, item) {
      let $el = $(this)

      $(this).find('a.mvLeft').click(function() {
        // move element up one step
        if ($el.not(':first-child'))
          $el.prev().before($el);
      })

      $(this).find('a.mvRight').click(function() {
        // move element down one step
        if ($el.not(':last-child'))
            $el.next().after($el);
      })

    })
    $(".save-ordering").click(function() {

      let els = $(this).parent().find(".items .item")
      let ids = []
      $(els).map((idx, item) => {
        ids.push( $(item).data('id') )
      })

      $.ajax({
        type: 'PATCH',
        url: AppRouter.gallery_update_ordering_path({ id: id }),
        data: {
          authenticity_token: token,
          gallery: {
            sorted_photo_ids: ids,
          },
        },
        success: (e) => {
          logg('success')
        },

      })

      logg('ok')
    })
  }

})

/*
//element to move
var $el = $(selector);

//move element down one step
if ($el.not(':last-child'))
    $el.next().after($el);

//move element up one step
if ($el.not(':first-child'))
    $el.prev().before($el);

//move element to top
$el.parent().prepend($el);

//move element to end
$el.parent().append($el);
*/

Version data entries

151 entries across 151 versions & 1 rubygems

Version Path
ish_manager-0.1.8.513 app/assets/javascripts/ish_manager/galleries.js
ish_manager-0.1.8.512 app/assets/javascripts/ish_manager/galleries.js
ish_manager-0.1.8.511 app/assets/javascripts/ish_manager/galleries.js
ish_manager-0.1.8.510 app/assets/javascripts/ish_manager/galleries.js
ish_manager-0.1.8.509 app/assets/javascripts/ish_manager/galleries.js
ish_manager-0.1.8.508 app/assets/javascripts/ish_manager/galleries.js
ish_manager-0.1.8.507 app/assets/javascripts/ish_manager/galleries.js
ish_manager-0.1.8.506 app/assets/javascripts/ish_manager/galleries.js
ish_manager-0.1.8.505 app/assets/javascripts/ish_manager/galleries.js
ish_manager-0.1.8.504 app/assets/javascripts/ish_manager/galleries.js
ish_manager-0.1.8.503 app/assets/javascripts/ish_manager/galleries.js
ish_manager-0.1.8.500 app/assets/javascripts/ish_manager/galleries.js
ish_manager-0.1.8.499 app/assets/javascripts/ish_manager/galleries.js
ish_manager-0.1.8.498 app/assets/javascripts/ish_manager/galleries.js
ish_manager-0.1.8.497 app/assets/javascripts/ish_manager/galleries.js
ish_manager-0.1.8.496 app/assets/javascripts/ish_manager/galleries.js
ish_manager-0.1.8.495 app/assets/javascripts/ish_manager/galleries.js
ish_manager-0.1.8.494 app/assets/javascripts/ish_manager/galleries.js
ish_manager-0.1.8.493 app/assets/javascripts/ish_manager/galleries.js
ish_manager-0.1.8.492 app/assets/javascripts/ish_manager/galleries.js