mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-21 07:46:58 +02:00
Escape actions with the escape key
This commit is contained in:
@@ -83,8 +83,6 @@
|
||||
});
|
||||
}
|
||||
|
||||
for (var a in iD.actions) iD.actions[a].bind();
|
||||
|
||||
d3.select('#geocode-form').on('submit', function() {
|
||||
d3.event.preventDefault();
|
||||
var val = d3.select('#geocode-location').node().value;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
iD.actions = {};
|
||||
|
||||
iD.actions.AddPlace = {
|
||||
bind: function() {
|
||||
bind: function(controller) {
|
||||
this.controller = controller;
|
||||
d3.selectAll('button#place').on('click', function() {
|
||||
iD.actions.AddPlace.enter();
|
||||
});
|
||||
@@ -19,7 +20,8 @@ iD.actions.AddPlace = {
|
||||
};
|
||||
|
||||
iD.actions.AddRoad = {
|
||||
bind: function() {
|
||||
bind: function(controller) {
|
||||
this.controller = controller;
|
||||
d3.selectAll('button#road').on('click', function() {
|
||||
iD.actions.AddRoad.enter();
|
||||
});
|
||||
@@ -37,7 +39,8 @@ iD.actions.AddRoad = {
|
||||
};
|
||||
|
||||
iD.actions.AddArea = {
|
||||
bind: function() {
|
||||
bind: function(controller) {
|
||||
this.controller = controller;
|
||||
d3.selectAll('button#area').on('click', function() {
|
||||
iD.actions.AddArea.enter();
|
||||
});
|
||||
@@ -53,3 +56,40 @@ iD.actions.AddArea = {
|
||||
d3.selectAll('button#area').classed('active', false);
|
||||
}
|
||||
};
|
||||
|
||||
iD.actions.Move = {
|
||||
bind: function(controller) {
|
||||
this.controller = controller;
|
||||
},
|
||||
enter: function() {
|
||||
d3.selectAll('button').classed('active', false);
|
||||
},
|
||||
exit: function() { }
|
||||
};
|
||||
|
||||
iD.controller = (function() {
|
||||
var controller = {},
|
||||
action;
|
||||
|
||||
for (var a in iD.actions) iD.actions[a].bind(controller);
|
||||
|
||||
controller.go = function(x) {
|
||||
if (action) {
|
||||
action.exit();
|
||||
}
|
||||
x.enter();
|
||||
action = x;
|
||||
};
|
||||
|
||||
controller.go(iD.actions.Move);
|
||||
|
||||
// Pressing 'escape' should exit any action.
|
||||
d3.select(document).on('keydown', function() {
|
||||
if (d3.event.keyCode === 27) {
|
||||
iD.controller.go(iD.actions.Move);
|
||||
}
|
||||
});
|
||||
|
||||
return controller;
|
||||
})();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user