Skip to content

Commit 50257ba

Browse files
committed
Fixing #32 and #33
1 parent 616d3c6 commit 50257ba

7 files changed

Lines changed: 149 additions & 112 deletions

File tree

.jshintrc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"browser": true,
3+
"jquery": true,
4+
"node": true,
5+
"camelcase": true,
6+
"eqeqeq": true,
7+
"indent": 2,
8+
"latedef": true,
9+
"maxlen": 80,
10+
"newcap": true,
11+
"quotmark": "single",
12+
"strict": true,
13+
"undef": true,
14+
"unused": true,
15+
"eqnull": true,
16+
"predef": ["angular"]
17+
}

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ng-context-menu",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "An AngularJS directive to display a context menu when a right-click event is triggered",
55
"keywords": [
66
"ng-context-menu",

dist/ng-context-menu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* ng-context-menu - v1.0.0 - An AngularJS directive to display a context menu
2+
* ng-context-menu - v1.0.1 - An AngularJS directive to display a context menu
33
* when a right-click event is triggered
44
*
55
* @author Ian Kennington Walter (http://ianvonwalter.com)

gulpfile.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,29 @@ var gulp = require('gulp'),
55
rename = require('gulp-rename'),
66
connect = require('gulp-connect'),
77
protractor = require("gulp-protractor").protractor,
8+
program = require('commander'),
9+
stylish = require('jshint-stylish'),
810
debug = false,
911
WATCH_MODE = 'watch',
1012
RUN_MODE = 'run';
1113

1214
var mode = RUN_MODE;
1315

16+
function list(val) {
17+
return val.split(',');
18+
}
19+
20+
program
21+
.version('0.0.1')
22+
.option('-t, --tests [glob]', 'Specify which tests to run')
23+
.option('-b, --browsers <items>', 'Specify which browsers to run on', list)
24+
.option('-r, --reporters <items>', 'Specify which reporters to use', list)
25+
.parse(process.argv);
26+
1427
gulp.task('lint', function () {
1528
gulp.src('src/**/*.js')
16-
.pipe(jshint())
17-
.pipe(jshint.reporter('default'));
29+
.pipe(jshint('.jshintrc'))
30+
.pipe(jshint.reporter(stylish));
1831
});
1932

2033
gulp.task('js', function() {
@@ -47,7 +60,10 @@ gulp.task('protractor', function(done) {
4760
gulp.src(["./src/tests/*.js"])
4861
.pipe(protractor({
4962
configFile: 'protractor.conf.js',
50-
args: ['--baseUrl', 'http://127.0.0.1:8080']
63+
args: [
64+
'--baseUrl', 'http://127.0.0.1:8080',
65+
'--browser', program.browsers ? program.browsers[0] : 'phantomjs'
66+
]
5167
}))
5268
.on('end', function() {
5369
if (mode === RUN_MODE) {
@@ -82,6 +98,7 @@ function watch() {
8298
}
8399

84100
// Removing protractor from default task until phantomjs issue is fixed
101+
// https://github.com/ariya/phantomjs/issues/11429
85102
//gulp.task('default', ['watch-mode', 'js', 'lint', 'protractor'], watch);
86103
gulp.task('default', ['watch-mode', 'js', 'lint'], watch);
87104
gulp.task('server', ['connect', 'default']);

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
{
22
"name": "ng-context-menu",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "An AngularJS directive to display a context menu when a right-click event is triggered",
55
"main": "index.html",
66
"devDependencies": {
7+
"commander": "^2.3.0",
78
"gulp": "~3.5.1",
89
"gulp-concat": "~2.1.7",
910
"gulp-connect": "^2.0.5",
1011
"gulp-jshint": "~1.3.4",
12+
"gulp-protractor": "0.0.11",
1113
"gulp-rename": "~0.2.2",
14+
"gulp-selenium": "0.0.3",
1215
"gulp-uglify": "~0.2.0",
13-
"protractor": "^1.2.0",
14-
"gulp-protractor": "0.0.11",
15-
"gulp-selenium": "0.0.3"
16+
"jshint-stylish": "^1.0.0",
17+
"protractor": "^1.2.0"
1618
},
1719
"scripts": {
1820
"test": "gulp test"

protractor.conf.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ exports.config = {
66
chromeDriver: gulpSelenium.chromeDriverPath,
77
//seleniumAddress: 'http://localhost:4444/wd/hub', // Using JAR instead of address
88
capabilities: {
9-
//'browserName': 'phantomjs', // Can't use phantomjs until this is fixed
10-
// https://github.com/detro/ghostdriver/issues/125
11-
'browserName': 'firefox'
12-
//'browserName': 'chrome'
9+
'browserName': 'phantomjs'
1310
},
1411
specs: ['test/ui/**/*.spec.js']
1512
};

src/ng-context-menu.js

Lines changed: 103 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,130 @@
11
/**
2-
* ng-context-menu - v1.0.0 - An AngularJS directive to display a context menu
2+
* ng-context-menu - v1.0.1 - An AngularJS directive to display a context menu
33
* when a right-click event is triggered
44
*
55
* @author Ian Kennington Walter (http://ianvonwalter.com)
66
*/
7-
angular
8-
.module('ng-context-menu', [])
9-
.factory('ContextMenuService', function() {
10-
return {
11-
element: null,
12-
menuElement: null
13-
};
14-
})
15-
.directive('contextMenu', [
16-
'$document',
17-
'ContextMenuService',
18-
function($document, ContextMenuService) {
7+
(function(angular) {
8+
'use strict';
9+
10+
angular
11+
.module('ng-context-menu', [])
12+
.factory('ContextMenuService', function() {
1913
return {
20-
restrict: 'A',
21-
scope: {
22-
'callback': '&contextMenu',
23-
'disabled': '&contextMenuDisabled',
24-
'closeCallback': '&contextMenuClose'
25-
},
26-
link: function($scope, $element, $attrs) {
27-
var opened = false;
14+
element: null,
15+
menuElement: null
16+
};
17+
})
18+
.directive('contextMenu', [
19+
'$document',
20+
'ContextMenuService',
21+
function($document, ContextMenuService) {
22+
return {
23+
restrict: 'A',
24+
scope: {
25+
'callback': '&contextMenu',
26+
'disabled': '&contextMenuDisabled',
27+
'closeCallback': '&contextMenuClose'
28+
},
29+
link: function($scope, $element, $attrs) {
30+
var opened = false;
2831

29-
function open(event, menuElement) {
30-
menuElement.addClass('open');
32+
function open(event, menuElement) {
33+
menuElement.addClass('open');
3134

32-
var doc = $document[0].documentElement;
33-
var docLeft = (window.pageXOffset || doc.scrollLeft) -
34-
(doc.clientLeft || 0),
35+
var doc = $document[0].documentElement;
36+
var docLeft = (window.pageXOffset || doc.scrollLeft) -
37+
(doc.clientLeft || 0),
3538
docTop = (window.pageYOffset || doc.scrollTop) -
36-
(doc.clientTop || 0),
39+
(doc.clientTop || 0),
3740
elementWidth = menuElement[0].scrollWidth,
3841
elementHeight = menuElement[0].scrollHeight;
39-
var docWidth = doc.clientWidth + docLeft,
40-
docHeight = doc.clientHeight + docTop,
41-
totalWidth = elementWidth + event.pageX,
42-
totalHeight = elementHeight + event.pageY,
43-
left = Math.max(event.pageX - docLeft, 0),
44-
top = Math.max(event.pageY - docTop, 0);
42+
var docWidth = doc.clientWidth + docLeft,
43+
docHeight = doc.clientHeight + docTop,
44+
totalWidth = elementWidth + event.pageX,
45+
totalHeight = elementHeight + event.pageY,
46+
left = Math.max(event.pageX - docLeft, 0),
47+
top = Math.max(event.pageY - docTop, 0);
4548

46-
if (totalWidth > docWidth) {
47-
left = left - (totalWidth - docWidth);
48-
}
49+
if (totalWidth > docWidth) {
50+
left = left - (totalWidth - docWidth);
51+
}
4952

50-
if (totalHeight > docHeight) {
51-
top = top - (totalHeight - docHeight);
53+
if (totalHeight > docHeight) {
54+
top = top - (totalHeight - docHeight);
55+
}
56+
57+
menuElement.css('top', top + 'px');
58+
menuElement.css('left', left + 'px');
59+
opened = true;
5260
}
5361

54-
menuElement.css('top', top + 'px');
55-
menuElement.css('left', left + 'px');
56-
opened = true;
57-
}
62+
function close(menuElement) {
63+
menuElement.removeClass('open');
5864

59-
function close(menuElement) {
60-
menuElement.removeClass('open');
65+
if (opened) {
66+
$scope.closeCallback();
67+
}
6168

62-
if (opened) {
63-
$scope.closeCallback();
69+
opened = false;
6470
}
6571

66-
opened = false;
67-
}
72+
$element.bind('contextmenu', function(event) {
73+
if (!$scope.disabled()) {
74+
if (ContextMenuService.menuElement !== null) {
75+
close(ContextMenuService.menuElement);
76+
}
77+
ContextMenuService.menuElement = angular.element(
78+
document.getElementById($attrs.target)
79+
);
80+
ContextMenuService.element = event.target;
81+
//console.log('set', ContextMenuService.element);
6882

69-
$element.bind('contextmenu', function(event) {
70-
if (!$scope.disabled()) {
71-
if (ContextMenuService.menuElement !== null) {
72-
close(ContextMenuService.menuElement);
83+
event.preventDefault();
84+
event.stopPropagation();
85+
$scope.$apply(function() {
86+
$scope.callback({ $event: event });
87+
});
88+
$scope.$apply(function() {
89+
open(event, ContextMenuService.menuElement);
90+
});
7391
}
74-
ContextMenuService.menuElement = angular.element(
75-
document.getElementById($attrs.target)
76-
);
77-
ContextMenuService.element = event.target;
78-
//console.log('set', ContextMenuService.element);
92+
});
7993

80-
event.preventDefault();
81-
event.stopPropagation();
82-
$scope.$apply(function() {
83-
$scope.callback({ $event: event });
84-
});
85-
$scope.$apply(function() {
86-
open(event, ContextMenuService.menuElement);
87-
});
88-
}
89-
});
90-
91-
function handleKeyUpEvent(event) {
92-
//console.log('keyup');
93-
if (!$scope.disabled() && opened && event.keyCode === 27) {
94-
$scope.$apply(function() {
95-
close(ContextMenuService.menuElement);
96-
});
94+
function handleKeyUpEvent(event) {
95+
//console.log('keyup');
96+
if (!$scope.disabled() && opened && event.keyCode === 27) {
97+
$scope.$apply(function() {
98+
close(ContextMenuService.menuElement);
99+
});
100+
}
97101
}
98-
}
99102

100-
function handleClickEvent(event) {
101-
if (!$scope.disabled() &&
102-
opened &&
103-
(event.button !== 2 ||
104-
event.target !== ContextMenuService.element)) {
105-
$scope.$apply(function() {
106-
close(ContextMenuService.menuElement);
107-
});
103+
function handleClickEvent(event) {
104+
if (!$scope.disabled() &&
105+
opened &&
106+
(event.button !== 2 ||
107+
event.target !== ContextMenuService.element)) {
108+
$scope.$apply(function() {
109+
close(ContextMenuService.menuElement);
110+
});
111+
}
108112
}
109-
}
110113

111-
$document.bind('keyup', handleKeyUpEvent);
112-
// Firefox treats a right-click as a click and a contextmenu event
113-
// while other browsers just treat it as a contextmenu event
114-
$document.bind('click', handleClickEvent);
115-
$document.bind('contextmenu', handleClickEvent);
114+
$document.bind('keyup', handleKeyUpEvent);
115+
// Firefox treats a right-click as a click and a contextmenu event
116+
// while other browsers just treat it as a contextmenu event
117+
$document.bind('click', handleClickEvent);
118+
$document.bind('contextmenu', handleClickEvent);
116119

117-
$scope.$on('$destroy', function() {
118-
//console.log('destroy');
119-
$document.unbind('keyup', handleKeyUpEvent);
120-
$document.unbind('click', handleClickEvent);
121-
$document.unbind('contextmenu', handleClickEvent);
122-
});
123-
}
124-
};
125-
}
126-
]);
120+
$scope.$on('$destroy', function() {
121+
//console.log('destroy');
122+
$document.unbind('keyup', handleKeyUpEvent);
123+
$document.unbind('click', handleClickEvent);
124+
$document.unbind('contextmenu', handleClickEvent);
125+
});
126+
}
127+
};
128+
}
129+
]);
130+
})(angular);

0 commit comments

Comments
 (0)