diff options
author | Lauri Ojansivu <x@xet7.org> | 2018-03-20 22:13:18 +0200 |
---|---|---|
committer | Lauri Ojansivu <x@xet7.org> | 2018-03-20 22:13:18 +0200 |
commit | ec1630f8dd3719a15a17328687e5416aed82e874 (patch) | |
tree | 0752c6fe03c7776e9f8b9ed2fc437885b5b36325 /client/lib/utils.js | |
parent | 90f3f7ba163ef5d015bc473946b02c23e263a011 (diff) | |
parent | 5e5a5ed9be33fe020b76dfb1ab4b32aec0753a20 (diff) | |
download | wekan-ec1630f8dd3719a15a17328687e5416aed82e874.tar.gz wekan-ec1630f8dd3719a15a17328687e5416aed82e874.tar.bz2 wekan-ec1630f8dd3719a15a17328687e5416aed82e874.zip |
Merge branch 'checklistItems' of https://github.com/andresmanelli/wekan into andresmanelli-checklistItems
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; |