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 Jun 26, 2015
1 parent 4ba52e3 commit 4c77c12
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/dropdown/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ angular.module('mgcrea.ngStrap.dropdown', ['mgcrea.ngStrap.tooltip'])
bodyEl.on('click', onBodyClick);
}, 0, false);
var target = getTarget();
target.hasClass('dropdown') && target.addClass('open');
(target.hasClass('dropdown') || target.hasClass('dropup')) && target.addClass('open');
};

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

var destroy = $dropdown.destroy;
Expand Down
43 changes: 33 additions & 10 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,13 @@ angular.module('mgcrea.ngStrap.tooltip', ['mgcrea.ngStrap.helpers.dimensions'])
$tooltip.$isShown = scope.$isShown = true;
safeDigest(scope);

// Now, apply placement
$tooltip.$applyPlacement();

if (options.inlineTemplate) {
enterAnimateCallback();
}
else {
// Now, apply placement
$tooltip.$applyPlacement();

// Once placed, animate it.
// Support v1.2+ $animate
// https://github.com/angular/angular.js/issues/11713
Expand Down Expand Up @@ -394,9 +394,11 @@ angular.module('mgcrea.ngStrap.tooltip', ['mgcrea.ngStrap.helpers.dimensions'])
placement = placement.replace(autoToken, '') || defaults.placement;
}

// Need to add the position class before we get
// the offsets
tipElement.addClass(options.placement);
if (!options.inlineTemplate) {
// Need to add the position class before we get
// the offsets
tipElement.addClass(options.placement);
}

// Get the position of the target element
// and the height and width of the tooltip so we can center it.
Expand Down Expand Up @@ -430,12 +432,33 @@ angular.module('mgcrea.ngStrap.tooltip', ['mgcrea.ngStrap.helpers.dimensions'])
placement = originalPlacement === 'left' ? 'right' : placement.replace('right', 'left');
}

tipElement.removeClass(originalPlacement).addClass(placement);
if (!options.inlineTemplate) {
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 4c77c12

Please sign in to comment.