Skip to content

Commit

Permalink
feature(dropdown): add dropup and menu-right support to dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Zschech committed Nov 11, 2016
1 parent a4c3930 commit 679fa05
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/dropdown/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ angular.module('mgcrea.ngStrap.dropdown', ['mgcrea.ngStrap.tooltip'])
bodyEl.on('click', onBodyClick);
}, 0, false);
var target = getTarget();
if (target.hasClass('dropdown')) target.addClass('open');
if (target.hasClass('dropdown') || target.hasClass('dropup')) target.addClass('open');
};

var hide = $dropdown.hide;
Expand All @@ -79,7 +79,7 @@ angular.module('mgcrea.ngStrap.dropdown', ['mgcrea.ngStrap.tooltip'])
if (options.keyboard && dropdownElement) dropdownElement.off('keydown', $dropdown.$onKeyDown);
bodyEl.off('click', onBodyClick);
var target = getTarget();
if (target.hasClass('dropdown')) target.removeClass('open');
if (target.hasClass('dropdown') || target.hasClass('dropup')) target.removeClass('open');
};

var destroy = $dropdown.destroy;
Expand Down
25 changes: 22 additions & 3 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,28 @@ angular.module('mgcrea.ngStrap.tooltip', ['mgcrea.ngStrap.core', 'mgcrea.ngStrap
tipElement.removeClass(originalPlacement).addClass(placement);
}

// Get the tooltip's top and left coordinates to center it with this directive.
var tipPosition = getCalculatedOffset(placement, elementPosition, tipWidth, tipHeight);
applyPlacement(tipPosition, placement);
if (options.target && (options.target.hasClass('dropdown') || options.target.hasClass('dropup'))) {
if (placement.indexOf('top') >= 0) {
options.target.removeClass('dropdown').addClass('dropup');
}
else {
options.target.removeClass('dropup').addClass('dropdown');
}

if (tipElement.hasClass('dropdown-menu')) {
if (placement.indexOf('left') >= 0) {
tipElement.removeClass('dropdown-menu-right');
}
else {
tipElement.addClass('dropdown-menu-right');
}
}
}
else {
// Get the tooltip's top and left coordinates to center it with this directive.
var tipPosition = getCalculatedOffset(placement, elementPosition, tipWidth, tipHeight);
applyPlacement(tipPosition, placement);
}
};

$tooltip.$onKeyUp = function (evt) {
Expand Down

0 comments on commit 679fa05

Please sign in to comment.