V
V
Vadim2014-01-07 18:11:59
JavaScript
Vadim, 2014-01-07 18:11:59

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" />&nbsp;Category</a>
    </li>
    <li id="1">
        <a href="/_loads/category/1"><img src="/static/images/star.png" alt="cat" />&nbsp;games</a>
    </li>
    <li id="5">
        <a href="/_loads/category/5"><img src="/static/images/star.png" alt="cat" />&nbsp;Category 2</a>
    </li>
    <li id="3">
        <a href="/_loads/category/3"><img src="/static/images/star.png" alt="cat" />&nbsp;ololo</a>
    </li>
  </ul>
  <!-- ... -->
  </body>


The contents of the file /_loads/static/js/categories.js
$(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();
});


Callbak receives the id of the moved element on the update event, determines its new position and sends this data to the script. Everything is ok in Yandex.Browser. But Firefox complains that event.toElement is undefined.
Can you tell me how in Firefox you can access a floating element?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex Pro, 2014-01-07
@Folour

Google?

M
mmka, 2014-01-07
@mmka

in general firefox has started to piss me off a bit lately

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question