Skip to content

Commit

Permalink
Add button to allow better list dragging
Browse files Browse the repository at this point in the history
When dealing with many lists with many links, it becomes hard for the
user to drag lists because it needs both scrolling and dragging.

Adds a button to collapse the links, allowing easier dragging and
dropping.
  • Loading branch information
tijmenb committed Jun 11, 2015
1 parent d855d45 commit 9d11f25
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//= require jquery-ui.sortable.min
//= require jquery.clicktoggle
//= require_tree .
//= require_self

Expand Down
15 changes: 12 additions & 3 deletions app/assets/javascripts/ordered_lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@

GOVUK.orderedLists = {
init: function() {
var $listContainer = $('.curated-lists');
$('#switch-to-list-sorting').clickToggle(
function () {
$('body').addClass('list-drag-in-progress');
$(this).text('Done');
},
function () {
$('body').removeClass('list-drag-in-progress');
$(this).text('Sort lists')
}
);

var $listContainer = $('.curated-lists');
$listContainer.sortable({
stop: function(event, draggable) {
var $lists = $listContainer.children();
Expand All @@ -22,8 +32,7 @@
GOVUK.orderedLists.reindex($listsToUpdate, indexToUpdateFrom);
GOVUK.publishing.unlockPublishing();
},
placeholder: 'sortable-placeholder',
forcePlaceholderSize: true
placeholder: 'sortable-placeholder'
});
},
reindex: function($lists, offset) {
Expand Down
14 changes: 14 additions & 0 deletions app/assets/stylesheets/curated_lists.scss
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ html.js {
cursor: move;
}

.list-drag-in-progress {
.curated-list {
display: none;
}

.links-table {
margin-bottom: 10px;
}

.sortable-placeholder {
height: 30px !important;
}
}

.curated-list {
tr.untagged {
background-color: #ffff99;
Expand Down
10 changes: 10 additions & 0 deletions app/views/lists/_list_editor.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
<div style="text-align: right">
<button type="button"
id="switch-to-list-sorting"
data-toggle="button"
class="btn btn-default"
autocomplete="off">
Sort lists
</button>
</div>

<div class="curated-lists">
<% lists.each do |list| %>
<section
Expand Down
13 changes: 13 additions & 0 deletions vendor/assets/javascripts/jquery.clicktoggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$.fn.clickToggle = function(a,b){
return this.each(function(){
var clicked = false;
$(this).bind("click",function(){
if (clicked) {
clicked = false;
return b.apply(this,arguments);
}
clicked = true;
return a.apply(this,arguments);
});
});
};

0 comments on commit 9d11f25

Please sign in to comment.