<commit_before>import Em from 'ember';
import { getRouter } from 'ember-href-to/lib/container-lookup';

var appNeedsClickHandler = true;

function setupClickHandler() {
  Em.$(document.body).on('click', 'a', function(e) {
    var $target = Em.$(e.currentTarget);
    var handleClick = (e.which === 1 && !e.ctrlKey && !e.metaKey);

    if(handleClick && !$target.hasClass('ember-view') && Em.isNone($target.attr('data-ember-action'))) {
      var router = getRouter();

      var url = $target.attr('href');
      if(url && url.indexOf('://') === -1) {
        var rootUrlLength = router.rootURL.length;
        if(rootUrlLength > 1) {
          url = url.substr(rootUrlLength);
        }

        if(router.router.recognizer.recognize(url)) {
          router.handleURL(url);
          router.router.updateURL(url);
          return false;
        }
      }
    }
    return true;
  });
}

export function hrefTo(params) {
  if(appNeedsClickHandler) {
    setupClickHandler();
    appNeedsClickHandler = false;
  }

  var lastParam = params[params.length - 1];

  var queryParams = {};
  if (lastParam && lastParam.isQueryParams) {
    queryParams = params.pop();
  }

  var targetRouteName = params.shift();

  var args = [targetRouteName];
  args.push.apply(args, params);
  args.push({ queryParams: queryParams.values });

  var router = getRouter();
  return router.generate.apply(router, args);
}

export default Em.HTMLBars.makeBoundHelper(hrefTo);
<commit_msg>check url beings with rootURL<commit_after>import Em from 'ember';
import { getRouter } from 'ember-href-to/lib/container-lookup';

var appNeedsClickHandler = true;

function setupClickHandler() {
  Em.$(document.body).on('click', 'a', function(e) {
    var $target = Em.$(e.currentTarget);
    var handleClick = (e.which === 1 && !e.ctrlKey && !e.metaKey);

    if(handleClick && !$target.hasClass('ember-view') && Em.isNone($target.attr('data-ember-action'))) {
      var router = getRouter();

      var url = $target.attr('href');
      if(url && url.indexOf(router.rootURL) === 0) {
        var rootUrlLength = router.rootURL.length;
        if(rootUrlLength > 1) {
          url = url.substr(rootUrlLength);
        }

        if(router.router.recognizer.recognize(url)) {
          router.handleURL(url);
          router.router.updateURL(url);
          return false;
        }
      }
    }
    return true;
  });
}

export function hrefTo(params) {
  if(appNeedsClickHandler) {
    setupClickHandler();
    appNeedsClickHandler = false;
  }

  var lastParam = params[params.length - 1];

  var queryParams = {};
  if (lastParam && lastParam.isQueryParams) {
    queryParams = params.pop();
  }

  var targetRouteName = params.shift();

  var args = [targetRouteName];
  args.push.apply(args, params);
  args.push({ queryParams: queryParams.values });

  var router = getRouter();
  return router.generate.apply(router, args);
}

export default Em.HTMLBars.makeBoundHelper(hrefTo);

{'fraction_non_alphanumeric': 0.15314401622718052, 'fraction_numerical': 0.002704530087897228, 'mean_word_length': 3.126917712691771, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '5770622', 'n_tokens_mistral': 957, 'n_tokens_neox': 933, 'n_words': 182}