Answer the question
In order to leave comments, you need to log in
Firefox + sortabble: how to access an element that has been shifted?
Page layout
<head>
<script src="/static/js/jquery-1.10.2.min.js"></script>
<script src="/static/js/jquery-ui-1.10.3.custom.min.js"></script>
<script>var ajaxPath = '/_loads/admApi/changePosition/0';</script>
<script src="/_loads/static/js/categories.js"></script>
</head>
<body>
<!-- ... -->
<!-- Content section begin -->
<ul class="links" id="draggable">
<li id="4">
<a href="/_loads/category/4"><img src="/static/images/star.png" alt="cat" /> Category</a>
</li>
<li id="1">
<a href="/_loads/category/1"><img src="/static/images/star.png" alt="cat" /> games</a>
</li>
<li id="5">
<a href="/_loads/category/5"><img src="/static/images/star.png" alt="cat" /> Category 2</a>
</li>
<li id="3">
<a href="/_loads/category/3"><img src="/static/images/star.png" alt="cat" /> ololo</a>
</li>
</ul>
<!-- ... -->
</body>
$(document).ready(function(){
var container = $('#draggable');
container.sortable({
items: 'li',
containment: 'parent',
tolerance: 'pointer',
scroll: false,
opacity: 0.9,
cursor: 'hand',
update: function(event) {
var li = event.toElement.parentNode;
var category, currentPosition, children;
if(li.tagName == 'A') {
li = li.parentNode;
}
category = li.id;
children = container[0].getElementsByTagName('li');
for(var i = 0; i < children.length; i++) {
if(category == children[i].id) {
currentPosition = i + 1;
}
}
$.get(ajaxPath, {
currentPosition: currentPosition,
category: category
}, function(data) {
if(data !== '') {
container.sortable('cancel');
alert(data);
}
});
}
});
container.disableSelection();
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question