UNPKG

office-ui-fabric-react

Version:

Reusable React components for building experiences for Office 365.

38 lines (37 loc) 1.16 kB
define(["require", "exports", './KeyCodes'], function (require, exports, KeyCodes_1) { "use strict"; var _isRTL; /** * Gets the rtl state of the page (returns true if in rtl.) */ function getRTL() { if (_isRTL === undefined) { _isRTL = document.documentElement.getAttribute('dir') === 'rtl'; } return _isRTL; } exports.getRTL = getRTL; /** * Sets the rtl state of the page (by adjusting the dir attribute of the html element.) */ function setRTL(isRTL) { document.documentElement.setAttribute('dir', isRTL ? 'rtl' : 'ltr'); _isRTL = isRTL; } exports.setRTL = setRTL; /** * Returns the given key, but flips right/left arrows if necessary. */ function getRTLSafeKeyCode(key) { if (getRTL()) { if (key === KeyCodes_1.KeyCodes.left) { key = KeyCodes_1.KeyCodes.right; } else if (key === KeyCodes_1.KeyCodes.right) { key = KeyCodes_1.KeyCodes.left; } } return key; } exports.getRTLSafeKeyCode = getRTLSafeKeyCode; });