<commit_before>//Extension to Ensembl.Panel.Masthead to add some dynamic behaviour to account links

Ensembl.Panel.Masthead = Ensembl.Panel.Masthead.extend({
  init: function () {
    var panel = this;
    this.base();

    var hideDropdown = function() {
      panel.toggleAccountsDropdown(false);
      $(document).off('click', hideDropdown);
    }

    this.elLk.accountLink = this.el.find('._accounts_link').on({
      'click': function(event) {
        event.preventDefault();
        if (!$(this).hasClass('selected')) {
          event.stopPropagation();
          panel.toggleAccountsDropdown(true);
          $(document).on('click', hideDropdown);
        }
      }
    });

    this.elLk.accountDropdown = this.el.find('._accounts_dropdown').on({
      'click': function(event) {
        if (event.target.nodeName !== 'A') {
          event.stopPropagation();
        }
      }
    }).find('a').on('click', hideDropdown).end();
  },

  toggleAccountsDropdown: function(flag) {
    this.elLk.accountLink.toggleClass('selected', flag);
    this.elLk.accountDropdown.toggle(flag);
    if (flag && !this.elLk.accountDropdown.data('initiated')) {
      this.elLk.accountDropdown.data('initiated', true).find('p').each(function() {
        var p = $(this);
        var checkHeight = p.children('a').hide().end().append('<a>abc</a>').height();
        p.children('a').last().remove().end().show();
        if (p.height() > checkHeight) {
          p.addClass('acc-bookmark-overflow');
        }
      });
    }
  }
});<commit_msg>accounts dropdown is now fetched via ajax<commit_after>//Extension to Ensembl.Panel.Masthead to add some dynamic behaviour to account links

Ensembl.Panel.Masthead = Ensembl.Panel.Masthead.extend({
  constructor: function (id) {
    this.base(id);

    Ensembl.EventManager.register('refreshAccountsDropdown', this, this.refreshAccountsDropdown);
  },

  init: function () {
    this.base();

    this.elLk.accountHolder = this.el.find('div._account_holder');
    
    this.refreshAccountsDropdown();
  },
  
  refreshAccountsDropdown: function() {
    var panel = this;

    this.elLk.accountHolder.empty();

    var hideDropdown = function() {
      panel.toggleAccountsDropdown(false);
      $(document).off('click', hideDropdown);
    }

    $.ajax('/Ajax/accounts_dropdown', {
      'context': this,
      'success': function(html) {
        this.elLk.accountHolder.html(html);
        this.elLk.accountLink = this.el.find('._accounts_link').on({
          'click': function(event) {
            event.preventDefault();
            if (!$(this).hasClass('selected')) {
              event.stopPropagation();
              panel.toggleAccountsDropdown(true);
              $(document).on('click', hideDropdown);
            }
          }
        });
    
        this.elLk.accountDropdown = this.el.find('._accounts_dropdown').on({
          'click': function(event) {
            if (event.target.nodeName !== 'A') {
              event.stopPropagation();
            }
          }
        }).find('a').on('click', hideDropdown).end();
      },
      'dataType': 'html'
    });
  },

  toggleAccountsDropdown: function(flag) {
    this.elLk.accountLink.toggleClass('selected', flag);
    this.elLk.accountDropdown.toggle(flag);
    if (flag && !this.elLk.accountDropdown.data('initiated')) {
      this.elLk.accountDropdown.data('initiated', true).find('p').each(function() {
        var p = $(this);
        var checkHeight = p.children('a').hide().end().append('<a>abc</a>').height();
        p.children('a').last().remove().end().show();
        if (p.height() > checkHeight) {
          p.addClass('acc-bookmark-overflow');
        }
      });
    }
  }
});
{'fraction_non_alphanumeric': 0.1730197350635307, 'fraction_numerical': 0.0, 'mean_word_length': 2.656126482213439, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '1360200', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1142, 'n_words': 161}