<commit_before>/* Copyright 2011 the Melange authors.
 *
 * 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.
 */
/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */

melange.templates.inherit(
  function (_self, context) {
    jQuery('.' + context.dashboard_link_class).bind('click', function() {
      var target_str = jQuery(this).attr('href') + context.dashboard_id_suffix;
      var dashboard = jQuery(target_str);

      // hide other dashboards
      jQuery('.' + context.dashboard_class).addClass('disabled');
      // show clicked dashboard
      dashboard.removeClass('disabled').show();

      // check if this dashboard contain components
      if (jQuery(this).hasClass(context.component_link_class)) {
        jQuery('.' + context.list_container_class, dashboard).each(function() {
          var extracted_id = /^(\w+[^\d+])(\d+)$/.exec(jQuery(this).attr('id'));
          if (extracted_id !== null) {
            melange.list.list_objects.get(extracted_id[2]).init();
          }
        });
      }

      return false;
    });
  }
);
<commit_msg>Change the event binding to window.onhashchange instead of onclick<commit_after>/* Copyright 2011 the Melange authors.
 *
 * 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.
 */
/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */

melange.templates.inherit(
  function (_self, context) {
    // Bind an event to window.onhashchange that, when the hash changes, gets
    // the hash and shows the related dashboard
    jQuery(window).hashchange(function() {
      var hash = location.hash;

      // targets the link to dashboard of current hash
      var dashboard_link = jQuery('.' + context.dashboard_link_class + '[href="' + hash + '"]');
      if ( !dashboard_link.length ) {
        // if nothing is targeted, targets the link to main dashboard
        hash = '#main';
        dashboard_link = jQuery('.' + context.dashboard_link_class + '[href="' + hash + '"]');
      }

      var current_dasboard = jQuery(hash + context.dashboard_id_suffix);

      // hide other dashboards
      jQuery('.' + context.dashboard_class).addClass('disabled');
      // show current dashboard
      current_dasboard.removeClass('disabled').show();

      // check if this dashboard contains components
      if (dashboard_link.hasClass(context.component_link_class)) {
        // if it does then trigger the list to be loaded
        jQuery('.' + context.list_container_class, current_dasboard).each(function() {
          var extracted_id = /^(\w+[^\d+])(\d+)$/.exec(jQuery(this).attr('id'));
          if (extracted_id !== null) {
            melange.list.list_objects.get(extracted_id[2]).init();
          }
        });
      }
    });

    // Since the event is only triggered when the hash changes, we need to
    // trigger the event now, to handle the hash the page may have loaded with.
    jQuery(window).hashchange();
  }
);
{'fraction_non_alphanumeric': 0.12381197020292833, 'fraction_numerical': 0.0046236835345491905, 'mean_word_length': 3.0946372239747633, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3431444', 'n_tokens_mistral': 1073, 'n_tokens_neox': 1051, 'n_words': 353}