Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made using dropdowns in dropped down panels work. #127

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 29 additions & 18 deletions jquery.dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ if (jQuery) (function ($) {
} else {
if (trigger !== object.target && $(object.target).hasClass('jq-dropdown-ignore')) return;
}
hide();
hide(event);

if (isOpen || trigger.hasClass('jq-dropdown-disabled')) return;

Expand All @@ -75,41 +75,52 @@ if (jQuery) (function ($) {
// In some cases we don't hide them
var targetGroup = event ? $(event.target).parents().addBack() : null;

// Things to hide, by default every dropdown visible
var toHide = $(document).find('.jq-dropdown:visible');

// Are we clicking anywhere in a jq-dropdown?
if (targetGroup && targetGroup.is('.jq-dropdown')) {
// Is it a jq-dropdown menu?
if (targetGroup.is('.jq-dropdown-menu')) {
// Did we click on an option? If so close it.
if (!targetGroup.is('A')) return;
} else {
// Nope, it's a panel. Leave it open.
return;
}
// Nope, it's a panel. Leave it open, but close others
toHide = $(document).find('.jq-dropdown:visible').not(
$(event.target).parents('.jq-dropdown')); }
}

// Hide any jq-dropdown that may be showing
$(document).find('.jq-dropdown:visible').each(function () {
toHide.each(function () {
var jqDropdown = $(this);
// Remove all jq-dropdown-open classes from things to hide...
jqDropdown.find('.jq-dropdown-open').removeClass('jq-dropdown-open');
// ... and from whatever caused it to be shown
$(document).find('[data-jq-dropdown=\'#' + this.id + '\']').
removeClass('jq-dropdown-open');
// Hide and trigger
jqDropdown
.hide()
.removeData('jq-dropdown-trigger')
.trigger('hide', { jqDropdown: jqDropdown });
});

// Remove all jq-dropdown-open classes
$(document).find('.jq-dropdown-open').removeClass('jq-dropdown-open');

}

function position() {

var jqDropdown = $('.jq-dropdown:visible').eq(0),
trigger = jqDropdown.data('jq-dropdown-trigger'),
hOffset = trigger ? parseInt(trigger.attr('data-horizontal-offset') || 0, 10) : null,
vOffset = trigger ? parseInt(trigger.attr('data-vertical-offset') || 0, 10) : null;

if (jqDropdown.length === 0 || !trigger) return;

$('.jq-dropdown:visible').each(function() {
positionJqDropdown($( this ));
});
}

function positionJqDropdown(jqDropdown) {

var trigger = jqDropdown.data('jq-dropdown-trigger');

if (!trigger) return;

var hOffset = parseInt(trigger.attr('data-horizontal-offset') || 0, 10),
vOffset = parseInt(trigger.attr('data-vertical-offset') || 0, 10);

// Position the jq-dropdown relative-to-parent...
if (jqDropdown.hasClass('jq-dropdown-relative')) {
jqDropdown.css({
Expand Down