diff --git a/static/script/draggable.js b/static/script/draggable.js new file mode 100644 index 0000000..42bc1a2 --- /dev/null +++ b/static/script/draggable.js @@ -0,0 +1,78 @@ +// https://codepen.io/retrofuturistic/pen/DJWYBv + +let dragSrcEl = null; + +function handleDragStart(e) { + // Target (this) element is the source node. + dragSrcEl = this; + + e.dataTransfer.effectAllowed = 'move'; + e.dataTransfer.setData('text/html', this.outerHTML); + + this.classList.add('dragElem'); +} + +function handleDragOver(e) { + if (e.preventDefault) { + e.preventDefault(); // Necessary. Allows us to drop. + } + this.classList.add('over'); + + e.dataTransfer.dropEffect = 'move'; // See the section on the DataTransfer object. + + return false; +} + +function handleDragEnter(e) { + // this / e.target is the current hover target. +} + +function handleDragLeave(e) { + this.classList.remove('over'); // this / e.target is previous target element. +} + +function handleDrop(e) { + // this/e.target is current target element. + + if (e.stopPropagation) { + e.stopPropagation(); // Stops some browsers from redirecting. + } + + // Don't do anything if dropping the same column we're dragging. + if (dragSrcEl != this) { + // Set the source column's HTML to the HTML of the column we dropped on. + //alert(this.outerHTML); + //dragSrcEl.innerHTML = this.innerHTML; + //this.innerHTML = e.dataTransfer.getData('text/html'); + this.parentNode.removeChild(dragSrcEl); + let dropHTML = e.dataTransfer.getData('text/html'); + this.insertAdjacentHTML('beforebegin', dropHTML); + let dropElem = this.previousSibling; + addDnDHandlers(dropElem); + } + + this.classList.remove('over'); + return false; +} + +function handleDragEnd(e) { + // this/e.target is the source node. + this.classList.remove('over'); + + /*[].forEach.call(cols, function (col) { + col.classList.remove('over'); + });*/ +} + +function addDnDHandlers(elem) { + elem.addEventListener('dragstart', handleDragStart, false); + elem.addEventListener('dragenter', handleDragEnter, false) + elem.addEventListener('dragover', handleDragOver, false); + elem.addEventListener('dragleave', handleDragLeave, false); + elem.addEventListener('drop', handleDrop, false); + elem.addEventListener('dragend', handleDragEnd, false); + +} + +const cols = document.querySelectorAll('#columns .column'); +[].forEach.call(cols, addDnDHandlers); \ No newline at end of file diff --git a/static/style/draggable.css b/static/style/draggable.css new file mode 100644 index 0000000..a2ba8fb --- /dev/null +++ b/static/style/draggable.css @@ -0,0 +1,21 @@ +/* https://codepen.io/retrofuturistic/pen/DJWYBv */ + +[draggable] { + -moz-user-select: none; + -khtml-user-select: none; + -webkit-user-select: none; + user-select: none; + + /* Required to make elements draggable in old WebKit */ + -khtml-user-drag: element; + -webkit-user-drag: element; +} + +.column { + cursor: move; +} + +.column.over { + //border: 2px dashed #000; + border-top: 2px solid blue; +} \ No newline at end of file diff --git a/templates/enter.jinja b/templates/enter.jinja new file mode 100644 index 0000000..4523b19 --- /dev/null +++ b/templates/enter.jinja @@ -0,0 +1,51 @@ +{% extends 'base.jinja' %} + +{% set active_page = "/enter" %} + +{% block title %}Formula 10 - Race Result{% endblock title %} + +{% block head_extra %} + + +{% endblock head_extra %} + +{% block body %} + +
+
+
{{ race.grandprix }}
+ +
+
    + {% for driver in drivers %} +
  • + {{ driver.name }} + +
    + {# Driver DNFed #} +
    + + +
    + + {# Driver Excluded #} +
    + + +
    +
    + + {# Standing order #} +
  • + {% endfor %} +
+ + +
+ +
+
+ +{% endblock body %} \ No newline at end of file