Problem/Motivation

#1419968: Replace $('selector', domelement) with $(domelement).find('selector') followup suggests improving tabledrag behavior by refactoring or possibly rewriting tabledrag.js It is currently slow and not a great design. Also #1261002: Draggable tables do not work on touch screen devices describes problems with tabledrag and mobile including a temporary workaround. Comments on this forum suggest there will be draggable UI support for touch events in JQuery 2.0: http://forum.jquery.com/topic/jquery-ui-and-touch-devices and there appears to be progress on github https://github.com/jquery/jquery-ui/tree/interactions

On the other hand, JQuery 2.0 will be a major point release, and if history is any indication, getting it into D8 seems unlikely. There also appear to be some jquery plugins which provide parts of what we need, but not all.

Proposed resolution

We rewrite tabledrag as initially suggested taking advantage of plugin libraries if appropriate. Even if JQuery 2.0 is released in time for D8, there is no guarantee it will a) resolve the mobile issues, b) work any better than what we have, and c) have consensus for getting into D8. Rewrite/rework with plugin seems a sensible solution. The show weights mode for tabledrag should be preserved for accessibility, and UI changes avoided.

Remaining tasks

  • Evaluate plugin libraries and add them to D8 if they're stable, and eliminate redundant code from tabledrag.js if it can be replaced with a plugin.
  • Refactor all tabledrag.js (or just remaining code if suitable libraries are found), optimize for mobile, and preserve accessibility .
  • Mobile review.
  • Accessibility team testing.
  • Document any (hopefully none) resulting changes affecting the API, javascript library, and or UI.

Original report by [cosmicdreams]

// Text of original report here.
Follow up to #1419968: Replace $('selector', domelement) with $(domelement).find('selector')

We are following up our review of javascript code by focusing on improving the tabledrag behavior. The patch from https://drupal.org/files/tabledrag-49-do-not-test.patch kicks up a full review of this.

CommentFileSizeAuthor
#12 core-js-tabledrag-lib-1415828-6.patch4.35 KBnod_

Comments

nod_’s picture

That should be a "refactor tabledrag" issue, It's not very efficient and quite messy.

Best case is making it work with jquery ui sortable, there are a few gotchas to it but it should work.

cosmicdreams’s picture

Title: tabledrag inefficiencies » Refactor the tabledrag.js library

changed the name of the issue as per #1

nod_’s picture

Title: Refactor the tabledrag.js library » Rewrite tabledrag.js
Issue tags: +mobile, +JavaScript clean-up

Makes much more sense to rewrite than refactor after all. That's the slowest piece of JS code in drupal core and it's not a great design.

If someone wants to tackle that, remember that we only need IE8 compatibility, it might not be necessary to rely on jQuery/UI for that. It needs to be mobile friendly somehow.

lewisnyman’s picture

Rumour has it the jquery ui team is working on bringing touch event support to drag and drop. We could gamble on that getting in before D8 and head that direction.

ZenDoodles’s picture

I'm actually on the fence about adding plugins. Some look like they may be helpful, but I'm not seeing anything terribly compelling either. I still wanted to add evaluating them to cover those bases.

nod_’s picture

Don't like plugins too much either but whatever works :)

#817176: UI Pattern suggestion for better accessibility of table drag implementation

bowersox’s picture

When working on tabledrag.js, keep in mind that a lot of work went into making an accessible mode. The "show row weights" functionality is not the most beautiful UX compromise, but it does allow D7 to be accessible so that all people are able to re-order menus and build a Drupal site.

If we're going to re-think tabledrag, accessibility needs to be a consideration.

It might be good to clarify whether this issue includes a UI change or not. If we are just refactoring the code but leaving the UI untouched, then you don't need to do so much coordination and build consensus with the UX and Accessibility teams.

nod_’s picture

Well I'm just planning on a js refactor, not touching the UI. If people want to change the UI it's in the other thread.

If the refactor is well done it should be easy to change/tweak the ui without having to change everything :)

bowersox’s picture

@nod_ that greatly simplifies things. The accessibility team is always eager to help if this grows into a UI change, but this will be simpler. We'll be glad to test when a new draft of this is ready. Thanks!

bowersox’s picture

Issue summary: View changes

Updated issue summary for clarification and to cross reference #1261002.

ZenDoodles’s picture

Added accessibility concerns to issue summary.

j0rd’s picture

Been looking into this as well for a D6 site.

I would recommend writing your own custom JS rather than using a plugin to reduce cruft not needed in core. With that said, I would also write the new tabledrag as a plugin, so that others can use it in the frontend on their sites easily.

I have another "speed fix" for tabledrag here:
#1571814: tableDrag.js, reduce the number of calls of .length from 33478 to 455

I've also been looking into an optimal setting for this.scrollSettings.interval which is used as the miliseconds to setInterval with regards to scrolling the window. Currently it's set to 50ms, which seems like it could be a little higher to reduce browser load and not be noticeable to the end user. 100ms, could reduce the amount of calls in half and still provide 10 updates a second. From checking the issue queue it doesn't appear there's been any discussion to this variable.

nod_’s picture

StatusFileSize
new4.35 KB

closing #1415828: Tabledrag should be a library for this one. and bring last patch from the other issue here.

sun’s picture

Hrm. This issue here looks like a major effort, which might even take months to complete, given how much research and also testing will have to be done. Contrary to that, #1415828: Tabledrag should be a library is a very trivial refactoring (and the replacement of jquery cookie was never within the scope of that issue).

I'd really prefer to be on the safe side for D8 and do the trivial refactoring first, which can land at any time and does not require manual testing. Therefore, I'm going to re-open the issue.

nod_’s picture

@bowersox, @all: the scope of this issue just changed, there will be UI changes.

Bojhan and I will be doing some brainstorming this friday around this, so if you have ideas/mockups about how you'd like to see tabledrag working please post your ideas in #817176: UI Pattern suggestion for better accessibility of table drag implementation :)

nod_’s picture

There is a working patch over at #1268530: drupal_add_tabledrag: Add javascript hooks for module writers that adds a custom event when a row changed. The new implementation should provide custom events for various actions as well.

robloach’s picture

I like this issue a lot. Taking the jQuery UI route would benefit from #1085590: Update to jQuery UI 1.9.

mgifford’s picture

There are a few other efforts to revamp the table drag in D8.

Mostly wanting to tag this to verify that it still works with screen readers & keyboard only users.

nod_’s picture

There are several issues with the jquery road.

1) Table row dragging is not officially supported. I made a prototype and it worked though (IE? don't know)
2) There is no tree-like structure supported
3) I am not sure we can support the move restrictions we currently have.

Now there are serval new things since my testing:
1) we're moving to admin lists (ul, li and all that) for admin tables #1276908: Administrative tables are too wide for smaller screens, so that'll help with jquery support
2) with that we can nest lists and have a proper tree structure with nested lis (ok, that one is a loooong shot but it might be possible), which would help for setting up jquery sortable and make it possible to implement the same kind of restrictions we have right now.
3) I'm happy to get rid of some of them, the mobile thing will likely kill a couple of them as long as nobody wants the exact same UX we should be good.

nod_’s picture

Priority: Normal » Major

This stuff needs to work well on mobile, bumping to major since it currently doesn't and that's a lot of work needing to happen before december.

kiphaas7’s picture

BONUS: Investigate if adding basic events and detach makes sense, as described in #1763812: [META] Provide complete attach/detach with basic events.

It probably makes sense to add this.

nod_’s picture

tag

moshe weitzman’s picture

Re #18, we ended up not using lists for responsive tables - they are good ole table tags. So this stays relevant and important. Keep on going, guys!

nod_’s picture

Priority: Major » Normal
quicksketch’s picture

Title: Rewrite tabledrag.js » Rewrite tabledrag.js to use jQuery UI
Status: Active » Closed (won't fix)

1) Table row dragging is not officially supported. I made a prototype and it worked though (IE? don't know)
2) There is no tree-like structure supported
3) I am not sure we can support the move restrictions we currently have.

Hi guys, looks like @nod_ already identified all the issues. But as the original author of tabledrag.js, I wanted to reiterate that there was a *reason* why we didn't use jQuery UI to begin with. If jQuery UI would have been a good fit, we probably would have used it, even back then in Drupal 6. However jQuery UI wasn't and still isn't a good fit for table drag. Moving table rows outside of their parent table does not work at all. The DOM simply does not allow it. I tried this approach when tabledrag.js was originally written and it won't work.

There is definitely places for improvement in tabledrag, especially around performance. However right now the biggest slowdowns with tabledrag isn't the JS itself, it's the number of items in select lists that are in the hidden weight column. You can literally get 500KB of select list items on a page that has a big menu tree for example.

Anyway in short:

  • Using jQuery UI is not going to work.
  • tabledrag.js could be converted to a jQuery plugin, but unless someone is going to maintain it as an independent jQuery plugin, there isn't much advantage to abstracting it from Drupal's particular use-case.
  • Touch support is clearly important, that's over in #1261002: Draggable tables do not work on touch screen devices.

I'm retitling this issue to reflect the discussion that followed and marking won't fix. If anyone thinks I'm incorrect, please reopen. I think we'd be better served by improving our existing code to eliminate inefficiencies rather than pursuing a big hand-wavy issue like this.

Unmarked duplicates:
#1164804: Table rows are intended to allow dragging, but this is not clear.

nod_’s picture

That's fair enough, agreed with the won't fix.

I'll try to get something going in contrib and see what happens for D9.

j0rd’s picture

@quicksketch & @nod_ the original purpose of this issue was to speed up tabledrag.js for large tables for which it is currently slow.

I personally do not care what library this uses to improve the performance of table drag, but currently on large menu's or taxonomies tabledrag.js is horribly slow in D6 and D7. This is something that can probably be improved with some JS tweaks.

I don't think the original issue was to "refactor tabledrag.js to use jquery ui" but simply speed up tabledrag.

treksler’s picture

there is a really easy soluton to the select list problem ... don't use them .. use a textbox instead .. 99% of the time nobody sees them anyway, and the 1% would need to learn to type a number in there

treksler’s picture

Issue summary: View changes

Added accessibility concerns to issue summary.