I would be grateful for some direction or an idea of where to look. I feel like I'm going in a circle with the resource module docs.
What I need to do is load a js module based on language direction in a skin. Ltr load a ltr.js, rtl direction load a rtl.js instead. Here is what I came up with, please let me know if there is a better way to do this.
if ( $GLOBALS['wgLang']->getDir() == 'rtl' ) { $out->addModules('skins.script-rtl.js'); } else { $out->addModules('skins.script-ltr.js'); }
Preliminary testing seems to work, is there a better or recommended way?
Thanks Tom
First note, don't use $wgLang; use getLanguage on the closest context you have (depends on where your code is).
Secondly, why do you have separate scripts for rtl/ltr? Writing two scripts that do the same thing sounds really weird when JS is itself a programming language.
You can get directionality information about the current language right out from the DOM.
document.documentElement.dir === 'rtl'
~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://danielfriesen.name/]
On 2016-06-09 7:27 PM, Tom wrote:
I would be grateful for some direction or an idea of where to look. I feel like I'm going in a circle with the resource module docs.
What I need to do is load a js module based on language direction in a skin. Ltr load a ltr.js, rtl direction load a rtl.js instead. Here is what I came up with, please let me know if there is a better way to do this.
if ( $GLOBALS['wgLang']->getDir() == 'rtl' ) { $out->addModules('skins.script-rtl.js'); } else { $out->addModules('skins.script-ltr.js'); }
Preliminary testing seems to work, is there a better or recommended way?
Thanks Tom
MediaWiki-l mailing list To unsubscribe, go to: https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
Thanks Daniel, under public function initPage, although I will have to do the same for rtl CSS under setupSkinUserCss for CSS modules. Unfortunately Janus isn't perfect for flipping but I still have a little bit more investigation work to do to see if it's just a few things that need tweaking.
I haven't run diffs against the framework's download ltr js files vs the download of rtl js files. I know the CSS files are modified, so I will have to use the same method for conditional module loading. The js files could all be same and all direction aware, just need to look at them all. Just picking some low hanging fruit in my initial test and verifying the best method to make it conditional.
Tom
On Jun 9, 2016, at 10:54 PM, Daniel Friesen daniel@nadir-seen-fire.com wrote:
First note, don't use $wgLang; use getLanguage on the closest context you have (depends on where your code is).
Secondly, why do you have separate scripts for rtl/ltr? Writing two scripts that do the same thing sounds really weird when JS is itself a programming language.
You can get directionality information about the current language right out from the DOM.
document.documentElement.dir === 'rtl'
~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://danielfriesen.name/]
On 2016-06-09 7:27 PM, Tom wrote: I would be grateful for some direction or an idea of where to look. I feel like I'm going in a circle with the resource module docs.
What I need to do is load a js module based on language direction in a skin. Ltr load a ltr.js, rtl direction load a rtl.js instead. Here is what I came up with, please let me know if there is a better way to do this.
if ( $GLOBALS['wgLang']->getDir() == 'rtl' ) { $out->addModules('skins.script-rtl.js'); } else { $out->addModules('skins.script-ltr.js'); }
Preliminary testing seems to work, is there a better or recommended way?
Thanks Tom
MediaWiki-l mailing list To unsubscribe, go to: https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
MediaWiki-l mailing list To unsubscribe, go to: https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
mediawiki-l@lists.wikimedia.org