Skip to content

Commit

Permalink
feature: implement basic dragging
Browse files Browse the repository at this point in the history
  • Loading branch information
mutantsan committed Sep 12, 2023
1 parent e54061c commit 80ed0fa
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 10 deletions.
12 changes: 12 additions & 0 deletions ckanext/tour/assets/css/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ckanext/tour/assets/css/style.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 22 additions & 4 deletions ckanext/tour/assets/js/tour-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ ckan.module("tour-steps", function ($) {

this._toggleRemoveBtns();
this._updateLastStepId();

new Sortable.default(document.querySelectorAll('.tour-steps__steps'), {
draggable: '.tour-accordion',
handle: ".dragger",
sortAnimation: {
duration: 200,
easingFunction: 'ease-in-out',
},
plugins: [Plugins.SortAnimation]
})
.on('drag:start', () => console.log('drag:start'))
.on('drag:move', () => console.log('drag:move'))
.on('drag:stop', () => console.log('drag:stop'))
.on("sortable:stop", () => console.log("sortable:stop"))

},

_onAddStep: function (e) {
Expand All @@ -40,18 +55,21 @@ ckan.module("tour-steps", function ($) {
_onRemoveStep: function (e) {
e.preventDefault();

$(e.target).closest(".tour-accordion").remove();
var self = this;

this._toggleRemoveBtns();
this._updateLastStepId();
$(e.target).closest(".tour-accordion").hide('slow', function () {
this.remove();
self._toggleRemoveBtns();
self._updateLastStepId();
});
},

/**
* Should be at least 1 step for a tour. Disable remove step button if
* only 1 left.
*/
_toggleRemoveBtns: function () {
var steps = $(".tour-steps__steps .tour-step");
var steps = $(".tour-steps__steps .tour-accordion");
$(".remove-step").toggleClass("disabled", steps.length == 1)
},

Expand Down
4 changes: 0 additions & 4 deletions ckanext/tour/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
<span class="hidden" data-module="tour-init"></span>

{% asset 'tour/tour-js' %}
<!-- Draggable only -->
<script src="https://cdn.jsdelivr.net/npm/@shopify/[email protected]/lib/draggable.js"></script>
<!-- Sortable only -->
<script src="https://cdn.jsdelivr.net/npm/@shopify/[email protected]/lib/sortable.js"></script>
{% endblock %}

{% block styles %}
Expand Down
1 change: 1 addition & 0 deletions ckanext/tour/templates/snippets/svg/drag.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion ckanext/tour/templates/tour/snippets/tour_step.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
<div class="accordion-item">
<h3 class="accordion-header" id="headingOne">
<div class="accordion-header--text">
Step <span class="step-idx">0</span>
Step <span class="step-idx">{{ step_id }}</span>
</div>
<span class="dragger">
{% snippet 'snippets/svg/drag.svg' %}
</span>
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapse-{{ step_id }}"
aria-expanded="true" aria-controls="collapse-{{ step_id }}">
</button>
Expand Down
4 changes: 4 additions & 0 deletions ckanext/tour/templates/tour/tour_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,9 @@ <h3>{{ _("Tour steps:") }}</h3>
{% block scripts %}
{{ super() }}

<!-- <script src="https://cdn.jsdelivr.net/npm/@shopify/[email protected]/lib/draggable.js"></script> -->
<script src="https://cdn.jsdelivr.net/npm/@shopify/[email protected]/lib/sortable.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@shopify/[email protected]/lib/plugins.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@shopify/[email protected]/lib/plugins/sort-animation.js"></script>
{% asset 'tour/tour-htmx' %}
{% endblock %}
12 changes: 12 additions & 0 deletions ckanext/tour/theme/elements.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
}

.accordion.tour-accordion {
width: 100%;

.accordion-header {
display: flex;
align-items: center;
Expand All @@ -48,6 +50,16 @@
margin-right: auto;
}

.dragger {
height: 38px;
width: 38px;
display: flex;
text-align: center;
align-items: center;
justify-content: center;
cursor: grab;
}

.accordion-button {
width: fit-content;
padding: 0.5rem;
Expand Down

0 comments on commit 80ed0fa

Please sign in to comment.