Sha256: fe10c77ab476f76c5f8041250a4c4e1a23fa42e21c6ff9b61b04a2a46e5028f6

Contents?: true

Size: 1.47 KB

Versions: 31

Compression:

Stored size: 1.47 KB

Contents

(function() {
  "use strict";
  window.GOVUK = window.GOVUK || {};

  // Only show the first {n} items in a list, documentation is in the README.md
  var PrimaryList = function(el, selector){
    this.$el = $(el);
    this.$extraLinks = this.$el.find('li:not('+selector+')');
    // only hide more than one extra link
    if(this.$extraLinks.length > 1){
      this.addToggleLink();
      this.hideExtraLinks();
    }
  };
  PrimaryList.prototype = {
    toggleText: function(){
      if(this.$extraLinks.length > 1){
        return '+'+ this.$extraLinks.length +' others';
      } else {
        return '+'+ this.$extraLinks.length +' other';
      }
    },
    addToggleLink: function(){
      this.$toggleLink = $('<a href="#">'+ this.toggleText() + '</a>');
      this.$toggleLink.click($.proxy(this.toggleLinks, this));
      this.$toggleLink.insertAfter(this.$el);
    },
    toggleLinks: function(e){
      e.preventDefault();
      this.$toggleLink.remove();
      this.showExtraLinks();
    },
    hideExtraLinks: function(){
      this.$extraLinks.addClass('visuallyhidden');
      $(window).trigger('govuk.pageSizeChanged');
    },
    showExtraLinks: function(){
      this.$extraLinks.removeClass('visuallyhidden');
      $(window).trigger('govuk.pageSizeChanged');
    }
  };
  GOVUK.PrimaryList = PrimaryList;

  GOVUK.primaryLinks = {
    init: function(selector){
      $(selector).parent().each(function(i, el){
        new GOVUK.PrimaryList(el, selector);
      });
    }
  };
}());

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
govuk_frontend_toolkit-4.13.0 app/assets/javascripts/govuk/primary-links.js
govuk_frontend_toolkit-4.12.0 app/assets/javascripts/govuk/primary-links.js
govuk_frontend_toolkit-4.11.0 app/assets/javascripts/govuk/primary-links.js
govuk_frontend_toolkit-4.10.0 app/assets/javascripts/govuk/primary-links.js
govuk_frontend_toolkit-4.9.1 app/assets/javascripts/govuk/primary-links.js
govuk_frontend_toolkit-4.9.0 app/assets/javascripts/govuk/primary-links.js
govuk_frontend_toolkit-4.8.2 app/assets/javascripts/govuk/primary-links.js
govuk_frontend_toolkit-4.8.1 app/assets/javascripts/govuk/primary-links.js
govuk_frontend_toolkit-4.8.0 app/assets/javascripts/govuk/primary-links.js
govuk_frontend_toolkit-4.7.0 app/assets/javascripts/govuk/primary-links.js
govuk_frontend_toolkit-4.6.1 app/assets/javascripts/govuk/primary-links.js
govuk_frontend_toolkit-4.6.0 app/assets/javascripts/govuk/primary-links.js
govuk_frontend_toolkit-4.5.0 app/assets/javascripts/govuk/primary-links.js
govuk_frontend_toolkit-4.4.0 app/assets/javascripts/govuk/primary-links.js
govuk_frontend_toolkit-4.3.0 app/assets/javascripts/govuk/primary-links.js
govuk_frontend_toolkit-4.2.1 app/assets/javascripts/govuk/primary-links.js
govuk_frontend_toolkit-4.2.0 app/assets/javascripts/govuk/primary-links.js
govuk_frontend_toolkit-4.1.1 app/assets/javascripts/govuk/primary-links.js
govuk_frontend_toolkit-4.1.0 app/assets/javascripts/govuk/primary-links.js
govuk_frontend_toolkit-4.0.1 app/assets/javascripts/govuk/primary-links.js