GithubHelp home page GithubHelp logo

Comments (4)

richardingham avatar richardingham commented on July 29, 2024 2

Bootstrap 3.0 has removed the ability to support submenus, but it is possible to position Bootstrap 2.3.2 submenus correctly with this context menu plugin by adding the following code:

In ContextMenu.prototype.show:

$menu.on('mouseover.context.data-api', items, $.proxy(this.layoutSubmenu, this))

In ContextMenu.prototype.closemenu:

$menu.off('mouseover.context.data-api', items, $.proxy(this.layoutSubmenu, this))

Then add the method:

,layoutSubmenu: function (e) {
    var parent = $(e.currentTarget);
    if (!parent.is('.dropdown-submenu') || parent.is('.dropdown-submenu-positioned')) {
        return;
    }
    parent.removeClass("pull-left dropup");
    var child = parent.children('.dropdown-menu');
    var childOffset = child.offset();

    if (childOffset.left + child.outerWidth() > $(window).width()) {
        parent.addClass("pull-left");
    }
    if (childOffset.top + child.outerHeight() > $(window).height()) {
        parent.addClass("dropup");
    }
    parent.addClass('dropdown-submenu-positioned');
}

Note that with this solution, the CSS rule for .dropup. dropdown-submenu > .dropdown-menu must be changed to .dropup.dropdown-submenu > .dropdown-menu:

// Dropups
.dropup.dropdown-submenu > .dropdown-menu {
  top: auto;
  bottom: 0;
  margin-top: 0;
  margin-bottom: -2px;
  .border-radius(5px 5px 5px 0);
}

Since it's deprecated in Bootstrap I decided just to leave a comment here for anyone who (like me) really wanted this functionality regardless of whether Bootstrap thinks it's a good idea. I can submit a pull request if you like though!

from bootstrap-contextmenu.

sydcanem avatar sydcanem commented on July 29, 2024

This is something I'll have to do in the next version.

from bootstrap-contextmenu.

sydcanem avatar sydcanem commented on July 29, 2024

I noticed bootstrap's dropdown does not automatically adjust submenu position when close on borders. Is this something that should be added to the contextmenu?

from bootstrap-contextmenu.

morgandenning avatar morgandenning commented on July 29, 2024

I was able to handle sub-contextmenus by calling .menu() on the context menu before initializing the plugin.

ie:

$("#context-menu").menu();
$("#container").contextmenu({
"target" : "#context-menu",
"onItem" : handleContextMenu
});

from bootstrap-contextmenu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.