<commit_before>/*
 * Copyright [1999-2015] 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.
 */

// FIXME: history isn't working properly when zooming in/out with slider - genoverse.length changes and everything is reset
// FIXME: occasional off-by-one error due to Math.round in getLocation - breaks history (and anything else that requires an x.start === y.start type comparison)
// TODO:  hide highlightRegion when new images are being made, and in other scenarios where it looks bad

Ensembl.Genoverse = Genoverse.extend({
  init: function () {
    this.base();
    this.highlightRegion = $('<div class="selector highlight">').appendTo(this.wrapper);
    
    Ensembl.EventManager.register('genoverseMove', this, this.moveTo);
    
    // Ensure that the popState function from Genoverse fires before the one from Ensembl, so that nothing happens when hashChange is triggered from using browser forward/back buttons
    $(window).off('hashchange.ensembl popstate.ensembl').on('hashchange.ensembl popstate.ensembl', $.proxy(Ensembl.LayoutManager.popState, Ensembl.LayoutManager));
    this.container.off('dblclick');
  },

  moveTo: function() {
    this.base.apply(this,arguments);
    this.updateEnsembl(true);
  },
  
  updateEnsembl: function (allow_move) {
    Ensembl.images[this.panel.imageNumber][0][2] = this.start;
    Ensembl.images[this.panel.imageNumber][0][3] = this.end;
    
    if (this.dragging || allow_move) {
      var location = this.getLocation(this.start, this.end,Ensembl.location.length,!allow_move);
      var text     = Ensembl.thousandify(location.start) + '-' + Ensembl.thousandify(location.end); 
      
      (this.updateEnsemblText = this.updateEnsemblText || $('h1.summary-heading, #masthead .location.long_tab a')).html(function (i, html) {
        return html.replace(/^(.+:\s?).+/, '$1' + text);
      });
      Ensembl.images[this.panel.imageNumber+1][0][2] = location.start;
      Ensembl.images[this.panel.imageNumber+1][0][3] = location.end;
    }

    Ensembl.EventManager.trigger('highlightAllImages');
  },
  
  updateURL: function (location) {
    location = location || (this.prev.scale === this.scale ? this.getLocation(this.start, this.end, Ensembl.location.length,1) : this);
    
    if (Ensembl.location.start === location.start && Ensembl.location.end === location.end) {
      return;
    }
    
    this.updatingURL = true;
    
    Ensembl.updateLocation(this.urlParamTemplate
      .replace('r=',        '')
      .replace('__CHR__',   this.chr)
      .replace('__START__', location.start)
      .replace('__END__',   location.end)
    );
  },
  
  popState: function () {
    this.updatingURL     = true;
    Ensembl.historyReady = true;
    this.base();
  },<commit_msg>Only update coords if the image exists<commit_after>/*
 * Copyright [1999-2015] 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.
 */

// FIXME: history isn't working properly when zooming in/out with slider - genoverse.length changes and everything is reset
// FIXME: occasional off-by-one error due to Math.round in getLocation - breaks history (and anything else that requires an x.start === y.start type comparison)
// TODO:  hide highlightRegion when new images are being made, and in other scenarios where it looks bad

Ensembl.Genoverse = Genoverse.extend({
  init: function () {
    this.base();
    this.highlightRegion = $('<div class="selector highlight">').appendTo(this.wrapper);
    
    Ensembl.EventManager.register('genoverseMove', this, this.moveTo);
    
    // Ensure that the popState function from Genoverse fires before the one from Ensembl, so that nothing happens when hashChange is triggered from using browser forward/back buttons
    $(window).off('hashchange.ensembl popstate.ensembl').on('hashchange.ensembl popstate.ensembl', $.proxy(Ensembl.LayoutManager.popState, Ensembl.LayoutManager));
    this.container.off('dblclick');
  },

  moveTo: function() {
    this.base.apply(this,arguments);
    this.updateEnsembl(true);
  },
  
  updateEnsembl: function (allow_move) {
    Ensembl.images[this.panel.imageNumber][0][2] = this.start;
    Ensembl.images[this.panel.imageNumber][0][3] = this.end;
    
    if (this.dragging || allow_move) {
      var location = this.getLocation(this.start, this.end,Ensembl.location.length,!allow_move);
      var text     = Ensembl.thousandify(location.start) + '-' + Ensembl.thousandify(location.end); 
      
      (this.updateEnsemblText = this.updateEnsemblText || $('h1.summary-heading, #masthead .location.long_tab a')).html(function (i, html) {
        return html.replace(/^(.+:\s?).+/, '$1' + text);
      });
      if (Ensembl.images[this.panel.imageNumber+1]) {
        Ensembl.images[this.panel.imageNumber+1][0][2] = location.start;
        Ensembl.images[this.panel.imageNumber+1][0][3] = location.end;
      }
    }

    Ensembl.EventManager.trigger('highlightAllImages');
  },
  
  updateURL: function (location) {
    location = location || (this.prev.scale === this.scale ? this.getLocation(this.start, this.end, Ensembl.location.length,1) : this);
    
    if (Ensembl.location.start === location.start && Ensembl.location.end === location.end) {
      return;
    }
    
    this.updatingURL = true;
    
    Ensembl.updateLocation(this.urlParamTemplate
      .replace('r=',        '')
      .replace('__CHR__',   this.chr)
      .replace('__START__', location.start)
      .replace('__END__',   location.end)
    );
  },
  
  popState: function () {
    this.updatingURL     = true;
    Ensembl.historyReady = true;
    this.base();
  },
{'fraction_non_alphanumeric': 0.12557518183167582, 'fraction_numerical': 0.007570135074959181, 'mean_word_length': 3.528225806451613, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5036697', 'n_tokens_mistral': 2016, 'n_tokens_neox': 1971, 'n_words': 530}