<commit_before>var EASING_DURATION = 500;

jQuery(document).ready(function() {
  console.log('ready event handler');
  if (ractive.tenantCallbacks==undefined) ractive.tenantCallbacks = $.Callbacks();
  ractive.tenantCallbacks.add(function() {
    ractive.initAutoComplete();
  });
  var params = getSearchParameters();
  for (idx in Object.keys(params)) {
    ractive.set(Object.keys(params)[idx], params[Object.keys(params)[idx]]);
  }
  if (ractive.get('questionnaireDef')!=undefined) ractive.fetch();
});

var ractive = new Ractive({
  el: 'containerSect',
  template: '#template',
  data: {
    q: function () {
      return ractive.toQuestionnaire(ractive.get('categories'));
    },
    easingDuration: 500, // millis
    fadeOutMessages: true,
    questionnaireDef: $('body').data('questionnaire'),
    server: $env.server,
    matchRole: function(role) {
      console.info('matchRole: '+role)
      if (window['$auth']==undefined) return false;
      if (role==undefined || $auth.getClaim('scopes').indexOf(role)>-1) {
        $('.'+role).show();
        return true;
      } else {
        return false;
      }
    },
    toId: function(name) {
      return name.toLowerCase().replace(/ /g,'_').replace('(','').replace(')','');
    },
    stdPartials: [
      { "name": "questionnaire", "url": "partials/questionnaire.html"},
      { "name": "questionnaireContact", "url": "partials/questionnaire-contact.html"},
      { "name": "sidebar", "url": $env.server+"/partials/sidebar.html"}
    ],
    toQName: function(i,j) {
      if (ractive==undefined) return;
      else return ractive.get('q.categories.'+i+'.questions.'+j+'.id');
    }
  },
  partials: {
    questionnaire: '',
    sidebar: ''
  },
  addDataList: function(d, data) {
    $('datalist#'+d.name).remove();
    $('body').append('<datalist id="'+d.name+'">');
    $.each(data, function (i,e) {
      $('datalist#'+d.name).append('<option value="'+e.name+'">'+e.name+'</option>');
    });
  },
  addSelectOptions: function(selector, data, value) {
    console.info('add selection options to '+selector+' selecting '+value);
    $(selector+' option').remove();
    $.each(data, function (i,e) {
      $(selector).append('<option '+(e.name==value ? 'selected ' : '')
          +'value="'+e.name+'">'+e.name+'</option>');
    });
  },
  applyBranding: function() {
    if (ractive.get('q.about.branding.favicon')!=undefined) {
      $('head').append('<link rel="icon" type="image/png" href="'+ractive.get('q.about.branding.favicon')+'">');
    }
    if (ractive.get('q.about.branding.link')!=undefined) {
      $('.navbar-brand').attr('href', ractive.get('q.about.branding.link'));
    }
    if (ractive.get('q.about.branding.logo')!=undefined) {
      $('.navbar-brand').empty().append('<img alt="logo" height="45px" src="'+ractive.get('q.about.branding.logo')+'"/>');
    }
  },
  fetch: function() {
    console.info('fetch');
    var url = ractive.get('questionnaireDef');
    if (!url.startsWith('http')) url = 'js/'+ractive.get('questionnaireDef')+'.json';
    $.ajax({
       type: 'GET',
       url: url,
       dataType: 'json',
       success: function(data, textStatus, jqxhr) {
         console.log('success:'+data);
         for (var i = 0 ; i < data.categories.length ; i++) {
           for (var j = 0 ; j < data.categories[i].length ; j++) {
             data.categories[i][j].optionValues = [];
           }
         }

         // sane defaults
         if (data['activeCategory']==undefined) data.activeCategory = 0;
         if (data['about']==undefined) data.about = { };
         if (data.about['branding']!=undefined) $('nav.navbar').show();
         if (data.about['title']==undefined) data.about.title = 'Questionnaire';
         if (data.about['options']==undefined) data.about.options = { };
         if (data.about.options['categoryAtATime']==undefined) data.about.options.categoryAtATime = true;
         if (data['submit']==undefined) data.submit = { };
         if (data.submit['buttonText']==undefined) data.submit.buttonText = 'Submit Now';
         if (data.submit['successPage']==undefined) data.submit.successPage = 'thanks.html';
         if (data.submit['title']==undefined) data.submit.title = "That's it!";
         if (data.submit['text']==undefined) data.submit.text = 'Thanks for your time.';

         ractive.set('q', data);
         ractive.applyBranding();
         if (ractive.fetchCallbacks!=null) ractive.fetchCallbacks.fire( data );
       }
    });
  },
  getServer: function() {
    return ractive.get('server')==undefined ? '' : ractive.get('server');
  },
  hash: function(email) {
    if (email==undefined) return;
    return hex_md5(email.trim().toLowerCase());
  },
  hideMessage: function() {
    $('#messages, .messages').hide();
  },
  initAutoComplete: function() {
    console.log('initAutoComplete');
    if (ractive.get('tenant.typeaheadControls')!=undefined && ractive.get('tenant.typeaheadControls').length>0) {
      $.each(ractive.get('tenant.typeaheadControls'), function(i,d) {
        //console.log('binding ' +d.url+' to typeahead control: '+d.selector);<commit_msg>enable jump to category through #name in URL<commit_after>var EASING_DURATION = 500;

jQuery(document).ready(function() {
  console.log('ready event handler');
  if (ractive.tenantCallbacks==undefined) ractive.tenantCallbacks = $.Callbacks();
  ractive.tenantCallbacks.add(function() {
    ractive.initAutoComplete();
  });
  var params = getSearchParameters();
  for (idx in Object.keys(params)) {
    ractive.set(Object.keys(params)[idx], params[Object.keys(params)[idx]]);
  }
  if (ractive.get('questionnaireDef')!=undefined) ractive.fetch();
});

var ractive = new Ractive({
  el: 'containerSect',
  template: '#template',
  data: {
    q: function () {
      return ractive.toQuestionnaire(ractive.get('categories'));
    },
    easingDuration: 500, // millis
    fadeOutMessages: true,
    questionnaireDef: $('body').data('questionnaire'),
    server: $env.server,
    matchRole: function(role) {
      console.info('matchRole: '+role)
      if (window['$auth']==undefined) return false;
      if (role==undefined || $auth.getClaim('scopes').indexOf(role)>-1) {
        $('.'+role).show();
        return true;
      } else {
        return false;
      }
    },
    toId: function(name) {
      return name.toLowerCase().replace(/ /g,'_').replace('(','').replace(')','');
    },
    stdPartials: [
      { "name": "questionnaire", "url": "partials/questionnaire.html"},
      { "name": "questionnaireContact", "url": "partials/questionnaire-contact.html"},
      { "name": "sidebar", "url": $env.server+"/partials/sidebar.html"}
    ],
    toQName: function(i,j) {
      if (ractive==undefined) return;
      else return ractive.get('q.categories.'+i+'.questions.'+j+'.id');
    }
  },
  partials: {
    questionnaire: '',
    sidebar: ''
  },
  addDataList: function(d, data) {
    $('datalist#'+d.name).remove();
    $('body').append('<datalist id="'+d.name+'">');
    $.each(data, function (i,e) {
      $('datalist#'+d.name).append('<option value="'+e.name+'">'+e.name+'</option>');
    });
  },
  addSelectOptions: function(selector, data, value) {
    console.info('add selection options to '+selector+' selecting '+value);
    $(selector+' option').remove();
    $.each(data, function (i,e) {
      $(selector).append('<option '+(e.name==value ? 'selected ' : '')
          +'value="'+e.name+'">'+e.name+'</option>');
    });
  },
  applyBranding: function() {
    if (ractive.get('q.about.branding.favicon')!=undefined) {
      $('head').append('<link rel="icon" type="image/png" href="'+ractive.get('q.about.branding.favicon')+'">');
    }
    if (ractive.get('q.about.branding.link')!=undefined) {
      $('.navbar-brand').attr('href', ractive.get('q.about.branding.link'));
    }
    if (ractive.get('q.about.branding.logo')!=undefined) {
      $('.navbar-brand').empty().append('<img alt="logo" height="45px" src="'+ractive.get('q.about.branding.logo')+'"/>');
    }
  },
  fetch: function() {
    console.info('fetch');
    var url = ractive.get('questionnaireDef');
    if (!url.startsWith('http')) url = 'js/'+ractive.get('questionnaireDef')+'.json';
    $.ajax({
       type: 'GET',
       url: url,
       dataType: 'json',
       success: function(data, textStatus, jqxhr) {
         console.log('success:'+data);
         for (var i = 0 ; i < data.categories.length ; i++) {
           for (var j = 0 ; j < data.categories[i].length ; j++) {
             data.categories[i][j].optionValues = [];
           }
         }

         if (ractive.getBookmark()!=undefined) {
           var cat = data['categories'].find(function(obj) { return obj.name == this; }, ractive.getBookmark());
           data['activeCategory'] = data['categories'].indexOf(cat);
         }

         // sane defaults
         if (data['activeCategory']==undefined) data.activeCategory = 0;
         if (data['about']==undefined) data.about = { };
         if (data.about['branding']!=undefined) $('nav.navbar').show();
         if (data.about['title']==undefined) data.about.title = 'Questionnaire';
         if (data.about['options']==undefined) data.about.options = { };
         if (data.about.options['categoryAtATime']==undefined) data.about.options.categoryAtATime = true;
         if (data['submit']==undefined) data.submit = { };
         if (data.submit['buttonText']==undefined) data.submit.buttonText = 'Submit Now';
         if (data.submit['successPage']==undefined) data.submit.successPage = 'thanks.html';
         if (data.submit['title']==undefined) data.submit.title = "That's it!";
         if (data.submit['text']==undefined) data.submit.text = 'Thanks for your time.';

         ractive.set('q', data);
         ractive.applyBranding();
         if (ractive.fetchCallbacks!=null) ractive.fetchCallbacks.fire( data );
       }
    });
  },
  getBookmark: function() {
    var end = document.location.hash.indexOf('?') ==-1
		  ? document.location.hash.length : document.location.hash.indexOf('?')
    var bmark = decodeURIComponent(document.location.hash.substring(1, end));
    return bmark.length > 0 ? bmark : undefined;
  },
  getServer: function() {
    return ractive.get('server')==undefined ? '' : ractive.get('server');
  },
  hash: function(email) {
    if (email==undefined) return;
    return hex_md5(email.trim().toLowerCase());
  },
  hideMessage: function() {
    $('#messages, .messages').hide();
  },
  initAutoComplete: function() {
    console.log('initAutoComplete');
    if (ractive.get('tenant.typeaheadControls')!=undefined && ractive.get('tenant.typeaheadControls').length>0) {
      $.each(ractive.get('tenant.typeaheadControls'), function(i,d) {
        //console.log('binding ' +d.url+' to typeahead control: '+d.selector);
{'fraction_non_alphanumeric': 0.20502829576027462, 'fraction_numerical': 0.002875962519714259, 'mean_word_length': 3.40359477124183, 'pattern_counts': {'":': 12, '<': 21, '<?xml version=': 0, '>': 22, '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': '2610777', 'n_tokens_mistral': 3484, 'n_tokens_neox': 3414, 'n_words': 560}