Skip to content

Commit

Permalink
Deffer sortable init to as late as possible, fix removing items
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Kerin committed Jul 31, 2013
1 parent 512b18a commit 009b776
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 61 deletions.
2 changes: 1 addition & 1 deletion views/tart/layout/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</div>
</div>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="/jam-tart/js/plugins.min.js"></script>
<script src="/jam-tart/js/bootstrap.min.js"></script>
<script src="/jam-tart/js/bootstrap-extensions.min.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion web/css/general.css
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ textarea.hide {
table .ui-sortable-helper{
opacity: 0.5;
}
.ui-sortable .thumbnail {
.ui-sortable-helper {
-webkit-transition: none !important;
-moz-transition: none !important;
-o-transition: none !important;
Expand Down
61 changes: 32 additions & 29 deletions web/js/bootstrap-extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,36 +385,39 @@
/* sortable DATA-API
* ============ */

$(function () {
$(document).on('mouseover.sortable.data-api', '[data-provide="sortable"]', function (e) {
var $this = $(this);
if ($this.data('sortable')) return;
e.preventDefault();
$this.sortable({
handle: $this.data('handle'),
items: $this.data('items'),
placeholder: $this.data('placeholder'),
tolerance: $this.data('tolerance'),
stop: function(event, ui) {
if ($(this).data('sortUrl')) {
// determine whether we move the element up or down
$.ajax([
$(this).data('sortUrl'),
'&from=',
getElementSortableId(ui.item, $(this).data('handle')),
'&to=',
getElementSortableId(ui.item.next(), $(this).data('handle'))
].join(''));
$(function () {

document.addEventListener('mousedown', function(event) {
if ($(event.target).closest('[data-provide="sortable"]').length) {
var $this = $(event.target).closest('[data-provide="sortable"]');
if ($this.data('sortable')) return;

$this.sortable({
handle: $this.data('handle'),
items: $this.data('items'),
placeholder: $this.data('placeholder'),
tolerance: $this.data('tolerance'),
stop: function(event, ui) {
if ($(this).data('sortUrl')) {
// determine whether we move the element up or down
$.ajax([
$(this).data('sortUrl'),
'&from=',
getElementSortableId(ui.item, $(this).data('handle')),
'&to=',
getElementSortableId(ui.item.next(), $(this).data('handle'))
].join(''));
}
else
{
$(this).children().each(function(i){
$(this).find('[data-sortable="position"]').val(i);
});
}
}
else
{
$(this).children().each(function(i){
$(this).find('[data-sortable="position"]').val(i);
});
}
}
});
});
});
}
}, true);
});

}(window.jQuery);!function ($) {
Expand Down
2 changes: 1 addition & 1 deletion web/js/bootstrap-extensions.min.js

Large diffs are not rendered by default.

61 changes: 32 additions & 29 deletions web/js/bootstrap-extensions/bootstrap-jquery-ui-sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,39 @@
/* sortable DATA-API
* ============ */

$(function () {
$(document).on('mouseover.sortable.data-api', '[data-provide="sortable"]', function (e) {
var $this = $(this);
if ($this.data('sortable')) return;
e.preventDefault();
$this.sortable({
handle: $this.data('handle'),
items: $this.data('items'),
placeholder: $this.data('placeholder'),
tolerance: $this.data('tolerance'),
stop: function(event, ui) {
if ($(this).data('sortUrl')) {
// determine whether we move the element up or down
$.ajax([
$(this).data('sortUrl'),
'&from=',
getElementSortableId(ui.item, $(this).data('handle')),
'&to=',
getElementSortableId(ui.item.next(), $(this).data('handle'))
].join(''));
}
else
{
$(this).children().each(function(i){
$(this).find('[data-sortable="position"]').val(i);
});
$(function () {

document.addEventListener('mousedown', function(event) {
if ($(event.target).closest('[data-provide="sortable"]').length) {
var $this = $(event.target).closest('[data-provide="sortable"]');
if ($this.data('sortable')) return;

$this.sortable({
handle: $this.data('handle'),
items: $this.data('items'),
placeholder: $this.data('placeholder'),
tolerance: $this.data('tolerance'),
stop: function(event, ui) {
if ($(this).data('sortUrl')) {
// determine whether we move the element up or down
$.ajax([
$(this).data('sortUrl'),
'&from=',
getElementSortableId(ui.item, $(this).data('handle')),
'&to=',
getElementSortableId(ui.item.next(), $(this).data('handle'))
].join(''));
}
else
{
$(this).children().each(function(i){
$(this).find('[data-sortable="position"]').val(i);
});
}
}
}
});
});
});
}
}, true);
});

}(window.jQuery);

0 comments on commit 009b776

Please sign in to comment.