Sha256: 7e7b3dada59adfefa4db9b314f18a9a6d774970134125b2c1c2adbcbf921e243

Contents?: true

Size: 1.71 KB

Versions: 1

Compression:

Stored size: 1.71 KB

Contents

@rebuild_sortable_tree = (rebuild_url, item_id, parent_id, prev_id, next_id) ->
  $.ajax
    type:     'POST'
    dataType: 'script'
    url:      rebuild_url
    data:
      id:        item_id
      parent_id: parent_id
      prev_id:   prev_id
      next_id:   next_id

    beforeSend: (xhr) ->
      $('.sortable_tree i.handle').hide()

    success: (data, status, xhr) ->
      $('.sortable_tree i.handle').show()

    error: (xhr, status, error) ->
      console.log error

$ ->
  for sortable_tree in $('ol.sortable_tree')
    sortable_tree = $ sortable_tree
    rebuild_url   = sortable_tree.data('rebuild_url') || sortable_tree.data('rebuild-url')
    max_levels    = sortable_tree.data('max_levels')  || sortable_tree.data('rebuild-url')

    ############################################
    # Initialize Sortable Tree
    ############################################
    sortable_tree.nestedSortable
      items:            'li'
      helper:           'clone'
      handle:           'i.handle'
      tolerance:        'pointer'
      maxLevels:        max_levels
      revert:           250
      tabSize:          25
      opacity:          0.6
      placeholder:      'placeholder'
      disableNesting:   'no-nest'
      toleranceElement: '> div'
      forcePlaceholderSize: true

    ############################################
    # Sortable Update Event
    ############################################
    sortable_tree.on "sortupdate", (event, ui) =>
      item      = ui.item
      item_id   = item.attr('id')
      prev_id   = item.prev().attr('id')
      next_id   = item.next().attr('id')
      parent_id = item.parent().parent().attr('id')
      
      rebuild_sortable_tree(rebuild_url, item_id, parent_id, prev_id, next_id)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
the_sortable_tree-2.3.1 app/assets/javascripts/sortable_tree/initializer.js.coffee