Button Dropdown Library

This library contains helper functions that make the manipulation of a button dropdown widget easier.

You will need to provide the full URL in order to load this library as a dependency to a module:

gx.controller.module(
  'my_custom_page',

  [
     gx.source + '/libs/button_dropdown'
  ],

  function(data) {
     // Module code ... 
  });

Example

var $buttonDropdown = $('#my.js-button-dropdown');

// Map an action to a dropdown item.
jse.libs.button_dropdown.mapAction($buttonDropdown, action, section, callback, $targetRecentButton);

// Change recent button.
jse.libs.button_dropdown.changeDefualtButton($buttonDropdown, text, callback, $targetRecentButton);

// Add a separator in a dropdown list.
jse.libs.button_dropdown.addDropdownSeperator($buttonDropdown);
Source:
To Do:
  • Further improve the code and the comments of this library.

Methods

(static) addAction($dropdown, action)

Add button-dropdown action.

This method works with the Bootstrap markup button-dropdowns and enables you to add actions with callbacks existing button dropdown elements.

The action object can have the following attributes and default values:

{ text: '{Undefined}', // The text to be displayed. href: '#', // URL for the element. target: '', // Target attribute for element. class: '', // Add custom classes to the element. data: {}, // Add data to the element. isDefault: false, // Whether the action is the default action. callback: function(e) {} // Callback for click event of the element. }

Parameters:
Name Type Description
$dropdown object

The jQuery selector of the button dropdown wrapper.

action object

An object containing the action information.

Source:

(static) addSeparator($dropdown, compatibilityMarkup)

Adds a separator to the dropdown list.

The separator will be added at the end of the list.

Parameters:
Name Type Description
$dropdown object

The jQuery selector of the button dropdown wrapper.

compatibilityMarkup bool

(optional) Whether to use the compatibility markup.

Source:

(static) bindDefaultAction($dropdowns, userId, configurationKey, userConfigurationService)

Bind button dropdown default action.

This method will update the default action of the dropdown upon click. This is useful for storing the default actions and then using them to display the default one with every new instance of the button dropdown.

Important: The elements need to have the "configurationValue" data property that defines a unique string for the selected action.

Parameters:
Name Type Description
$dropdowns object

The jQuery selector of the button dropdowns wrapper.

userId number

The ID of the current user.

configurationKey string

The configuration key to be saved.

userConfigurationService object

The user_configuration_service module (needs to be passed explicitly).

Source:

(static) changeDefaultAction($button, title, callback, $targetDefaultButton)

Changes the default action of the button.

Parameters:
Name Type Description
$button object

The affected button dropdown widget.

title string

Text of the new button.

callback string

The callback

$targetDefaultButton object

A custom element for which button should be changed.

Source:

(static) mapAction(translationPhrase, translationSection, customCallback, $targetDefaultButton)

Adds a new item to the dropdown.

Parameters:
Name Type Description
translationPhrase string

Translation phrase key.

translationSection string

Translation section of the phrase.

customCallback function

Define a custom callback.

$targetDefaultButton object

(optional) A custom selector which dropdown buttons should be changed.

Source:

(static) setDefaultAction($dropdowns, $actionLink)

Set the default action item for button dropdowns.

Parameters:
Name Type Description
$dropdowns object

jQuery selector for the button dropdowns.

$actionLink object

jQuery selector for the action link to be set as default.

Source: