diff --git a/lib/assets/javascripts/sortable_tree.js b/lib/assets/javascripts/sortable_tree.js index 6c62b6b..01e232c 100644 --- a/lib/assets/javascripts/sortable_tree.js +++ b/lib/assets/javascripts/sortable_tree.js @@ -1,4 +1,11 @@ -$(document).ready(function(){ +if (typeof Turbolinks !== 'undefined' && Turbolinks.supported) { + $(document).on("turbolinks:load", sortableCallback); + // https://github.com/turbolinks/turbolinks#full-list-of-events +} else { + $(document).ready(sortableCallback); // document.ready +} + +function sortableCallback(){ $('.sortable_tree').each(function() { $(this).nestedSortable({ @@ -6,13 +13,14 @@ $(document).ready(function(){ errorClass: 'cantdoit', disableNesting: 'cantdoit', handle: '> .item', - helper: 'clone', + helper: 'clone', listType: 'ol', items: 'li', opacity: 0.6, placeholder: 'placeholder', revert: 250, maxLevels: $(this).data('max-levels'), + expression: /(.+)_(.+)/, //maxLevels: #{options[:max_levels] || 5}, //tabSize: 20, // protectRoot: $(this).data('protect-root'), @@ -57,5 +65,4 @@ $(document).ready(function(){ }); // nested tree }); - -}); // document.ready +} diff --git a/readme.md b/readme.md index 0b1d25f..906ca34 100644 --- a/readme.md +++ b/readme.md @@ -230,7 +230,18 @@ If you use ancestry in model - set :parent_method to 'parent'. * edit file 'views/sortable/_sortable.html.haml' to access the whole layout - +# UUID support + +When using uuid instead of id, add this to `application.js`: +```javascript +$(document).ready(function() { + $('.sortable_tree').each(function () { + $(this).nestedSortable({ + expression: /(.+)_(.+)/, + }); + }); +}); +```