diff --git a/bootstrap-contextmenu.js b/bootstrap-contextmenu.js index dc1e38bc..3c8d3a8c 100644 --- a/bootstrap-contextmenu.js +++ b/bootstrap-contextmenu.js @@ -23,6 +23,7 @@ this.before = options.before || this.before; this.onItem = options.onItem || this.onItem; this.scopes = options.scopes || null; + this.container = options.container || window; if (options.target) { this.$element.data('target', options.target); @@ -137,23 +138,23 @@ ,getPosition: function(e, $menu) { var mouseX = e.clientX , mouseY = e.clientY - , boundsX = $(window).width() - , boundsY = $(window).height() + , boundsX = $(this.container).width() + , boundsY = $(this.container).height() , menuWidth = $menu.find('.dropdown-menu').outerWidth() , menuHeight = $menu.find('.dropdown-menu').outerHeight() , tp = {"position":"absolute","z-index":9999} , Y, X, parentOffset; if (mouseY + menuHeight > boundsY) { - Y = {"top": mouseY - menuHeight + $(window).scrollTop()}; + Y = {"top": mouseY - menuHeight + $(this.container).scrollTop()}; } else { - Y = {"top": mouseY + $(window).scrollTop()}; + Y = {"top": mouseY + $(this.container).scrollTop()}; } if ((mouseX + menuWidth > boundsX) && ((mouseX - menuWidth) > 0)) { - X = {"left": mouseX - menuWidth + $(window).scrollLeft()}; + X = {"left": mouseX - menuWidth + $(this.container).scrollLeft()}; } else { - X = {"left": mouseX + $(window).scrollLeft()}; + X = {"left": mouseX + $(this.container).scrollLeft()}; } // If context-menu's parent is positioned using absolute or relative positioning, diff --git a/bower.json b/bower.json index c422ee8f..4d34ce75 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "bootstrap-contextmenu", "main": "bootstrap-contextmenu.js", - "version": "0.3.2", + "version": "0.3.3", "homepage": "https://github.com/sydcanem/bootstrap-contextmenu", "authors": [ "sydcanem " diff --git a/package.json b/package.json index 7b289c62..23e770bc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bootstrap-contextmenu", - "version": "0.3.2", + "version": "0.3.3", "description": "Context-menu extension for the Bootstrap framework", "main": "bootstrap-contextmenu.js", "directories": {