<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.
 */

Ensembl.Panel.CloudMultiSelector = Ensembl.Panel.extend({
  constructor: function (id, params) {
    this.base(id);
    this.urlParam = params.urlParam;
    this.params = params;

    this.selection = [];
    Ensembl.EventManager.register('updateConfiguration', this, this.updateSelection);
  },
 
  set_selection: function () {
    var panel = this;

    panel.selection = $.makeArray(
      $('.cloud_multi_selector_list li:not(.off)',panel.elLk.content).map(
        function(i,val) {
          return $(val).data('key');
        }
      )
    );
  }, 
 
  init: function () {
    var panel = this;
    
    this.base();
    this.elLk.content = $('.modal_wrapper', this.el);
    this.elLk.list = $('.cloud_multi_selector_list li', this.elLk.content);
    this.elLk.filter = $('.cloud_filter input',this.el);
    this.elLk.clear = $('.cloud_filter_clear',this.el);
    this.elLk.all = $('.all',this.el);
    this.elLk.none = $('.none',this.el);
    panel.changed = 0;
    $(panel.el).on('filter',function(e,val) {
      panel.elLk.list.each(function() {
        var $li = $(this);
        if($li.text().toLowerCase().indexOf(val.toLowerCase()) == 0) {
          $li.removeClass('hidden');
        } else {
          $li.addClass('hidden');
        }
      });
      if(val) { panel.elLk.clear.show(); } else { panel.elLk.clear.hide(); }
      panel.elLk.filter.focus();
    });
    this.elLk.list.click(function() {
      $(this).toggleClass('off');
      panel.set_selection();
      panel.elLk.filter.focus();
      panel.changed = 1;
      return false;
    });
    this.elLk.all.click(function() {
      panel.elLk.list.removeClass('off');
      panel.set_selection();
      panel.changed = 1;
      return false;
    });
    this.elLk.none.click(function() {
      panel.elLk.list.addClass('off');
      panel.set_selection();
      panel.changed = 1;
      return false;
    });
    this.set_selection();
    this.val = '';
    panel.elLk.filter.val('');
    panel.elLk.clear.hide();
    this.elLk.filter.on({
      'keydown paste keyup mouseup blur': function(e) {
        var new_val = panel.elLk.filter.val();
        if(panel.val != new_val) {
          $(panel.el).trigger('filter',[new_val]);
          panel.val = new_val;
        }
      }
    }).focus();
    $(this.el).click(function() { panel.elLk.filter.focus(); });
    panel.elLk.clear.click(function() {
      panel.val = '';
      panel.elLk.filter.val('');
      $(panel.el).trigger('filter',['']);
    });
  }
});
<commit_msg>Better cloud "changed" detect to prevent oddities.<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.
 */

Ensembl.Panel.CloudMultiSelector = Ensembl.Panel.extend({
  constructor: function (id, params) {
    this.base(id);
    this.urlParam = params.urlParam;
    this.params = params;

    this.selection = [];
    Ensembl.EventManager.register('updateConfiguration', this, this.updateSelection);
  },
 
  set_selection: function () {
    var panel = this;

    panel.selection = $.makeArray(
      $('.cloud_multi_selector_list li:not(.off)',panel.elLk.content).map(
        function(i,val) {
          return $(val).data('key');
        }
      )
    );

    if(panel.orig_selection) {
      if(panel.orig_selection.length == panel.selection.length) {
        panel.changed = false;
        $.each(panel.selection,function(i,v) {
          if(v != panel.orig_selection[i]) {
            panel.changed = true;
          }
        });
      } else {
        panel.changed = true;
      }
    } else {
      panel.orig_selection = panel.selection;
      panel.changed = false;
    }
  },
 
  init: function () {
    var panel = this;
    
    this.base();
    this.elLk.content = $('.modal_wrapper', this.el);
    this.elLk.list = $('.cloud_multi_selector_list li', this.elLk.content);
    this.elLk.filter = $('.cloud_filter input',this.el);
    this.elLk.clear = $('.cloud_filter_clear',this.el);
    this.elLk.all = $('.all',this.el);
    this.elLk.none = $('.none',this.el);

    panel.set_selection();
    $(panel.el).on('filter',function(e,val) {
      panel.elLk.list.each(function() {
        var $li = $(this);
        if($li.text().toLowerCase().indexOf(val.toLowerCase()) == 0) {
          $li.removeClass('hidden');
        } else {
          $li.addClass('hidden');
        }
      });
      if(val) { panel.elLk.clear.show(); } else { panel.elLk.clear.hide(); }
      panel.elLk.filter.focus();
    });
    this.elLk.list.click(function() {
      $(this).toggleClass('off');
      panel.set_selection();
      panel.elLk.filter.focus();
      return false;
    });
    this.elLk.all.click(function() {
      panel.elLk.list.removeClass('off');
      panel.set_selection();
      return false;
    });
    this.elLk.none.click(function() {
      panel.elLk.list.addClass('off');
      panel.set_selection();
      return false;
    });
    this.set_selection();
    this.val = '';
    panel.elLk.filter.val('');
    panel.elLk.clear.hide();
    this.elLk.filter.on({
      'keydown paste keyup mouseup blur': function(e) {
        var new_val = panel.elLk.filter.val();
        if(panel.val != new_val) {
          $(panel.el).trigger('filter',[new_val]);
          panel.val = new_val;
        }
      }
    }).focus();
    $(this.el).click(function() { panel.elLk.filter.focus(); });
    panel.elLk.clear.click(function() {
      panel.val = '';
      panel.elLk.filter.val('');
      $(panel.el).trigger('filter',['']);
    });
  }
});

{'fraction_non_alphanumeric': 0.16282846176557425, 'fraction_numerical': 0.0044286979627989375, 'mean_word_length': 2.5998937300743887, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3858603', 'n_tokens_mistral': 2193, 'n_tokens_neox': 2141, 'n_words': 425}