forked from Aspen-Discovery/aspen-discovery
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from ammopt/ammo_sortablelist_24.07.00
Preferred Mail Sender
- Loading branch information
Showing
8 changed files
with
197 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
code/web/interface/themes/responsive/DataObjectUtil/sortableList.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
{strip} | ||
<ol class="list-unstyled" id="sortable"> | ||
{foreach from=$property.values item=propertyName key=propertyValue} | ||
<li draggable="true" style="cursor:grab" data-value='{$propertyValue}'><i class="fas fa-grip-vertical"></i> {$propertyName|escape}</li> | ||
{/foreach} | ||
</ol> | ||
<input type='hidden' name='{$propName}' id='{$propName}' value='{$propValue|escape}'> | ||
|
||
<script type="text/javascript"> | ||
$(document).ready(function(){ | ||
refreshListOptions(); | ||
const sortableList = | ||
document.getElementById("sortable"); | ||
let draggedItem = null; | ||
function refreshListValue(){ | ||
let listOptions = []; | ||
$( "#sortable li" ).each(function( index ) { | ||
listOptions.push($(this).text().trim().replace('|','')); | ||
}); | ||
let text = listOptions.join('|'); | ||
$("#{$propName}").val(text.trim()); | ||
} | ||
function refreshListOptions(drag){ | ||
let value = $("#{$propName}").val(); | ||
let optionsFromText = value.split("|"); | ||
optionsFromText.forEach(textOption => { | ||
$('#sortable').children().each(function () { | ||
if(textOption.trim() == $(this).data().value){ | ||
$('#sortable').append($(this)); | ||
} | ||
}); | ||
}); | ||
} | ||
sortableList.addEventListener( | ||
"dragstart", | ||
(e) => { | ||
draggedItem = e.target; | ||
setTimeout(() => { | ||
e.target.style.display = | ||
"none"; | ||
}, 0); | ||
}); | ||
sortableList.addEventListener( | ||
"dragend", | ||
(e) => { | ||
setTimeout(() => { | ||
e.target.style.display = ""; | ||
draggedItem = null; | ||
refreshListValue(); | ||
}, 0); | ||
}); | ||
sortableList.addEventListener( | ||
"dragover", | ||
(e) => { | ||
e.preventDefault(); | ||
const afterElement = | ||
getDragAfterElement( | ||
sortableList, | ||
e.clientY); | ||
const currentElement = | ||
document.querySelector( | ||
".dragging"); | ||
if (afterElement == null) { | ||
sortableList.appendChild( | ||
draggedItem | ||
); | ||
} else { | ||
sortableList.insertBefore( | ||
draggedItem, | ||
afterElement | ||
); | ||
} | ||
}); | ||
const getDragAfterElement = ( | ||
container, y | ||
) => { | ||
const draggableElements = [ | ||
...container.querySelectorAll( | ||
"li:not(.dragging)" | ||
), | ||
]; | ||
return draggableElements.reduce( | ||
(closest, child) => { | ||
const box = | ||
child.getBoundingClientRect(); | ||
const offset = | ||
y - box.top - box.height / 2; | ||
if ( | ||
offset < 0 && | ||
offset > closest.offset) { | ||
return { | ||
offset: offset, | ||
element: child, | ||
}; | ||
} else { | ||
return closest; | ||
} | ||
}, { | ||
offset: Number.NEGATIVE_INFINITY, | ||
} | ||
).element; | ||
}; | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters