Hello,
I suggest adding an RTL property to the page class/element; then check this property before setting any button/icon default positions and check it in sliders code as shown below; then make another RTL CSS file that overrides/reverses some values (floats, margins, text-direction.. etc) which users can simply link when RTL support is needed.
Here is my idea:
1) Make a property for RTL, I would make it a boolean and name it IsRTL or make it as an enumeration or a string and name it something like data-uidirection. The default value is false/ltr so it should be explicity set on the mark-up when RTL is needed, for example:
<div data-role="page" data-uidirection="rtl">
...
</div>
2) In jQuery JS file check the property in the slider code to make sliders and flip switches work properly, the value should be increased when dragging the handle to the LEFT or pressing the LEFT button and vice versa:
The switch statement on line 7792 may look like this:
- // move the slider according to the keypress
- // var isRtl = something like closest(".ui-page").attr("data-uidirection") == "rtl";
- switch (event.keyCode) {
- case $.mobile.keyCode.HOME:
- self.refresh(min);
- break;
- case $.mobile.keyCode.END:
- self.refresh(min);
- break;
- case $.mobile.keyCode.PAGE_UP:
- case $.mobile.keyCode.UP:
- self.refresh(index + step);
- break;
- case $.mobile.keyCode.PAGE_DOWN:
- case $.mobile.keyCode.DOWN:
- self.refresh(index - step);
- break;
- case $.mobile.keyCode.RIGHT:
- isRtl ? self.refresh(index - step) : self.refresh(index + step);
- break;
- case $.mobile.keyCode.LEFT:
- isRtl ? self.refresh(index + step) : self.refresh(index - step);
- break;
- }
For handle dragging, I guess its code on line 7860 and you can only subtract the percent from 100, like:
- // after percent = Math.round(((data.pageX - this.slider.offset().left) / this.slider.width()) * 100);
- if (isRtl) { percent = 100 - percent; }
Then finally on line 7901 check the property to decide which CSS to change:
- this.handle.css(isRtl ? "right" : "left", percent + "%");
3) Check the property before setting default button/icon positions to reverse the value:
Line 4807, if it is RTL the back button should be on the right and its arrow should be a right arrow:
- var btnPositionDirection = isRtl ? "right" : "left";
- var arrowPositionChar = isRtl ? "r" : "l";
- backBtn = $("<a href='javascript:void(0);' class='ui-btn-" + btnPositionDirection + "' data-" + $.mobile.ns + "rel='back' data-" + $.mobile.ns + "icon='arrow-" + arrowPositionChar + "'>" + o.backBtnText + "</a>")
Line 4995, default icon position should be 'right' when it is RTL:
- o.iconpos = o.iconpos || (isRtl ? "right" : "left");
Line 5252, default icon position:
- iconpos: $el.jqmData("iconpos") || o.iconPos || (isRtl ? "right" : "left")
Line 5494, default arrow on lists should be to the left when it is RTL:
- splitIcon: isRtl ? "arrow-l" : "arrow-r"
Lines 5684 and 5684:
- iconpos: isRtl ? "left" : "right",
- icon: a.length > 1 || icon === false ? false : icon || isRtl ? "arrow-l" : "arrow-r",
Line 7969, select menu icon position is left when it is RTL:
- iconpos: isRtl ? "left" : "right"
4) Make the CSS file that overrides/reverses some values that developers will link to when they need RTL, I would name it something like rtl.jquery.mobile-1.2.0.css, for example:
- /* original .ui-controlgroup .ui-btn-icon-notext .ui-btn-inner .ui-icon { position: absolute; top: 50%; right: 50%; margin: -9px -9px 0 0; } */
- .ui-controlgroup .ui-btn-icon-notext .ui-btn-inner .ui-icon {margin: -9px 0 0 -9px;}
- /* original .ui-footer .ui-navbar .ui-grid-d li.ui-block-e .ui-btn { margin-right: -4px; } */
- .ui-footer .ui-navbar .ui-grid-d li.ui-block-e .ui-btn { margin-left: -4px; }
- /* and so on, but DON'T reverse ui-btn-icon-left, ui-btn-icon-right, ui-btn-left, ui-btn-right */
I believe you can come up with better ways to do that. Regards.