-
- 'use strict';
-
- /**
- * Process elements with the .dropbutton class on page load.
- *
- * @type {Drupal~behavior}
- *
- * @prop {Drupal~behaviorAttach} attach
- * Attaches dropButton behaviors.
- */
- Drupal.behaviors.dropButton = {
- attach: function (context, settings) {
- var $dropbuttons = $(context).find('.dropbutton-wrapper').once('dropbutton');
- if ($dropbuttons.length) {
- // Adds the delegated handler that will toggle dropdowns on click.
- var $body = $('body').once('dropbutton-click');
- if ($body.length) {
- $body.on('click', '.dropbutton-toggle', dropbuttonClickHandler);
- }
- // Initialize all buttons.
- var il = $dropbuttons.length;
- for (var i = 0; i < il; i++) {
- DropButton.dropbuttons.push(new DropButton($dropbuttons[i], settings.dropbutton));
- }
- }
- }
- };
-
- /**
- * Delegated callback for opening and closing dropbutton secondary actions.
- *
- * @function Drupal.DropButton~dropbuttonClickHandler
- *
- * @param {jQuery.Event} e
- * The event triggered.
- */
- function dropbuttonClickHandler(e) {
- e.preventDefault();
- $(e.target).closest('.dropbutton-wrapper').toggleClass('open');
- }
-
- /**
- * A DropButton presents an HTML list as a button with a primary action.
- *
- * All secondary actions beyond the first in the list are presented in a
- * dropdown list accessible through a toggle arrow associated with the button.
- *
- * @constructor Drupal.DropButton
- *
- * @param {HTMLElement} dropbutton
- * A DOM element.
- * @param {object} settings
- * A list of options including:
- * @param {string} settings.title
- * The text inside the toggle link element. This text is hidden
- * from visual UAs.
- */