From 53787c93bfc32e481079edcca3fe6f37f8c458d2 Mon Sep 17 00:00:00 2001 From: tgelu Date: Mon, 6 Jul 2015 10:31:38 +0200 Subject: [PATCH 1/9] Adjust context menu position If the context menu is rendered outside the window viewport then adjust its position accordingly --- dist/angular-context-menu.js | 28 ++++++++++++++++++---------- dist/angular-context-menu.min.js | 2 +- src/angular-context-menu.js | 28 ++++++++++++++++++---------- 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/dist/angular-context-menu.js b/dist/angular-context-menu.js index 2db59d1..af243d9 100644 --- a/dist/angular-context-menu.js +++ b/dist/angular-context-menu.js @@ -57,12 +57,11 @@ angular.module('ng-context-menu', []) if (css) { element.css(css); } - + adjustPosition(element); return element; }); } - function attach (html, locals) { container = angular.element(config.container || document.body); element = angular.element(html); @@ -104,6 +103,17 @@ angular.module('ng-context-menu', []) return deferred.promise; } + function adjustPosition(element) { + var windowHeight = 'innerHeight' in window ? window.innerHeight : document.documentElement.offsetHeight; + var windowWidth = 'innerWidth' in window ? window.innerWidth : document.documentElement.offsetWidth; + if (windowHeight < element[0].offsetTop + element[0].offsetHeight) { + element.css('top', element[0].offsetTop - element[0].offsetHeight + 'px'); + } + if (windowWidth < element[0].offsetLeft + element[0].offsetWidth) { + element.css('left', element[0].offsetLeft - element[0].offsetWidth + 'px'); + } + } + function active () { return !!element; } @@ -137,14 +147,12 @@ angular.module('ng-context-menu', []) triggerOnEvent allows for binding the event for opening the menu to "click" */ // prepare locals, these define properties to be passed on to the context menu scope - if (attrs.locals) { - var localKeys = attrs.locals.split(',').map(function(local) { - return local.trim(); - }); - angular.forEach(localKeys, function(key) { - locals[key] = scope[key]; - }); - } + var localKeys = attrs.locals.split(',').map(function(local) { + return local.trim(); + }); + angular.forEach(localKeys, function(key) { + locals[key] = scope[key]; + }); function open(event) { diff --git a/dist/angular-context-menu.min.js b/dist/angular-context-menu.min.js index fc4aa50..7f6f4d2 100644 --- a/dist/angular-context-menu.min.js +++ b/dist/angular-context-menu.min.js @@ -1 +1 @@ -angular.module("ng-context-menu",[]).factory("ngContextMenu",["$q","$http","$compile","$templateCache","$animate","$rootScope","$controller",function(e,t,n,o,r,a,l){return function(c){function i(e,t){return g&&e&&p(e),s.then(function(n){return $||u(n,e),t&&$.css(t),$})}function u(e,t){if(h=angular.element(c.container||document.body),$=angular.element(e),0===$.length)throw new Error("The template contains no elements; you need to wrap text nodes");r.enter($,h),g=a.$new(),t&&p(t);var o=l(v,{$scope:g});d&&(g[d]=o),n($)(g)}function p(e){for(var t in e)g[t]=e[t]}function f(){var t=e.defer();return $?r.leave($,function(){g.$destroy(),$=null,t.resolve()}):t.resolve(),t.promise}function m(){return!!$}if(!(!c.template^!c.templateUrl))throw new Error("Expected context menu to have exacly one of either `template` or `templateUrl`");var s,g,v=(c.template,c.controller||angular.noop),d=c.controllerAs,$=null,h=null;if(c.template){var x=e.defer();x.resolve(c.template),s=x.promise}else s=t.get(c.templateUrl,{cache:o}).then(function(e){return e.data});return{open:i,close:f,active:m}}}]).directive("hasContextMenu",["$injector","$window","$parse",function(e,t){return{restrict:"A",link:function(n,o,r){function a(e){p.open(f,c(e))}function l(){p.close()}function c(e){return{top:Math.max(e.pageY,0)+"px",left:Math.max(e.pageX,0)+"px"}}function i(e){p.active()&&u&&2!==e.button&&n.$apply(function(){l()})}var u,p=e.get(r.target),f={},m=angular.element(t),s=r.triggerOnEvent||"contextmenu";if(r.locals){var g=r.locals.split(",").map(function(e){return e.trim()});angular.forEach(g,function(e){f[e]=n[e]})}o.bind(s,function(e){u=e.target,e.preventDefault(),e.stopPropagation(),n.$apply(function(){a(e)})}),m.bind("keyup",function(e){p.active()&&27===e.keyCode&&n.$apply(function(){l()})}),m.bind("click",i),m.bind(s,i)}}}]); \ No newline at end of file +angular.module("ng-context-menu",[]).factory("ngContextMenu",["$q","$http","$compile","$templateCache","$animate","$rootScope","$controller",function(e,t,n,o,r,i,a){return function(c){function l(e,t){return h&&e&&u(e),d.then(function(n){return w||f(n,e),t&&w.css(t),s(w),w})}function f(e,t){if($=angular.element(c.container||document.body),w=angular.element(e),0===w.length)throw new Error("The template contains no elements; you need to wrap text nodes");r.enter(w,$),h=i.$new(),t&&u(t);var o=a(g,{$scope:h});v&&(h[v]=o),n(w)(h)}function u(e){for(var t in e)h[t]=e[t]}function p(){var t=e.defer();return w?r.leave(w,function(){h.$destroy(),w=null,t.resolve()}):t.resolve(),t.promise}function s(e){var t="innerHeight"in window?window.innerHeight:document.documentElement.offsetHeight,n="innerWidth"in window?window.innerWidth:document.documentElement.offsetWidth;t Date: Mon, 6 Jul 2015 10:40:46 +0200 Subject: [PATCH 2/9] Reverted one unintended change --- dist/angular-context-menu.js | 14 ++++++++------ dist/angular-context-menu.min.js | 2 +- src/angular-context-menu.js | 14 ++++++++------ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/dist/angular-context-menu.js b/dist/angular-context-menu.js index af243d9..af01943 100644 --- a/dist/angular-context-menu.js +++ b/dist/angular-context-menu.js @@ -147,12 +147,14 @@ angular.module('ng-context-menu', []) triggerOnEvent allows for binding the event for opening the menu to "click" */ // prepare locals, these define properties to be passed on to the context menu scope - var localKeys = attrs.locals.split(',').map(function(local) { - return local.trim(); - }); - angular.forEach(localKeys, function(key) { - locals[key] = scope[key]; - }); + if (attrs.locals) { + var localKeys = attrs.locals.split(',').map(function(local) { + return local.trim(); + }); + angular.forEach(localKeys, function(key) { + locals[key] = scope[key]; + }); + } function open(event) { diff --git a/dist/angular-context-menu.min.js b/dist/angular-context-menu.min.js index 7f6f4d2..19bc7cc 100644 --- a/dist/angular-context-menu.min.js +++ b/dist/angular-context-menu.min.js @@ -1 +1 @@ -angular.module("ng-context-menu",[]).factory("ngContextMenu",["$q","$http","$compile","$templateCache","$animate","$rootScope","$controller",function(e,t,n,o,r,i,a){return function(c){function l(e,t){return h&&e&&u(e),d.then(function(n){return w||f(n,e),t&&w.css(t),s(w),w})}function f(e,t){if($=angular.element(c.container||document.body),w=angular.element(e),0===w.length)throw new Error("The template contains no elements; you need to wrap text nodes");r.enter(w,$),h=i.$new(),t&&u(t);var o=a(g,{$scope:h});v&&(h[v]=o),n(w)(h)}function u(e){for(var t in e)h[t]=e[t]}function p(){var t=e.defer();return w?r.leave(w,function(){h.$destroy(),w=null,t.resolve()}):t.resolve(),t.promise}function s(e){var t="innerHeight"in window?window.innerHeight:document.documentElement.offsetHeight,n="innerWidth"in window?window.innerWidth:document.documentElement.offsetWidth;t Date: Mon, 6 Jul 2015 10:46:11 +0200 Subject: [PATCH 3/9] Incremented version in required files --- bower.json | 5 +++-- dist/angular-context-menu.js | 2 +- package.json | 4 ++-- src/angular-context-menu.js | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/bower.json b/bower.json index e486af6..771f811 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-context-menu", - "version": "0.1.2", + "version": "0.1.3", "description": "An AngularJS directive to set up and open a context menu when a right-click or click event is triggered", "keywords": [ "angular-context-menu", @@ -12,7 +12,8 @@ "authors": [ "Ian Kennington Walter (http://ianvonwalter.com)", "Briant Ford", - "Till Breuer (https://github.com/tilt)" + "Till Breuer (https://github.com/tilt)", + "Gelu Timoficiuc (https://github.com/tgelu)" ], "license": "MIT", "main": [ diff --git a/dist/angular-context-menu.js b/dist/angular-context-menu.js index af01943..bbfe203 100644 --- a/dist/angular-context-menu.js +++ b/dist/angular-context-menu.js @@ -1,6 +1,6 @@ /** * @license - * angular-context-menu - v0.1.2 - An AngularJS directive to display a context menu + * angular-context-menu - v0.1.3 - An AngularJS directive to display a context menu * (c) 2014 * License: MIT * diff --git a/package.json b/package.json index ff1ec94..7fedbfc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-context-menu", - "version": "0.1.1", + "version": "0.1.2", "description": "An AngularJS directive to display a context menu when a right-click event is triggered", "main": "dist/angular-context-menu.min.js", "devDependencies": { @@ -20,6 +20,6 @@ "angularjs", "angular" ], - "authors": "Ian Kennington Walter (http://ianvonwalter.com), Briant Ford, Till Breuer (https://github.com/tilt)", + "authors": "Ian Kennington Walter (http://ianvonwalter.com), Briant Ford, Till Breuer (https://github.com/tilt), Gelu Timoficiuc (https://github.com/tgelu)", "license": "MIT" } diff --git a/src/angular-context-menu.js b/src/angular-context-menu.js index af01943..bbfe203 100644 --- a/src/angular-context-menu.js +++ b/src/angular-context-menu.js @@ -1,6 +1,6 @@ /** * @license - * angular-context-menu - v0.1.2 - An AngularJS directive to display a context menu + * angular-context-menu - v0.1.3 - An AngularJS directive to display a context menu * (c) 2014 * License: MIT * From 94580bdd6478bd03af36392a739a3d799a8620d6 Mon Sep 17 00:00:00 2001 From: Gelu Timoficiuc Date: Wed, 29 Jul 2015 15:11:13 +0200 Subject: [PATCH 4/9] Use of mousedown instead of click To increase the user experience when using a complex UI together with this context menu. This way ther will be no "hanging" menus around --- dist/angular-context-menu.js | 2 +- dist/angular-context-menu.min.js | 2 +- src/angular-context-menu.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/angular-context-menu.js b/dist/angular-context-menu.js index bbfe203..8925e26 100644 --- a/dist/angular-context-menu.js +++ b/dist/angular-context-menu.js @@ -202,7 +202,7 @@ angular.module('ng-context-menu', []) // Firefox treats a right-click as a click and a contextmenu event while other browsers // just treat it as a contextmenu event - win.bind('click', handleWindowClickEvent); + win.bind('mousedown', handleWindowClickEvent); win.bind(triggerOnEvent, handleWindowClickEvent); } }; diff --git a/dist/angular-context-menu.min.js b/dist/angular-context-menu.min.js index 19bc7cc..9528eee 100644 --- a/dist/angular-context-menu.min.js +++ b/dist/angular-context-menu.min.js @@ -1 +1 @@ -angular.module("ng-context-menu",[]).factory("ngContextMenu",["$q","$http","$compile","$templateCache","$animate","$rootScope","$controller",function(e,t,n,o,r,i,a){return function(c){function l(e,t){return h&&e&&u(e),d.then(function(n){return w||f(n,e),t&&w.css(t),s(w),w})}function f(e,t){if($=angular.element(c.container||document.body),w=angular.element(e),0===w.length)throw new Error("The template contains no elements; you need to wrap text nodes");r.enter(w,$),h=i.$new(),t&&u(t);var o=a(g,{$scope:h});v&&(h[v]=o),n(w)(h)}function u(e){for(var t in e)h[t]=e[t]}function p(){var t=e.defer();return w?r.leave(w,function(){h.$destroy(),w=null,t.resolve()}):t.resolve(),t.promise}function s(e){var t="innerHeight"in window?window.innerHeight:document.documentElement.offsetHeight,n="innerWidth"in window?window.innerWidth:document.documentElement.offsetWidth;t Date: Wed, 29 Jul 2015 15:14:09 +0200 Subject: [PATCH 5/9] Incremented necessary versions --- bower.json | 2 +- package.json | 2 +- src/angular-context-menu.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bower.json b/bower.json index 771f811..d6972e8 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-context-menu", - "version": "0.1.3", + "version": "0.1.4", "description": "An AngularJS directive to set up and open a context menu when a right-click or click event is triggered", "keywords": [ "angular-context-menu", diff --git a/package.json b/package.json index 7fedbfc..f3c8909 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-context-menu", - "version": "0.1.2", + "version": "0.1.4", "description": "An AngularJS directive to display a context menu when a right-click event is triggered", "main": "dist/angular-context-menu.min.js", "devDependencies": { diff --git a/src/angular-context-menu.js b/src/angular-context-menu.js index 8925e26..311d026 100644 --- a/src/angular-context-menu.js +++ b/src/angular-context-menu.js @@ -1,10 +1,10 @@ /** * @license - * angular-context-menu - v0.1.3 - An AngularJS directive to display a context menu + * angular-context-menu - v0.1.4 - An AngularJS directive to display a context menu * (c) 2014 * License: MIT * - * @authors Brian Ford (http://briantford.com), Ian Kennington Walter (http://ianvonwalter.com), Till Breuer (https://github.com/tilt) + * @authors Brian Ford (http://briantford.com), Ian Kennington Walter (http://ianvonwalter.com), Till Breuer (https://github.com/tilt), Gelu Timoficiuc (https://github.com/tgelu) */ angular.module('ng-context-menu', []) From a122c17c2116bae84c59d959c5335c0666cc1aaa Mon Sep 17 00:00:00 2001 From: Gelu Timoficiuc Date: Wed, 5 Aug 2015 13:58:06 +0200 Subject: [PATCH 6/9] Fixed two Ie8 issues --- dist/angular-context-menu.js | 22 ++++++++++++++-------- dist/angular-context-menu.min.js | 2 +- src/angular-context-menu.js | 18 ++++++++++++------ 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/dist/angular-context-menu.js b/dist/angular-context-menu.js index 8925e26..4e83721 100644 --- a/dist/angular-context-menu.js +++ b/dist/angular-context-menu.js @@ -1,10 +1,10 @@ /** * @license - * angular-context-menu - v0.1.3 - An AngularJS directive to display a context menu + * angular-context-menu - v0.1.4 - An AngularJS directive to display a context menu * (c) 2014 * License: MIT * - * @authors Brian Ford (http://briantford.com), Ian Kennington Walter (http://ianvonwalter.com), Till Breuer (https://github.com/tilt) + * @authors Brian Ford (http://briantford.com), Ian Kennington Walter (http://ianvonwalter.com), Till Breuer (https://github.com/tilt), Gelu Timoficiuc (https://github.com/tgelu) */ angular.module('ng-context-menu', []) @@ -148,10 +148,9 @@ angular.module('ng-context-menu', []) // prepare locals, these define properties to be passed on to the context menu scope if (attrs.locals) { - var localKeys = attrs.locals.split(',').map(function(local) { - return local.trim(); - }); + var localKeys = attrs.locals.split(','); angular.forEach(localKeys, function(key) { + key = key.trim(); locals[key] = scope[key]; }); } @@ -167,9 +166,16 @@ angular.module('ng-context-menu', []) } function getCssPositionProperties(event) { + if (event.pageX || event.pageY) { + clickX = event.pageX; + clickY = event.pageY; + } else { + clickX = event.clientX + document.documentElement.scrollLeft; + clickY = event.clientY + document.documentElement.scrollTop; + } return { - top: Math.max(event.pageY, 0) + 'px', - left: Math.max(event.pageX, 0) + 'px' + left: Math.max(clickX, 0) + 'px', + top: Math.max(clickY, 0) + 'px' }; } @@ -202,7 +208,7 @@ angular.module('ng-context-menu', []) // Firefox treats a right-click as a click and a contextmenu event while other browsers // just treat it as a contextmenu event - win.bind('mousedown', handleWindowClickEvent); + win.bind('click', handleWindowClickEvent); win.bind(triggerOnEvent, handleWindowClickEvent); } }; diff --git a/dist/angular-context-menu.min.js b/dist/angular-context-menu.min.js index 9528eee..88ff79a 100644 --- a/dist/angular-context-menu.min.js +++ b/dist/angular-context-menu.min.js @@ -1 +1 @@ -angular.module("ng-context-menu",[]).factory("ngContextMenu",["$q","$http","$compile","$templateCache","$animate","$rootScope","$controller",function(e,t,n,o,r,i,a){return function(c){function l(e,t){return h&&e&&u(e),d.then(function(n){return w||f(n,e),t&&w.css(t),s(w),w})}function f(e,t){if($=angular.element(c.container||document.body),w=angular.element(e),0===w.length)throw new Error("The template contains no elements; you need to wrap text nodes");r.enter(w,$),h=i.$new(),t&&u(t);var o=a(g,{$scope:h});v&&(h[v]=o),n(w)(h)}function u(e){for(var t in e)h[t]=e[t]}function p(){var t=e.defer();return w?r.leave(w,function(){h.$destroy(),w=null,t.resolve()}):t.resolve(),t.promise}function s(e){var t="innerHeight"in window?window.innerHeight:document.documentElement.offsetHeight,n="innerWidth"in window?window.innerWidth:document.documentElement.offsetWidth;t Date: Wed, 5 Aug 2015 14:12:07 +0200 Subject: [PATCH 7/9] Avoid binding mouseevents on the window object As it is not supported in IE8 --- dist/angular-context-menu.js | 12 ++++++------ dist/angular-context-menu.min.js | 2 +- src/angular-context-menu.js | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/dist/angular-context-menu.js b/dist/angular-context-menu.js index 4e83721..fa448b5 100644 --- a/dist/angular-context-menu.js +++ b/dist/angular-context-menu.js @@ -129,16 +129,16 @@ angular.module('ng-context-menu', []) .directive('hasContextMenu', [ '$injector', - '$window', + '$document', '$parse', - function($injector, $window, $parse) { + function($injector, $document, $parse) { return { restrict: 'A', link: function(scope, element, attrs) { var openTarget, contextMenu = $injector.get(attrs.target), locals = {}, - win = angular.element($window), + doc = angular.element($document), menuElement, triggerOnEvent = attrs.triggerOnEvent || 'contextmenu'; @@ -189,7 +189,7 @@ angular.module('ng-context-menu', []) }); }); - win.bind('keyup', function(event) { + doc.bind('keyup', function(event) { if (contextMenu.active() && event.keyCode === 27) { scope.$apply(function() { close(); @@ -208,8 +208,8 @@ angular.module('ng-context-menu', []) // Firefox treats a right-click as a click and a contextmenu event while other browsers // just treat it as a contextmenu event - win.bind('click', handleWindowClickEvent); - win.bind(triggerOnEvent, handleWindowClickEvent); + doc.bind('click', handleWindowClickEvent); + doc.bind(triggerOnEvent, handleWindowClickEvent); } }; }]); diff --git a/dist/angular-context-menu.min.js b/dist/angular-context-menu.min.js index 88ff79a..456e4db 100644 --- a/dist/angular-context-menu.min.js +++ b/dist/angular-context-menu.min.js @@ -1 +1 @@ -angular.module("ng-context-menu",[]).factory("ngContextMenu",["$q","$http","$compile","$templateCache","$animate","$rootScope","$controller",function(e,t,n,o,r,c,i){return function(l){function a(e,t){return g&&e&&f(e),d.then(function(n){return w||u(n,e),t&&w.css(t),s(w),w})}function u(e,t){if($=angular.element(l.container||document.body),w=angular.element(e),0===w.length)throw new Error("The template contains no elements; you need to wrap text nodes");r.enter(w,$),g=c.$new(),t&&f(t);var o=i(h,{$scope:g});v&&(g[v]=o),n(w)(g)}function f(e){for(var t in e)g[t]=e[t]}function p(){var t=e.defer();return w?r.leave(w,function(){g.$destroy(),w=null,t.resolve()}):t.resolve(),t.promise}function s(e){var t="innerHeight"in window?window.innerHeight:document.documentElement.offsetHeight,n="innerWidth"in window?window.innerWidth:document.documentElement.offsetWidth;t Date: Wed, 5 Aug 2015 14:13:34 +0200 Subject: [PATCH 8/9] Incremented necessary version for the IE8 working release --- bower.json | 2 +- dist/angular-context-menu.js | 2 +- package.json | 2 +- src/angular-context-menu.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bower.json b/bower.json index d6972e8..ecc119b 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-context-menu", - "version": "0.1.4", + "version": "0.1.5", "description": "An AngularJS directive to set up and open a context menu when a right-click or click event is triggered", "keywords": [ "angular-context-menu", diff --git a/dist/angular-context-menu.js b/dist/angular-context-menu.js index fa448b5..95f6aba 100644 --- a/dist/angular-context-menu.js +++ b/dist/angular-context-menu.js @@ -1,6 +1,6 @@ /** * @license - * angular-context-menu - v0.1.4 - An AngularJS directive to display a context menu + * angular-context-menu - v0.1.5 - An AngularJS directive to display a context menu * (c) 2014 * License: MIT * diff --git a/package.json b/package.json index f3c8909..e0e9017 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-context-menu", - "version": "0.1.4", + "version": "0.1.5", "description": "An AngularJS directive to display a context menu when a right-click event is triggered", "main": "dist/angular-context-menu.min.js", "devDependencies": { diff --git a/src/angular-context-menu.js b/src/angular-context-menu.js index fa448b5..95f6aba 100644 --- a/src/angular-context-menu.js +++ b/src/angular-context-menu.js @@ -1,6 +1,6 @@ /** * @license - * angular-context-menu - v0.1.4 - An AngularJS directive to display a context menu + * angular-context-menu - v0.1.5 - An AngularJS directive to display a context menu * (c) 2014 * License: MIT * From 8d82dcb7b974e097f4744bdba8874c3946825d58 Mon Sep 17 00:00:00 2001 From: Gelu Timoficiuc Date: Thu, 6 Aug 2015 14:31:29 +0200 Subject: [PATCH 9/9] Bugfixed the contextMenu adjust position function The issue was that if the template of the context menu would affect the width/height of it, then positioning would not know about this until after the first rendering. --- bower.json | 2 +- dist/angular-context-menu.js | 19 +++++++++++-------- dist/angular-context-menu.min.js | 2 +- package.json | 2 +- src/angular-context-menu.js | 19 +++++++++++-------- 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/bower.json b/bower.json index ecc119b..20a1886 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-context-menu", - "version": "0.1.5", + "version": "0.1.6", "description": "An AngularJS directive to set up and open a context menu when a right-click or click event is triggered", "keywords": [ "angular-context-menu", diff --git a/dist/angular-context-menu.js b/dist/angular-context-menu.js index 95f6aba..ed0383a 100644 --- a/dist/angular-context-menu.js +++ b/dist/angular-context-menu.js @@ -1,6 +1,6 @@ /** * @license - * angular-context-menu - v0.1.5 - An AngularJS directive to display a context menu + * angular-context-menu - v0.1.6 - An AngularJS directive to display a context menu * (c) 2014 * License: MIT * @@ -12,12 +12,13 @@ angular.module('ng-context-menu', []) .factory('ngContextMenu', [ '$q', '$http', + '$timeout', '$compile', '$templateCache', '$animate', '$rootScope', '$controller', - function($q, $http, $compile, $templateCache, $animate, $rootScope, $controller) { + function($q, $http, $timeout, $compile, $templateCache, $animate, $rootScope, $controller) { return function contextMenuFactory(config) { if (!(!config.template ^ !config.templateUrl)) { @@ -106,12 +107,14 @@ angular.module('ng-context-menu', []) function adjustPosition(element) { var windowHeight = 'innerHeight' in window ? window.innerHeight : document.documentElement.offsetHeight; var windowWidth = 'innerWidth' in window ? window.innerWidth : document.documentElement.offsetWidth; - if (windowHeight < element[0].offsetTop + element[0].offsetHeight) { - element.css('top', element[0].offsetTop - element[0].offsetHeight + 'px'); - } - if (windowWidth < element[0].offsetLeft + element[0].offsetWidth) { - element.css('left', element[0].offsetLeft - element[0].offsetWidth + 'px'); - } + $timeout(function() { + if (windowHeight < element[0].offsetTop + element[0].offsetHeight) { + element.css('top', element[0].offsetTop - element[0].offsetHeight + 'px'); + } + if (windowWidth < element[0].offsetLeft + element[0].offsetWidth) { + element.css('left', element[0].offsetLeft - element[0].offsetWidth + 'px'); + } + }, 0); } function active () { diff --git a/dist/angular-context-menu.min.js b/dist/angular-context-menu.min.js index 456e4db..c37ddfc 100644 --- a/dist/angular-context-menu.min.js +++ b/dist/angular-context-menu.min.js @@ -1 +1 @@ -angular.module("ng-context-menu",[]).factory("ngContextMenu",["$q","$http","$compile","$templateCache","$animate","$rootScope","$controller",function(e,t,n,o,r,c,i){return function(l){function a(e,t){return g&&e&&f(e),d.then(function(n){return $||u(n,e),t&&$.css(t),m($),$})}function u(e,t){if(w=angular.element(l.container||document.body),$=angular.element(e),0===$.length)throw new Error("The template contains no elements; you need to wrap text nodes");r.enter($,w),g=c.$new(),t&&f(t);var o=i(h,{$scope:g});v&&(g[v]=o),n($)(g)}function f(e){for(var t in e)g[t]=e[t]}function p(){var t=e.defer();return $?r.leave($,function(){g.$destroy(),$=null,t.resolve()}):t.resolve(),t.promise}function m(e){var t="innerHeight"in window?window.innerHeight:document.documentElement.offsetHeight,n="innerWidth"in window?window.innerWidth:document.documentElement.offsetWidth;t