<commit_before>/*
 * Copyright [1999-2014] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

(function($) {

  function obj_empty(x) {
    for(var k in x) {
      if(x.hasOwnProperty(k)) { return false; }
    }
    return true;
  }

  $.fn.new_table_filter = function(config,data,widgets) {

    var filterable_columns = {};

    function find_widget(wanted_name,type,def) {
      var w;
      $.each(widgets,function(name,contents) {
        if(contents[type]) {
          for(var i=0;i<contents[type].length;i++) {
            if(contents[type][i].name == wanted_name) {
              w = contents[type][i];
            }
          }
        }
      });
      if(w) { return w; }
      if(def!==null) { return find_widget(def,type,null); }
      return null;
    }

    function dropdown(idx,filter,label,primary) {
      var prec = primary?"pri":"sec";
      if(filter=='') { filter = 'more'; }
      return '<li class="t prec_'+prec+'" data-idx="'+idx+'"><span class="k">'+label+'</span><span class="v">All</span><div class="m newtable_filtertype_'+filter+'" data-filter="'+filter+'">'+label+'</div></li>';
    }

    function activate_menu($table,$button,others_only) {
      var $el = $button.find('.m');
      $('.newtable_filter li .m:visible').each(function() {
        if($el.length && $el[0] == this) { return; }
        hide_menu($(this));
      });
      if($button.length && !others_only) {
        if(!$el.is(":visible")) {
          menu($table,$button,$el);
          show_menu($el);
        } else {
          hide_menu($el);
        }
      }
    }

    function draw_more($table,$menu) {
      var $out = $("<ul/>");
      $('.newtable_filter .prec_sec.valid',$table).each(function() {
        var $item = $(this);
        var $li = $("<li/>").text($('.k',$item).text()).appendTo($out);
        $li.on('click',function(e) {
          $item.removeClass('prec_sec').addClass('prec_pri');
          activate_menu($table,$item,false);<commit_msg>ENSWEB-1711(5): hide more when no more.<commit_after>/*
 * Copyright [1999-2014] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

(function($) {

  function obj_empty(x) {
    for(var k in x) {
      if(x.hasOwnProperty(k)) { return false; }
    }
    return true;
  }

  $.fn.new_table_filter = function(config,data,widgets) {

    var filterable_columns = {};

    function find_widget(wanted_name,type,def) {
      var w;
      $.each(widgets,function(name,contents) {
        if(contents[type]) {
          for(var i=0;i<contents[type].length;i++) {
            if(contents[type][i].name == wanted_name) {
              w = contents[type][i];
            }
          }
        }
      });
      if(w) { return w; }
      if(def!==null) { return find_widget(def,type,null); }
      return null;
    }

    function dropdown(idx,filter,label,primary) {
      var prec = primary?"pri":"sec";
      if(filter=='') { filter = 'more'; }
      return '<li class="t prec_'+prec+'" data-idx="'+idx+'"><span class="k">'+label+'</span><span class="v">All</span><div class="m newtable_filtertype_'+filter+'" data-filter="'+filter+'">'+label+'</div></li>';
    }

    function activate_menu($table,$button,others_only) {
      var $el = $button.find('.m');
      $('.newtable_filter li .m:visible').each(function() {
        if($el.length && $el[0] == this) { return; }
        hide_menu($(this));
      });
      if($button.length && !others_only) {
        if(!$el.is(":visible")) {
          menu($table,$button,$el);
          show_menu($el);
        } else {
          hide_menu($el);
        }
      }
    }

    function draw_more($table,$menu) {
      var $out = $("<ul/>");
      $('.newtable_filter .prec_sec.valid',$table).each(function() {
        var $item = $(this);
        var $li = $("<li/>").text($('.k',$item).text()).appendTo($out);
        $li.on('click',function(e) {
          $item.removeClass('prec_sec').addClass('prec_pri');
          activate_menu($table,$item,false);
          if(!$('.newtable_filter .prec_sec.valid',$table).length) {
            $out.closest('.more').hide();
          }
{'fraction_non_alphanumeric': 0.17207977207977207, 'fraction_numerical': 0.0062678062678062675, 'mean_word_length': 2.7994227994227994, 'pattern_counts': {'":': 4, '<': 25, '<?xml version=': 0, '>': 23, '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': '2393627', 'n_tokens_mistral': 1664, 'n_tokens_neox': 1615, 'n_words': 367}