<commit_before>//this depends on formatXml.js and parseQuerystring.js
//TODO formalize this dependency

//based on the jquery plugin lightweight boilerplate
//http://www.smashingmagazine.com/2011/10/11/essential-jquery-plugin-patterns-2/

;(function ( $, window, document, undefined ) {
  var form_field_template = '<tr><td>{{>name}}</td><td><input type="text" class="{{>input_class}}" name="{{>name}}" {{if required}} placeholder="required" {{/if}}/></td><td>{{>requirements}}</td><td>{{>description}}</td></tr>';
  var cancel_button = '<button class="btn btn-danger cancel" id="cancel-{{>identifier}}">Cancel</button>';
  var tryit_button = '<button class="btn btn-success tryit" id="tryit-{{>identifier}}">Try It</button>';
  var settings_button = '<button class="btn btn-default settings" id="settings-{{>identifier}}">Settings</button>';

  $.templates({
    form_field_template: form_field_template,
    cancel_button: cancel_button,
    tryit_button: tryit_button,
    settings_button: settings_button
  });

  var pluginName = 'livedocs',
    defaults = {};

  //there are currently no options but some things probably should be
  //so leaving the scaffolding up
  function Livedocs( element, options ) {
    this.element = element;

    this.options = $.extend( {}, defaults, options) ;

    this._defaults = defaults;
    this._name = pluginName;

    this.init();
  };

  Livedocs.prototype = {
    init: function () {
      livedoc = $(this.element);
      var form = livedoc.find('form');
      var form_table = livedoc.find('form>table');

      var id = livedoc.attr('id');
      var identifier = id.substr(id.indexOf('-') + 1, id.length);

      Livedocs.addButtons(identifier, livedoc);
      form_table.append(Livedocs.getFormFieldHtml(identifier));
      form.append('<div class="text-center"><button type="input" class="btn btn-primary">Make Request</button></div>');

      //TODO these event listeners shouldn't be wired up for all elements each time we instantiate the plugin
      $('#credentials').submit(function (e) {
        e.preventDefault();
        username = $('#username').val();
        password = $('#password').val();
        responseFormat = $('#response-format').val();

        $.cookie('username', username);
        $.cookie('password', password);
        $.cookie('responseFormat', responseFormat);

        $('#credentialsModal').modal('hide');
      });

      $('.tryit').click(function () {
        Livedocs.getCredentials();
        var id = $(this).attr('id');
        var identifier = id.substr(id.indexOf('-') + 1, id.length);
        Livedocs.toggleLivedoc(identifier, true);
      })
      
      $('.cancel').click(function () {
        var id = $(this).attr('id');
        var identifier = id.substr(id.indexOf('-') + 1, id.length);
        Livedocs.toggleLivedoc(identifier, false);
      });
<commit_msg>change cookies to secure<commit_after>//this depends on formatXml.js and parseQuerystring.js
//TODO formalize this dependency

//based on the jquery plugin lightweight boilerplate
//http://www.smashingmagazine.com/2011/10/11/essential-jquery-plugin-patterns-2/

;(function ( $, window, document, undefined ) {
  var form_field_template = '<tr><td>{{>name}}</td><td><input type="text" class="{{>input_class}}" name="{{>name}}" {{if required}} placeholder="required" {{/if}}/></td><td>{{>requirements}}</td><td>{{>description}}</td></tr>';
  var cancel_button = '<button class="btn btn-danger cancel" id="cancel-{{>identifier}}">Cancel</button>';
  var tryit_button = '<button class="btn btn-success tryit" id="tryit-{{>identifier}}">Try It</button>';
  var settings_button = '<button class="btn btn-default settings" id="settings-{{>identifier}}">Settings</button>';

  $.templates({
    form_field_template: form_field_template,
    cancel_button: cancel_button,
    tryit_button: tryit_button,
    settings_button: settings_button
  });

  var pluginName = 'livedocs',
    defaults = {};

  //there are currently no options but some things probably should be
  //so leaving the scaffolding up
  function Livedocs( element, options ) {
    this.element = element;

    this.options = $.extend( {}, defaults, options) ;

    this._defaults = defaults;
    this._name = pluginName;

    this.init();
  };

  Livedocs.prototype = {
    init: function () {
      livedoc = $(this.element);
      var form = livedoc.find('form');
      var form_table = livedoc.find('form>table');

      var id = livedoc.attr('id');
      var identifier = id.substr(id.indexOf('-') + 1, id.length);

      Livedocs.addButtons(identifier, livedoc);
      form_table.append(Livedocs.getFormFieldHtml(identifier));
      form.append('<div class="text-center"><button type="input" class="btn btn-primary">Make Request</button></div>');

      //TODO these event listeners shouldn't be wired up for all elements each time we instantiate the plugin
      $('#credentials').submit(function (e) {
        e.preventDefault();
        username = $('#username').val();
        password = <PASSWORD>();
        responseFormat = $('#response-format').val();

        $.cookie('username', username, { secure:true });
        $.cookie('password', password, { secure:true });
        $.cookie('responseFormat', responseFormat, { secure:true });

        $('#credentialsModal').modal('hide');
      });

      $('.tryit').click(function () {
        Livedocs.getCredentials();
        var id = $(this).attr('id');
        var identifier = id.substr(id.indexOf('-') + 1, id.length);
        Livedocs.toggleLivedoc(identifier, true);
      })
      
      $('.cancel').click(function () {
        var id = $(this).attr('id');
        var identifier = id.substr(id.indexOf('-') + 1, id.length);
        Livedocs.toggleLivedoc(identifier, false);
      });

{'fraction_non_alphanumeric': 0.17572714681440443, 'fraction_numerical': 0.004155124653739612, 'mean_word_length': 3.570411392405063, 'pattern_counts': {'":': 0, '<': 46, '<?xml version=': 0, '>': 64, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5201935', 'n_tokens_mistral': 1738, 'n_tokens_neox': 1649, 'n_words': 370}