While drag and drop support was added, RTL concerns were completely put aside, as Steven Wittens noted. The last few days, I went in and gradully fixed the two CSS bugs I noted:
- http://drupal.org/cvs?commit=90204 - the indentation divs were left floated
- http://drupal.org/cvs?commit=90089 - table drag handlers were left positioned
But there are JavaScript bugs still. If you set your Drupal language to Arabic for example, all is nicely positioned, the drag and drop handles and indents are positioned nicely on the right, as intended. But, as soon as you have a hierarchical list (ie. try with menus, taxonomy or forums), there are two UI problems:
- when dragging an item with children, the lines connecting the items are not properly facing towards the items
- you need to move the item left(!) to make it one level higher, and right to make it one level deeper (while the visuals suggest otherwise)
Note, that you can detect an RTL page by looking for body's direction property to be rtl.
Comment | File | Size | Author |
---|---|---|---|
#74 | 197641-74.patch | 1.35 KB | ravi.shankar |
#67 | core-tabledrag_rtl_pointer_events-197641-67.patch | 1.2 KB | huzooka |
#37 | fix-tabledrag-d7-197641-37.patch | 733 bytes | herom |
#33 | 197641-33.patch | 713 bytes | herom |
#29 | 197641-29.patch | 1.25 KB | good_man |
Comments
Comment #1
Gábor HojtsyKeyboard event handlers are also need their effects swapped.
Comment #2
Gábor HojtsyLooked into fixing the connector lines, and it seemed from the tree images, that it is indeed built into them, so with a different background position, RTL themes are served.
This is still short of fixing the JS mouse and keyboard events.
Comment #3
Gábor HojtsyDoh, this could be made simpler on the RTL css side.
Comment #4
quicksketchI did think about RTL support when building drag and drop, but I found that floating items left or right will only give us a small amount of benifit. For full RTL support, wouldn't we need to write all our tables so the columns could be in reverse order? Floating the handles right instead of left while still remaining in the left-most column seems like it would do more harm than good, as the handles would be located in the middle of the table. Is there a solution for tables in the rest of Drupal core that I could base a fix on?
Comment #5
Gábor Hojtsyquicksketch: Try it! Enable locale module, add Arabic, and switch your site to Arabic. Browsers flip the order of table columns automatically. So you get the enabled checkboxes for modules on the right, now with my fixes, you get the dnd handle on the right, you get the indentation on the right, and with the applied patch above, even the connectors face to left properly. BUT the JavaScript would need to indent items when you move to the left and outdent, when you move to the right. Currently it does this in the other direction. The same goes for keyboard events.
Browsers are intelligent enough to reverse stuff like character order or table column order. They are not intelligent enough to reverse our indenting code in JavaScript ;)
So basically we need the left/right indent/outdent actions swapped when body has a direction=rtl CSS rule. Also for keyboard shortcuts. Otherwise, with the patch above, all seems to work for me right in RTL.
Comment #6
quicksketchOh fancy! That makes everything much more feasible. I'll whip up something to swap the keys and mouse directions.
Comment #7
Gábor HojtsyGreat. Awaiting your patch soon.
Comment #8
quicksketchI have javascript that will successfully switch the direction (just multiple by -1), but I can't find any property in the page source that would indicate RTL languages, other than the inclusion of -rtl css files. Is there an existing method for this or should we add one to the body tag?
Comment #9
quicksketchHere's a patch that adds the RTL direction as part of drupal_add_tabledrag(). It's not incredibly ideal, but it would allow you to have a right-aligned table and a left-aligned table on the same page (however unlikely). If there's a more central place to get RTL I'd prefer just making it one or the other per-page, but this method certainly will work and changes none of the parameters of our current functions.
Comment #10
quicksketchOops. That last patch reversed LTR languages drag and drop :)
This one works both ways.
Comment #11
Gábor HojtsyHm, as I have indicated two times above, and as visible in the rtl themes, body gets a direction CSS property set to RTL in RTL themes. While it is theoretically possible that LTR tables might end up on the same page, they might receive a direction property or LTR too. I don' think that looking at the language object is the right way to go here. The information about the page being RTL is already in the styles.
People suggested earlier that we should actually add dir="rtl" as a HTML attribute to the body tag, so pages displaying unstyled will still be acceptable with their semantics. If this HTML attribute would make your life easier, feel free to add this to core themes. This can be done with:
- adding a
$variables['direction'] = ' dir="'. ($language->direction ? 'rtl' : 'ltr') .'"';
to theme.inc's variable init- then adding
print $direction;
to the body tag on core themes.I think this should give the JS enough info in the HTML code to hook on.
Comment #12
quicksketchSorry Gábor I didn't read the "CSS" mention and was looking for something in the HTML source. The direction = 'rtl' in the CSS code is plenty enough. This patch checks for the direction == 'rtl' and if so flips the logic. Otherwise it assumes LTR.
Comment #13
Gábor HojtsyThanks. I tested this, found it nicely working, so removed the console.log call and committed.
Comment #14
mooffie CreditAttribution: mooffie commentedSuperb! Thanks!
Would you mind if we checked the directionality of the table instead of the body's? I've attached this 'fix' as a little patch. I know that this doesn't make a _lot_ of sense right now to have LTR tables on RTL pages --because we don't support both rtl and ltr CSS on the same page-- but it's nice nevertheless.
Note that the css() method gives us _computed_ styles, so we don't have to have a 'direction: rtl/ltr' directive on the tables themselves: it's inherited from an ancestor container (such as BODY).
The patch includes three other tiny fixes:
1. Made the title of the handle translatable.
2. Fixed something that looked like a bug ("if ($('...', context)").
3. Changed "$Id $" to "$Id$".
(And sorry for piggybacking on this issue!)
Comment #15
Gábor HojtsyNo patch attached. Not critical.
Comment #16
mooffie CreditAttribution: mooffie commentedHere's the patch again. (I know I attached it. It's probably a bug here.)
Comment #17
Gábor HojtsyDrupal.t() and the Id changes look good. The other two I am asking quicksketch to comment.
Comment #18
quicksketchUsing
.attr('title', Drupal.t('Drag to re-order'))
to to set the title isn't really necessary, I probably would've just included the translated text inline as part of the<a>
tag, but that's just a matter of style. This approach is more readable, which is probably the reason for doing it this way.This looks great, the $Id$ tags I'd been meaning to fix with every patch but it kept slipping away. I tested it in all browsers (IE6/7, Opera, Safari, Firefox) just to ensure that the computed css was being retrieved properly. Works like a charm!
Comment #19
mooffie CreditAttribution: mooffie commentedThanks for giving the computed css an extra check.
Although uncommon, translated strings may contain quotes and apostrophes, so it's a Good Thing to ensure they are escaped. attr() relieves us from this task. Unlike in English, these two characters aren't used just for quoting. Here's what happened for somebody who didn't escape his JS strings...
Comment #20
Gábor HojtsyGreat, thanks, committed.
Comment #21
quicksketchThanks for that tip mooffie! I'll keep that in mind for future work. :D
Gábor, prompt as always. Thanks!
Comment #22
(not verified) CreditAttribution: commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #23
elcuco CreditAttribution: elcuco commentedI opened this issue #374652: Nesting of sublists in RTL is broken ... it seems this is not fixed in Drupal 6.
What's wrong? It seems the code does support this.
Comment #24
elcuco CreditAttribution: elcuco commentedOk. Looked at it again (around line 412):
This works on my setup (FF 3, Opera 9.63 on Linux/64). However I got another report on IRC that this does not work.
As mentioned above - it would be smarter to check the direction of the element instead of the body: what happens when I force an LTR table on an RTL window? Trust me, this will happen! ;-)
Credits to this "patch" go to yhager who looked at the code and found a possible bug.
Comment #25
yhager CreditAttribution: yhager commentedI have to reopen this, as this does not work for me.
The code in tabledrag.js computes the indentation amount in:
Then, it measures the amount of mouse movement, and divides by indentAmount, but then multiplied by self.rtl:
The multiplication is wrong, since indentAmount calculation already takes RTL in consideration, so the patch attached simply removed this multiplication.
Comment #26
NaX CreditAttribution: NaX commentedThe only problem I was having was that I had to drag in the same direction as when in a ltr language, so in a rtl language it would be the opposite to the direction I would want to move it on screen.
I don't know if this would be correct or not, but the only thing that worked for me was to change
this.rtl
to 1, regardless of direction.When I first tried it, I thought I had to be wrong, but it worked.
I tested this on the Primary links admin page in English and Arabic using D 6.17 in Opera and Firefox.
From:
To:
All the other problems described in the original post seem to be resolved.
Comment #28
TR CreditAttribution: TR commentedTagging
Comment #29
good_man CreditAttribution: good_man commentedConverted #25 to git patch, I think it's simple & RTBC.
Comment #30
Gábor HojtsyCan someone else help review this?
Comment #31
sinasalek CreditAttribution: sinasalek commentedWondering why no one responded to this!
I applied patch #30 manually on Drupal 7.32 and it fixed the problem.
Haven't tried it on Drupal 6 since i'm not using it for several years now
Check on both rtl and ltr and works well
Tx Gábor
Comment #32
Gábor HojtsyBased on our backport process this would need to be fixed in 8.x now and then backported. We want to avoid introducing regressions.
Comment #33
herom CreditAttribution: herom commentedRerolled the patch.
Tested, the issue still exists in D8 and the patch fixes it. This has also been reported as working in #24, #25, and #31, so marking as RTBC.
Comment #34
alexpottCommitted 862d51f and pushed to 8.0.x. Thanks!
Comment #36
Gábor HojtsyYay :) Thanks @herom!
Comment #37
herom CreditAttribution: herom commentedRerolled for D7.
Comment #38
Gábor HojtsySame as in D8.
Comment #41
Gábor HojtsyComment #42
sinasalek CreditAttribution: sinasalek commentedDoes this work for tree tables as well? like terms
Comment #45
David_Rothstein CreditAttribution: David_Rothstein commentedTestbot fluke.
Comment #48
David_Rothstein CreditAttribution: David_Rothstein commentedComment #49
David_Rothstein CreditAttribution: David_Rothstein commentedI tried this out on the Menu administration pages to see how it worked, and yeah, it makes things way way better :)
Committed to 7.x - thanks!
Comment #52
mohsen81666 CreditAttribution: mohsen81666 commentedI'm using D7 v7.32 and I had the same problem in RTL mode. I used patch #37 and it worked, but only when we have 1 indentation. If We have more level of indentation than one, it bounces middle levels.
Patch #37 changes one line(500):
I changed another line(505) too:
It solved the problem. I checked it in ltr mode and there is no problem as far as I know.
Comment #53
herom CreditAttribution: herom commentedMarking as active so I don't miss this, but anyone feel free to post a new patch.
Also, the mentioned line exists in Drupal 8 too, so going back to 8.x
Comment #65
huzookaRe @mohsen81666's comment #52:
I'm really happy that I've found and seen your remark!
The change you're suggesting (still) fixes the issue of the hierarchy rearrangement for RTL languages.
Comment #66
huzookaComment #67
huzookaComment #71
lauriiiComment #72
TR CreditAttribution: TR commentedExactly what is still needed here? Perhaps someone can update the issue summary.
Comment #73
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedComment #74
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedAdded reroll of patch #67 for Drupal 9.1.x.
Comment #75
lauriiiThis was fixed by #3083044: Prevent line breaks in draggable (first) table cells. Since this issue has a patch committed earlier, marking as fixed.