Skip to content

Commit

Permalink
feature(js): elgg.ui.toggle now triggers jQuery event
Browse files Browse the repository at this point in the history
After a toggle is activated, an event is fired on the toggle element. Listeners
receive a jQuery-wrapped reference to the target element(s).
  • Loading branch information
mrclay committed Dec 8, 2015
1 parent 8d2a4b2 commit 941b49a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions js/lib/ui.js
Expand Up @@ -55,24 +55,30 @@ elgg.ui.init = function () {
elgg.ui.toggles = function(event) {
event.preventDefault();
var $this = $(this),
target = $this.data().toggleSelector;
selector = $this.data().toggleSelector;

if (!target) {
if (!selector) {
// @todo we can switch to elgg.getSelectorFromUrlFragment() in 1.x if
// we also extend it to support href=".some-class"
target = $this.attr('href');
selector = $this.attr('href');
}

var $elements = $(selector);

$this.toggleClass('elgg-state-active');

$(target).each(function(index, elem) {
$elements.each(function(index, elem) {
var $elem = $(elem);
if ($elem.data().toggleSlide != false) {
$elem.slideToggle('medium');
} else {
$elem.toggle();
}
});

$this.trigger('elgg_ui_toggle', [{
$toggled_elements: $elements
}]);
};

/**
Expand Down

0 comments on commit 941b49a

Please sign in to comment.