diff options
author | Lauri Ojansivu <x@xet7.org> | 2018-03-20 22:58:22 +0200 |
---|---|---|
committer | Lauri Ojansivu <x@xet7.org> | 2018-03-20 22:58:22 +0200 |
commit | a7855f3f582d193b0a6dbd70b5da6f59384f9520 (patch) | |
tree | 8bb0c9d19a23dfb374a251241ba83f8e7b448bae /client/lib/utils.js | |
parent | 90f3f7ba163ef5d015bc473946b02c23e263a011 (diff) | |
parent | ac19904ee86541165b0017dcaaee33629904806b (diff) | |
download | wekan-a7855f3f582d193b0a6dbd70b5da6f59384f9520.tar.gz wekan-a7855f3f582d193b0a6dbd70b5da6f59384f9520.tar.bz2 wekan-a7855f3f582d193b0a6dbd70b5da6f59384f9520.zip |
Merge branch 'andresmanelli-checklistItems' into devel
Diffstat (limited to 'client/lib/utils.js')
-rw-r--r-- | client/lib/utils.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/client/lib/utils.js b/client/lib/utils.js index 9a9ff654..1f44c60d 100644 --- a/client/lib/utils.js +++ b/client/lib/utils.js @@ -33,6 +33,37 @@ Utils = { return $(window).width() <= 800; }, + calculateIndexData(prevData, nextData, nItems = 1) { + let base, increment; + // If we drop the card to an empty column + if (!prevData && !nextData) { + base = 0; + increment = 1; + // If we drop the card in the first position + } else if (!prevData) { + base = nextData.sort - 1; + increment = -1; + // If we drop the card in the last position + } else if (!nextData) { + base = prevData.sort + 1; + increment = 1; + } + // In the general case take the average of the previous and next element + // sort indexes. + else { + const prevSortIndex = prevData.sort; + const nextSortIndex = nextData.sort; + increment = (nextSortIndex - prevSortIndex) / (nItems + 1); + base = prevSortIndex + increment; + } + // XXX Return a generator that yield values instead of a base with a + // increment number. + return { + base, + increment, + }; + }, + // Determine the new sort index calculateIndex(prevCardDomElement, nextCardDomElement, nCards = 1) { let base, increment; |