<commit_before>/*! knockout-spa (https://github.com/onlyurei/knockout-spa) * Copyright 2015-2016 <NAME> * MIT Licensed (https://raw.githubusercontent.com/onlyurei/knockout-spa/master/LICENSE) */
define(['framework/page', 'app/shared/routes', 'util/dom', 'director', 'jquery', 'sugar'], function (
  Page, Routes, Dom, Router) {

  function initPage(pageModulePath, controller) {
    require([pageModulePath], function (page) {
      var pathParts = pageModulePath.split('/');
      var pageName = pathParts.slice(1, pathParts.length - 1).join('-');
      Page.init(pageName, page, controller, pageModulePath);
    });
  }

  var routes = {};
  Object.each(Routes, function (key, value) {
    var values = value.split(' ');
    var pageModulePath = values[0];
    var controllerName = values[1];
    routes[key] = function () {
      Page.loading(true);
      var args = Array.prototype.slice.call(arguments, 0);
      var controller = controllerName ? function (page) {
        page.controllers[controllerName].apply(null, args);
      } : null;
      initPage(pageModulePath, controller);
    };
  });

  var router = new Router(routes).configure({
    strict: false,
    html5history: true, //TODO change to false to use hash if it's not practical to use HTML5 history api (e.g. no catch-all route on the server side, need to support IE 9 and below, etc.)
    convert_hash_in_init: false,
    notfound: function () {
      routes['/error/:code'](404);
    }
  });

  var urlNotAtRoot = window.location.pathname && (window.location.pathname != '/');

  if (!router.historySupport && urlNotAtRoot) {
    window.location.href = '/#' + (window.location.pathname.startsWith('/') ? '' : '/') + window.location.pathname;
    return;
  }

  if (urlNotAtRoot) {
    router.init();
  } else {
    router.init('/');
  }

  $('body').on('click', 'a[href]', function (event) {
    var anchor = $(this)[0];
    var href = anchor.href.compact();
    var origin = Dom.getOriginFromLocation(anchor);
    if (href && !href.startsWith('#') && ((origin === window.location.origin) || (origin === '://')) &&
        ($(this).attr('target') != '_blank') && !$(this).data('go') && !event.ctrlKey && !event.metaKey) {
      event.preventDefault();<commit_msg>Fix href issue for IE9 for graceful fallback to hash.<commit_after>/*! knockout-spa (https://github.com/onlyurei/knockout-spa) * Copyright 2015-2016 <NAME> * MIT Licensed (https://raw.githubusercontent.com/onlyurei/knockout-spa/master/LICENSE) */
define(['framework/page', 'app/shared/routes', 'util/dom', 'director', 'jquery', 'sugar'], function (
  Page, Routes, Dom, Router) {

  function initPage(pageModulePath, controller) {
    require([pageModulePath], function (page) {
      var pathParts = pageModulePath.split('/');
      var pageName = pathParts.slice(1, pathParts.length - 1).join('-');
      Page.init(pageName, page, controller, pageModulePath);
    });
  }

  var routes = {};
  Object.each(Routes, function (key, value) {
    var values = value.split(' ');
    var pageModulePath = values[0];
    var controllerName = values[1];
    routes[key] = function () {
      Page.loading(true);
      var args = Array.prototype.slice.call(arguments, 0);
      var controller = controllerName ? function (page) {
        page.controllers[controllerName].apply(null, args);
      } : null;
      initPage(pageModulePath, controller);
    };
  });

  var router = new Router(routes).configure({
    strict: false,
    html5history: true, //TODO change to false to use hash if it's not practical to use HTML5 history api (e.g. no catch-all route on the server side, need to support IE 9 and below, etc.)
    convert_hash_in_init: false,
    notfound: function () {
      routes['/error/:code'](404);
    }
  });

  var urlNotAtRoot = window.location.pathname && (window.location.pathname != '/');

  if (!router.historySupport && urlNotAtRoot) {
    window.location.href = '/#' + (window.location.pathname.startsWith('/') ? '' : '/') + window.location.pathname;
    return;
  }

  if (urlNotAtRoot) {
    router.init();
  } else {
    router.init('/');
  }

  $('body').on('click', 'a[href]', function (event) {
    var href = $(this).attr('href').compact();
    var origin = Dom.getOriginFromLocation($(this)[0]);
    if (href && !href.startsWith('#') && ((origin === window.location.origin) || (origin === '://')) &&
        ($(this).attr('target') != '_blank') && !$(this).data('go') && !event.ctrlKey && !event.metaKey) {
      event.preventDefault();
{'fraction_non_alphanumeric': 0.1791907514450867, 'fraction_numerical': 0.009115162294353045, 'mean_word_length': 3.4945054945054945, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '875202', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1407, 'n_words': 317}