Templarian / ui.bootstrap.contextMenu

AngularJS Bootstrap UI Context Menu
MIT License
259 stars 127 forks source link

Feature: Menu position offset #4

Open nobalmohan opened 9 years ago

nobalmohan commented 9 years ago

In SPA with fixed height, there should be an option to position the menu via CSS class or by JS.

         if( event.pageY > 360 ) {
             popupPosition = (event.pageY - 250) + 'px';
         }else {
             popupPosition = event.pageY + 'px';
         }

         $ul.css({
             display: 'block',
             position: 'absolute',
             left: event.pageX + 'px',
             top: popupPosition,
             width: '15%'
         });
Templarian commented 9 years ago

Maybe something more along the lines of an anchor ability.

<any context-menu="" context-menu-anchor="top left"></any>

Where contextMenuAnchor can be:

default            - Calculate based on position and contextmenu size.
bottom right
bottom left
top right
top left

Would be a nice idea to have in the future.

nobalmohan commented 9 years ago

Yup. Something like this http://angular-ui.github.io/bootstrap/#/popover

Templarian commented 9 years ago

Yep. Now we wait for someone to make a pull request, or me to get bored enough to code it. :smile_cat:

nobalmohan commented 9 years ago

Give me the spec on how to do it. I will make a PR

On Tue, Feb 10, 2015 at 12:06 PM, Austin Andrews notifications@github.com wrote:

Yep. Now we wait for someone to make a pull request, or me to get bored enough to code it. [image: :smile_cat:]

— Reply to this email directly or view it on GitHub https://github.com/Templarian/ui.bootstrap.contextMenu/issues/4#issuecomment-73651729 .

Thanks, Nobal

nobal.in | @NobalMohan https://twitter.com/NobalMohan

nobalmohan commented 9 years ago

There are two use-case here: 1. Positioning of the pop-up 2. Making it fluid with respect to view port

On Tue, Feb 10, 2015 at 7:09 PM, Nobal Mohan nobal20@gmail.com wrote:

Give me the spec on how to do it. I will make a PR

On Tue, Feb 10, 2015 at 12:06 PM, Austin Andrews <notifications@github.com

wrote:

Yep. Now we wait for someone to make a pull request, or me to get bored enough to code it. [image: :smile_cat:]

— Reply to this email directly or view it on GitHub https://github.com/Templarian/ui.bootstrap.contextMenu/issues/4#issuecomment-73651729 .

Thanks, Nobal

nobal.in | @NobalMohan https://twitter.com/NobalMohan

Thanks, Nobal

nobal.in | @NobalMohan https://twitter.com/NobalMohan

Templarian commented 9 years ago

Correct. I'm working on client work tonight. Will type out a spec of what it should look like/features tomorrow. :sweat_smile:

Templarian commented 9 years ago

So basically it will support the following locations...

contextmenu-right-click

I'm not 100% sure the best way to implement this. Basically:

  1. Render the full context menu.
  2. Get the width and height of the context menu.
  3. Calculate screen.height - (cursorPosition.y + contextMenu.height) = offset.y
  4. Similar to above calculate, screen.width - (cursorPosition.x + contextMenu.width) = offset.x
  5. Offset based on offset values from 4 and 5 as long as they are negative.

That is the basic idea.

nobalmohan commented 9 years ago

Thankns. This snippet will be helpful https://github.com/angular-ui-tree/angular-ui-tree/blob/master/source/directives/uiTreeNode.js#L168

On Sat, Feb 14, 2015 at 1:14 PM, Austin Andrews notifications@github.com wrote:

So basically it will support the following locations...

[image: contextmenu-right-click] https://cloud.githubusercontent.com/assets/338885/6198966/33357f3e-b3ea-11e4-8159-286af183c1ca.png

I'm not 100% sure the best way to implement this. Basically:

  1. Render the full context menu.
  2. Get the width and height of the context menu.
  3. Calculate screen.height - cursorPosition.y + contextMenu.height = offset.y
  4. Similar to above, screen.width - calculate cursorPosition.x + contextMenu.width = offset.x
  5. Offset based on offset values from 4 and 5.

That is the basic idea.

— Reply to this email directly or view it on GitHub https://github.com/Templarian/ui.bootstrap.contextMenu/issues/4#issuecomment-74365894 .

Thanks, Nobal

nobal.in | @NobalMohan https://twitter.com/NobalMohan

madmas commented 8 years ago

:+1: this would be very helpful; any progress so far? :)

Templarian commented 8 years ago

Nope. Working on other open source projects at the moment. Now that nested menus are in this would be the next feature to add I think.

Definitely would take a pull request, but I'm probably not going to add this functionality for a while until I need it myself.

madmas commented 8 years ago

Here it is :-) Didn't look at submenues for the first version ;)

Templarian commented 8 years ago

Looks awesome. I'm going to leave this issue opened to track the progress for nested menu's, but simply having support for single level will solve most users issue (nesting wasn't supported when this issue was created).

If anyone sees this and wants to pull request that functionality I'll definitely merge it. :smile:

madmas commented 8 years ago

Cool thing, very happy to see it got merged so quickly :+1: Any plans on releasing a new version that contains this?

Templarian commented 8 years ago

Yea, should have time later today after my run (I have a few other minor features to edit in before I tag it for a release). Busy working on my other open source project for the next few hours.

madmas commented 8 years ago

Cool, looking forward to it ;-) Thanks a lot for your work!

josetaira commented 8 years ago

This commit https://github.com/Templarian/ui.bootstrap.contextMenu/pull/52/commits/bc4d4d0ece0b9dce5b7213f744b63ed90aaa6d41 in PR https://github.com/Templarian/ui.bootstrap.contextMenu/pull/52 integrates the work done here with the Nested Menus.

I've only worked on the topCoordinate though. I'm still thinking of a good way to implement the leftCoordinate part. @madmas maybe you have some ideas?