views:

549

answers:

3

Hello everybody,

While I'm using this site quite often as a resource for jQuery related problems I can't seem to find an answer this time. So here is my first post.

During daytime at work I'm developing an informationsystem for generating MS Word documents. One of the modules I'm developing is for defining a default chapterselection for the table of contents and selecting texts by the given chapters. A user can submit new chapters and if necessary, add them as childchapter to a parent, flag them as 'adopt in TOC' and link a default text (from another module) to the chapter.

My chapterlist is retreived recursively from a MySQL table and could look something like this:

<ul class="sortableChapterlist">
  <li>1</li>
  <li>2
    <ul class="sortableChapterlist">
      <li>2.1</li>
      <li>2.2</li>
      <li>2.3
        <ul class="sortableChapterlist">
          <li>2.3.1</li>
          <li>2.3.2</li>
        </ul>
      </li>
    </ul>
  </li>
</ul>

In FireFox the code works like a charm but IE (7) doesn't seem to like it that much. I'm only able to correctly drag arround the mainchapters. When attempting to drag a subchapter, no matter it's level, the correspondending mainchapter lifts up with some child, never all.

This is the jQuery code I'm using to accomplish the task:

$(function(){
  $(".sortableChapterlist").sortable({
    opacity: 0.7,
    helper:  'clone',
    cursor:  'move'
  });

  $(".sortableChapterlist").selectable();
  $(".sortableChapterlist").disableSelection();
});

Does anybody have some ideas about this? I'm guessing IE kinda falls over the multiple class reference "chapter_list" in combination with jQuery trying to handle the draggable/sortable.

Kinds regards from Holland, Ben Fransen

+1  A: 

This is a long shot, but try to replace the underscores with something else, e.g. a hyphen. Underscores used to cause problems in some browsers.

Mozilla Developer Center: Underscores in class and ID names.

Jan Aagaard
Thanks for the quick reply! Unfortunately it didn't resolve in a working solution. Nevertheless the link you posted gave me some insight in not to use _'s in CSS. I've updated the source.
Ben Fransen
+2  A: 

I believe you could fix this by only applying the sortable to the root <ul> element, rather than all of them in the tree. This works in all browsers I have tested, but unfortunately leads to a slightly less smooth experience as the position at which the item will be inserted after dragging "jumps around" quite a bit.

Essentially this would look like this:

<ul id="sortableNestedList" class="sortableChapterlist">
  <li>1</li>
  <li>2
    <ul class="sortableChapterlist">
      <li>2.1</li>
      <li>2.2</li>
      <li>2.3
        <ul class="sortableChapterlist">
          <li>2.3.1</li>
          <li>2.3.2</li>
        </ul>
      </li>
    </ul>
  </li>
</ul>

$("#sortableNestedList").sortable({ ... });
Nikolas Stephan
But wouldn't I then end up with a sortable list for all items? I want to pick entire chapters, with subchapters to drag arround and reorder. Imo this is done by adding more `<ul>`'s?
Ben Fransen
I gave your suggestion a try but I end up only being able to drag arround the main items 1 and 2. When I click and hold for example 2.3.1. the entire block of 2 gets dragged.
Ben Fransen
I haven't tried this, but you may want to see if adding items: 'ul' as an option does what you want.
Nikolas Stephan
It should, because I have to group the nested sets somehow. I figured this should/must be done by nesting sortable lists?
Ben Fransen
A: 

I have the same problem... :-(

Maxime Asselin
I've posted another question about this problem, it fixed my problem: http://stackoverflow.com/questions/1789169/jquery-unexpected-sortable-behaviour
Ben Fransen
The comment on that answer also fixed my problem. If you're experiencing weird sortable behavior in IE, check it out.
techpeace