<commit_before>// SCB - Firebelly 2015
// jshint ignore: start

// Good Design for Good Reason for Good Namespace
var SCB = (function($) {

  var screen_width = 0,
      breakpoint_small = false,
      breakpoint_medium = false,
      breakpoint_large = false,
      breakpoint_array = [480,1000,1200],
      $document,
      $sidebar,
      $collection,
      loadingTimer,
      page_at;

  function _init() {
    // touch-friendly fast clicks
    FastClick.attach(document.body);

    // Cache some common DOM queries
    $document = $(document);
    $collection = $('.collection.mini');
    $('body').addClass('loaded');

    // Set screen size vars
    _resize();

    // Fit them vids!
    $('main').fitVids();

    // Homepage (pre _initMasonry)
    if ($('.home.page').length) {
      page_at = 'homepage';
      $('.project-categories').on('click', 'a', function(e) {
        e.preventDefault();
        var $li = $(this).parent('li');
        // match height of absolutely-positing children lists
        var childHeight = $li.find('ul.children:first').outerHeight();
        $('.project-categories').outerHeight(childHeight);
        $li.find('ul.children:first').addClass('active');
        if (!$li.hasClass('active')) {
          $li.addClass('active');
        } else {
          $li.removeClass('active');
          $li.find('ul.children').removeClass('active');
        }
        // Activate/deactivate the parent ul
        var $parentUl = $li.parent('ul');
        if (!$parentUl.hasClass('children')) {
          if (!$parentUl.is('.active')) {
            $li.parent('ul').addClass('active');
          } else if ($parentUl.hasClass('active') && !$li.siblings('.active').length) {
            $parentUl.removeClass('active');
          }
        }

        var project_categories = [];
        $('.project-categories li.active>a').each(function() {
          project_categories.push($(this).text());
        });
        $.ajax({
            url: wp_ajax_url,
            method: 'post',
            data: {
                action: 'load_more_posts',
                post_type: 'project',
                page: 1,
                per_page: 6,
                project_category: project_categories.join(',')
            },
            success: function(data) {
              var $data = $(data);
              if (loadingTimer) { clearTimeout(loadingTimer); }
              $('section.projects').html($data).removeClass('loading');
            }
        });

      });
    }

    // Show/hide mini collection in nav
    $(document).on('click', '.show-collection', function(e) {
      e.preventDefault();
      if ($collection.hasClass('active')) {
        _hideCollection();
      } else {
        _showCollection();
      }
    });

    // Add/Remove from collection links
    $(document).on('click', '.collection-action', function(e) {
      e.preventDefault();
      var $link = $(this);
      var id = $link.data('id');
      var action = $link.data('action');
      $.ajax({
        url: wp_ajax_url,
        method: 'post',
        dataType: 'json',
        data: {
          action: 'collection_action',
          do: action,
          post_id: id
        }
      }).done(function(response) {
        _updatePostCollectionLinks(id,action);
        // repopulate all collections
        $('section.collection').html(response.data.collection_html);
        _initCollectionSorting();
        _showCollection();
      });
    });

    // Esc handlers
    $(document).keyup(function(e) {
      if (e.keyCode === 27) {
        _hideSearch();
        _hideCollection();<commit_msg>send collection_id to backend, on reinit on add/remove actions<commit_after>// SCB - Firebelly 2015
// jshint ignore: start

// Good Design for Good Reason for Good Namespace
var SCB = (function($) {

  var screen_width = 0,
      breakpoint_small = false,
      breakpoint_medium = false,
      breakpoint_large = false,
      breakpoint_array = [480,1000,1200],
      $document,
      $sidebar,
      $collection,
      loadingTimer,
      page_at;

  function _init() {
    // touch-friendly fast clicks
    FastClick.attach(document.body);

    // Cache some common DOM queries
    $document = $(document);
    $collection = $('.collection.mini');
    $('body').addClass('loaded');

    // Set screen size vars
    _resize();

    // Fit them vids!
    $('main').fitVids();

    // Homepage (pre _initMasonry)
    if ($('.home.page').length) {
      page_at = 'homepage';
      $('.project-categories').on('click', 'a', function(e) {
        e.preventDefault();
        var $li = $(this).parent('li');
        // match height of absolutely-positing children lists
        var childHeight = $li.find('ul.children:first').outerHeight();
        $('.project-categories').outerHeight(childHeight);
        $li.find('ul.children:first').addClass('active');
        if (!$li.hasClass('active')) {
          $li.addClass('active');
        } else {
          $li.removeClass('active');
          $li.find('ul.children').removeClass('active');
        }
        // Activate/deactivate the parent ul
        var $parentUl = $li.parent('ul');
        if (!$parentUl.hasClass('children')) {
          if (!$parentUl.is('.active')) {
            $li.parent('ul').addClass('active');
          } else if ($parentUl.hasClass('active') && !$li.siblings('.active').length) {
            $parentUl.removeClass('active');
          }
        }

        var project_categories = [];
        $('.project-categories li.active>a').each(function() {
          project_categories.push($(this).text());
        });
        $.ajax({
            url: wp_ajax_url,
            method: 'post',
            data: {
                action: 'load_more_posts',
                post_type: 'project',
                page: 1,
                per_page: 6,
                project_category: project_categories.join(',')
            },
            success: function(data) {
              var $data = $(data);
              if (loadingTimer) { clearTimeout(loadingTimer); }
              $('section.projects').html($data).removeClass('loading');
            }
        });

      });
    }

    // Show/hide mini collection in nav
    $(document).on('click', '.show-collection', function(e) {
      e.preventDefault();
      if ($collection.hasClass('active')) {
        _hideCollection();
      } else {
        _showCollection();
      }
    });

    // Add/Remove from collection links
    $(document).on('click', '.collection-action', function(e) {
      e.preventDefault();
      var $link = $(this);
      var id = $link.data('id');
      var collection_id = $link.parents('section.collection:first').data('id');
      var action = $link.data('action');
      $.ajax({
        url: wp_ajax_url,
        method: 'post',
        dataType: 'json',
        data: {
          action: 'collection_action',
          do: action,
          post_id: id,
          collection_id: collection_id
        }
      }).done(function(response) {
        // if add/remove, repopulate collection & reinit behavior
        if (action.match(/add|remove/)) {
          _updatePostCollectionLinks(id,action);
          // repopulate all collections
          $('section.collection').html(response.data.collection_html);
          _initCollectionSorting();
          _showCollection();
        }
      });
    });

    // Esc handlers
    $(document).keyup(function(e) {
      if (e.keyCode === 27) {
        _hideSearch();
        _hideCollection();
{'fraction_non_alphanumeric': 0.1598398932621748, 'fraction_numerical': 0.00533689126084056, 'mean_word_length': 2.0335896398219346, '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': '1071997', 'n_tokens_mistral': 2166, 'n_tokens_neox': 2097, 'n_words': 416}