From 98832fbc5715287a8204b16bc92bb13477447aeb Mon Sep 17 00:00:00 2001 From: Ben Thomson Date: Mon, 8 Apr 2019 15:57:04 +0800 Subject: [PATCH] Initial work on handlers for re-ordering repeater items --- .../repeater/assets/js/repeater.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/modules/backend/formwidgets/repeater/assets/js/repeater.js b/modules/backend/formwidgets/repeater/assets/js/repeater.js index 32d2fdd5e..e3d5cfc0e 100644 --- a/modules/backend/formwidgets/repeater/assets/js/repeater.js +++ b/modules/backend/formwidgets/repeater/assets/js/repeater.js @@ -22,6 +22,9 @@ this.$el = $(element) this.$sortable = $(options.sortableContainer, this.$el) + // Sortable tracking + this.sortingStartIndex = null + $.oc.foundation.controlUtils.markDisposable(element) Base.call(this) this.init() @@ -77,7 +80,9 @@ Repeater.prototype.bindSorting = function() { var sortableOptions = { handle: this.options.sortableHandle, - nested: false + nested: false, + onDragStart: this.proxy(this.onSortStart), + onDrop: this.proxy(this.onSortStop) } this.$sortable.sortable(sortableOptions) @@ -224,6 +229,18 @@ return defaultText } + Repeater.prototype.onSortStart = function($item, container, callback, event) { + this.sortingStartIndex = $item.index() + + callback($item, container, callback, event); + } + + Repeater.prototype.onSortStop = function($item, container, callback, event) { + var endIndex = $item.index() + + callback($item, container, callback, event); + } + // FIELD REPEATER PLUGIN DEFINITION // ============================