bidi.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. define(['bidi/numericshaping'], function(numericshaping) {
  4. 'use strict';
  5. var shaperType = '';
  6. var _uiLang = function() {
  7. return navigator.language.toLowerCase();
  8. };
  9. var _loadLocale = function() {
  10. if (_isMirroringEnabled()) {
  11. document.body.dir = 'rtl';
  12. }
  13. requirejs(['moment'], function (moment) {
  14. console.log('Loaded moment locale', moment.locale(_uiLang()));
  15. });
  16. shaperType = _uiLang().split('-')[0] == 'ar' ? 'national' : 'defaultNumeral';
  17. };
  18. var _isMirroringEnabled = function() {
  19. return new RegExp('^(ar|he)').test(_uiLang());
  20. };
  21. /**
  22. * @param value : the string to apply the bidi-support on it.
  23. * @param flag :indicates the type of bidi-support (Numeric-shaping ,Base-text-dir ).
  24. */
  25. var _applyBidi = function(value /*, flag*/) {
  26. value = numericshaping.shapeNumerals(value, shaperType);
  27. return value;
  28. };
  29. var bidi = {
  30. applyBidi: _applyBidi,
  31. isMirroringEnabled: _isMirroringEnabled,
  32. loadLocale: _loadLocale,
  33. };
  34. return bidi;
  35. });