From 22333bd1ab8581ea7e9b967f70b179a732008774 Mon Sep 17 00:00:00 2001 From: Cihad Paksoy Date: Sun, 23 Sep 2018 22:43:01 +0300 Subject: [PATCH 1/3] adds turbolinks support --- lib/assets/javascripts/sortable_tree.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/assets/javascripts/sortable_tree.js b/lib/assets/javascripts/sortable_tree.js index 6c62b6b..349ad05 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,7 +13,7 @@ $(document).ready(function(){ errorClass: 'cantdoit', disableNesting: 'cantdoit', handle: '> .item', - helper: 'clone', + helper: 'clone', listType: 'ol', items: 'li', opacity: 0.6, @@ -57,5 +64,4 @@ $(document).ready(function(){ }); // nested tree }); - -}); // document.ready +} From 270fba8ec283b50d5d0de77b46479df86c169fb8 Mon Sep 17 00:00:00 2001 From: Jetse Koopmans Date: Tue, 22 Jan 2019 12:46:03 +0100 Subject: [PATCH 2/3] uuid support --- readme.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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: /(.+)_(.+)/, + }); + }); +}); +``` From f94d6dde3309fe50e6bcf2767d0ee4fd958acae0 Mon Sep 17 00:00:00 2001 From: jetsekoopmans Date: Tue, 22 Jan 2019 12:56:57 +0100 Subject: [PATCH 3/3] add uuid support --- lib/assets/javascripts/sortable_tree.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/assets/javascripts/sortable_tree.js b/lib/assets/javascripts/sortable_tree.js index 349ad05..01e232c 100644 --- a/lib/assets/javascripts/sortable_tree.js +++ b/lib/assets/javascripts/sortable_tree.js @@ -20,6 +20,7 @@ function sortableCallback(){ placeholder: 'placeholder', revert: 250, maxLevels: $(this).data('max-levels'), + expression: /(.+)_(.+)/, //maxLevels: #{options[:max_levels] || 5}, //tabSize: 20, // protectRoot: $(this).data('protect-root'),