Repository: pcottle/learnGitBranching
File: src/js/app/index.js (JavaScript)

Code before:
  var mode = eventData.mode;
  var isGit = eventData.mode === 'git';

  var displayMode = mode.slice(0, 1).toUpperCase() + mode.slice(1);
  var otherMode = (displayMode === 'Git') ? 'Hg' : 'Git';
  var regex = new RegExp(otherMode, 'g');

  document.title = intl.str('learn-git-branching').replace(regex, displayMode);
  $('span.vcs-mode-aware').each(function(i, el) {
    var text = $(el).text().replace(regex, displayMode);
    $(el).text(text);
  });

  $('body').toggleClass('gitMode', isGit);
  $('body').toggleClass('hgMode', !isGit);
};

var insertAlternateLinks = function(pageId) {
  // For now pageId is null, which would link to the main page.
  // In future if pageId is provided this method should link to a specific page

  // The value of the hreflang attribute identifies the language (in ISO 639-1 format)
  // and optionally a region (in ISO 3166-1 Alpha 2 format) of an alternate URL
  var altLinks = _.map(LocaleStore.getSupportedLocales(), function(langCode) {
    var url = "https://learngitbranching.js.org/?locale=" + langCode;
    return '<link rel="alternate" hreflang="'+langCode+'" href="' + url +'" />';
  });
  var defaultUrl = "https://learngitbranching.js.org/?locale=" + LocaleStore.getDefaultLocale();
  altLinks.push('<link rel="alternate" hreflang="x-default" href="' + defaultUrl +'" />');
  $('head').prepend(altLinks);

};

var intlRefresh = function() {
  if (!window.$) { return; }
  $('span.intl-aware').each(function(i, el) {
    var intl = require('../intl');
    var key = $(el).attr('data-intl');
    $(el).text(intl.str(key));
  });
};

var initRootEvents = function(eventBaton) {
  // we always want to focus the text area to collect input
  var focusTextArea = function() {
    $('#commandTextField').focus();
  };
  focusTextArea();

  $(window).focus(function(e) {
    eventBaton.trigger('windowFocus', e);

Review comment (bug):
a lot of this will break if the langCode has a `"` for some reason. maybe we can uri encode or use jquery to set the attributes? will be cleaner than doing string concats

Code after:
  var isGit = eventData.mode === 'git';

  var displayMode = mode.slice(0, 1).toUpperCase() + mode.slice(1);
  var otherMode = (displayMode === 'Git') ? 'Hg' : 'Git';
  var regex = new RegExp(otherMode, 'g');

  document.title = intl.str('learn-git-branching').replace(regex, displayMode);
  $('span.vcs-mode-aware').each(function(i, el) {
    var text = $(el).text().replace(regex, displayMode);
    $(el).text(text);
  });

  $('body').toggleClass('gitMode', isGit);
  $('body').toggleClass('hgMode', !isGit);
};

var insertAlternateLinks = function(pageId) {
  // For now pageId is null, which would link to the main page.
  // In future if pageId is provided this method should link to a specific page

  // The value of the hreflang attribute identifies the language (in ISO 639-1 format)
  // and optionally a region (in ISO 3166-1 Alpha 2 format) of an alternate URL

  var altLinks = LocaleStore.getSupportedLocales().map(function(langCode) {
    var url = "https://learngitbranching.js.org/?locale=" + langCode;
    return '<link rel="alternate" hreflang="'+langCode+'" href="' + url +'" />';
  });
  var defaultUrl = "https://learngitbranching.js.org/?locale=" + LocaleStore.getDefaultLocale();
  altLinks.push('<link rel="alternate" hreflang="x-default" href="' + defaultUrl +'" />');
  $('head').prepend(altLinks);

};

var intlRefresh = function() {
  if (!window.$) { return; }
  $('span.intl-aware').each(function(i, el) {
    var intl = require('../intl');
    var key = $(el).attr('data-intl');
    $(el).text(intl.str(key));
  });
};

var initRootEvents = function(eventBaton) {
  // we always want to focus the text area to collect input
  var focusTextArea = function() {
    $('#commandTextField').focus();
  };
  focusTextArea();

  $(window).focus(function(e) {
    eventBaton.trigger('windowFocus', e);