var initClickFunctions = function()

in static/js/glossary.js [50:163]


  var initClickFunctions = function() {

    var deactivateTagTerms = function(elt) {
      var targetTag = elt.data("target");
      var targetClass = "." + targetTag;
      var tagName = targetTag.split('tag-')[1];

      elt.removeClass("active-tag");
      $(targetClass).each(function(){
        var showCount = $(this).data("show-count");
        var newShowCount = showCount - 1;
        $(this).data("show-count", newShowCount);
        if (newShowCount < 1) {
          $(this).addClass("hide");
        }
      });
      delete activeTags[tagName];
    };

    var activateTagTerms = function(elt) {
      var targetTag = elt.data("target");
      var targetClass = "." + targetTag;
      var tagName = targetTag.split('tag-')[1];

      elt.addClass("active-tag");
      $(targetClass).each(function(){
        var showCount = $(this).data("show-count");
        var newShowCount = showCount + 1;
        $(this).data("show-count", newShowCount);
        if (newShowCount > 0) {
          $(this).removeClass("hide");
        }
      });
      activeTags[tagName] = true;
      if (activeTags[deselectAllKey]) {
        delete activeTags[deselectAllKey];
      }
    };

    // Shows/hides glossary terms when their relevant tags are clicked
    $(".canonical-tag").each(function(){
      var placeholder = $("#placeholder");
      var targetTag = $(this).data("target");
      $(this).mouseenter(function(){
        var tagDescription = $("#" + targetTag + "-description").html();
        placeholder.html(tagDescription);
        placeholder.removeClass('invisible');
      }).mouseleave(function(){
        placeholder.addClass('invisible');
      });

      $(this).click(function(){
        var shouldHide = $(this).hasClass("active-tag");
        if (shouldHide) {
          deactivateTagTerms($(this));
        } else {
          activateTagTerms($(this));
        }
        urlParamLib.updateParams(activeTags);
      });
    });

    // Adds functionality to "select all tags" link
    $("#select-all-tags").click(function(){
      $(".canonical-tag").each(function(){
        var shouldActivate = !$(this).hasClass("active-tag");
        if (shouldActivate) {
          activateTagTerms($(this));
        }
      });
      queryParams = {}
      queryParams[selectAllKey] = true;
      urlParamLib.updateParams(queryParams);
    });

    // Adds functionality to "deselect all tags" link
    $("#deselect-all-tags").click(function(){
      $(".canonical-tag").each(function(){
        var shouldHide = $(this).hasClass("active-tag");
        if (shouldHide) {
          deactivateTagTerms($(this));
        }
      });
      queryParams = {}
      queryParams[deselectAllKey] = true;
      urlParamLib.updateParams(queryParams);
    });

    // Expands/hides glossary term definitions when [+] button is clicked
    $(".click-controller").each(function(){
      $(this).click(function() {
        var targetId = $(this).data("target");
        var shouldExpand = $(this).html() == expandText;

        if (shouldExpand) {
          $("#" + targetId).removeClass('hide');
          $(this).html(closeText);
        } else {
          $("#" + targetId).addClass('hide');
          $(this).html(expandText);
        }
      });
    });

    // Shows permalink when term name is hovered over
    $(".term-name").each(function() {
      var permalink = $($(this).parent().find(".permalink")[0]);
      $(this).mouseenter(function(){
        permalink.removeClass("hide");
      }).mouseleave(function(){
        permalink.addClass("hide");
      });;
    });
  };