<commit_before>define([
  'App',
  // Templates
  'text!tpl/item.html',
  'text!tpl/class.html',
  'text!tpl/itemEnd.html',
  // Tools
  'prettify'
], function (App, itemTpl, classTpl, endTpl) {

  'use strict';

  var itemView = Backbone.View.extend({
    el: '#item',
    init: function () {
      this.$html = $('html');
      this.$body = $('body');
      this.$scrollBody = $('html, body'); // hack for Chrome/Firefox scroll

      this.tpl = _.template(itemTpl);
      this.classTpl = _.template(classTpl);
      this.endTpl = _.template(endTpl);

      return this;
    },
    getSyntax: function(isMethod, cleanItem) {
      var isConstructor = cleanItem.is_constructor;
      var syntax = '';
      if (isConstructor) syntax += 'new ';
      syntax += cleanItem.name;

      if (isMethod || isConstructor) {
        syntax += '(';
        if (cleanItem.params) {
          for (var i=0; i<cleanItem.params.length; i++) {
            var p = cleanItem.params[i];
            if (p.optional) syntax += '[';
            syntax += p.name;
            if (p.optdefault) syntax += '='+p.optdefault;
            if (p.optional) syntax += ']';
            if (i !== cleanItem.params.length-1) {
              syntax += ',';
            }
          }
        }
        syntax += ')';
      }

      return syntax;
    },
    // Return a list of valid syntaxes across all overloaded versions of
    // this item.
    //
    // For reference, we ultimately want to replicate something like this:
    //
    // https://processing.org/reference/color_.html
    getSyntaxes: function(isMethod, cleanItem) {
      var overloads = cleanItem.overloads || [cleanItem];
      return overloads.map(this.getSyntax.bind(this, isMethod));
    },
    render: function (item) {
      if (item) {
        var itemHtml = '',
            cleanItem = this.clean(item),
            isClass = item.hasOwnProperty('itemtype') ? 0 : 1,
            collectionName = isClass ? 'Constructor' : this.capitalizeFirst(cleanItem.itemtype),
            isConstructor = cleanItem.is_constructor;
        cleanItem.isMethod = collectionName === 'Method';

        var syntaxes = this.getSyntaxes(cleanItem.isMethod, cleanItem);

        // Set the item header (title)

        // Set item contents
        if (isClass) {
          if (isConstructor) {
            var constructor = this.tpl({
              item: cleanItem,
              syntaxes: syntaxes
            });
            cleanItem.constructor = constructor;
          }

          var contents = _.find(App.classes, function(c){ return c.name === cleanItem.name; });
          cleanItem.things = contents.items;

          itemHtml = this.classTpl(cleanItem);

        } else {
          itemHtml = this.tpl({
            item: cleanItem,
            syntaxes: syntaxes
          });
        }

        itemHtml += this.endTpl({item:cleanItem});

        // Insert the view in the dom
        this.$el.html(itemHtml);

        renderCode();

        // Hook up alt-text for examples
        setTimeout(function() {
          var alts = $('.example-content')[0];
          if (alts) {
            alts = $(alts).data('alt').split('\n');

            var examples = $('.example_container canvas');
            for (var i=0; i<alts.length; i++) {
              if (i < examples.length) {
                $(examples[i]).attr('alt', alts[i]);
              }
            }
          }
        }, 1000);
        Prism.highlightAll();
      }

      return this;
    },
    /**
     * Clean item properties: url encode properties containing paths.
     * @param {object} item The item object.
     * @returns {object} Returns the same item object with urlencoded paths.
     */
    clean: function (item) {
      var cleanItem = item;<commit_msg>fix for accessibility ref ex alt text<commit_after>define([
  'App',
  // Templates
  'text!tpl/item.html',
  'text!tpl/class.html',
  'text!tpl/itemEnd.html',
  // Tools
  'prettify'
], function (App, itemTpl, classTpl, endTpl) {

  'use strict';

  var itemView = Backbone.View.extend({
    el: '#item',
    init: function () {
      this.$html = $('html');
      this.$body = $('body');
      this.$scrollBody = $('html, body'); // hack for Chrome/Firefox scroll

      this.tpl = _.template(itemTpl);
      this.classTpl = _.template(classTpl);
      this.endTpl = _.template(endTpl);

      return this;
    },
    getSyntax: function(isMethod, cleanItem) {
      var isConstructor = cleanItem.is_constructor;
      var syntax = '';
      if (isConstructor) syntax += 'new ';
      syntax += cleanItem.name;

      if (isMethod || isConstructor) {
        syntax += '(';
        if (cleanItem.params) {
          for (var i=0; i<cleanItem.params.length; i++) {
            var p = cleanItem.params[i];
            if (p.optional) syntax += '[';
            syntax += p.name;
            if (p.optdefault) syntax += '='+p.optdefault;
            if (p.optional) syntax += ']';
            if (i !== cleanItem.params.length-1) {
              syntax += ',';
            }
          }
        }
        syntax += ')';
      }

      return syntax;
    },
    // Return a list of valid syntaxes across all overloaded versions of
    // this item.
    //
    // For reference, we ultimately want to replicate something like this:
    //
    // https://processing.org/reference/color_.html
    getSyntaxes: function(isMethod, cleanItem) {
      var overloads = cleanItem.overloads || [cleanItem];
      return overloads.map(this.getSyntax.bind(this, isMethod));
    },
    render: function (item) {
      if (item) {
        var itemHtml = '',
            cleanItem = this.clean(item),
            isClass = item.hasOwnProperty('itemtype') ? 0 : 1,
            collectionName = isClass ? 'Constructor' : this.capitalizeFirst(cleanItem.itemtype),
            isConstructor = cleanItem.is_constructor;
        cleanItem.isMethod = collectionName === 'Method';

        var syntaxes = this.getSyntaxes(cleanItem.isMethod, cleanItem);

        // Set the item header (title)

        // Set item contents
        if (isClass) {
          if (isConstructor) {
            var constructor = this.tpl({
              item: cleanItem,
              syntaxes: syntaxes
            });
            cleanItem.constructor = constructor;
          }

          var contents = _.find(App.classes, function(c){ return c.name === cleanItem.name; });
          cleanItem.things = contents.items;

          itemHtml = this.classTpl(cleanItem);

        } else {
          itemHtml = this.tpl({
            item: cleanItem,
            syntaxes: syntaxes
          });
        }

        itemHtml += this.endTpl({item:cleanItem});

        // Insert the view in the dom
        this.$el.html(itemHtml);

        renderCode();

        // Hook up alt-text for examples
        setTimeout(function() {
          var alts = $('.example-content')[0];
          if (alts) {
            alts = $(alts).data('alt').split('\n');

            var examples = $('.cnv_div');
            for (var i=0; i<alts.length; i++) {
              if (i < examples.length) {
                $(examples[i]).append('<span class="ref_ex_fallback">'+alts[i]+'</span>');
              }
            }
          }
        }, 1000);
        Prism.highlightAll();
      }

      return this;
    },
    /**
     * Clean item properties: url encode properties containing paths.
     * @param {object} item The item object.
     * @returns {object} Returns the same item object with urlencoded paths.
     */
    clean: function (item) {
      var cleanItem = item;
{'fraction_non_alphanumeric': 0.1385994988790716, 'fraction_numerical': 0.002637478570486615, 'mean_word_length': 1.8522000752162466, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '1210303', 'n_tokens_mistral': 2226, 'n_tokens_neox': 2175, 'n_words': 520}