modularize iD.behavior

This commit is contained in:
Kushan Joshi
2016-06-17 12:52:54 +05:30
parent 46d68bca87
commit 14f0d95e94
19 changed files with 1458 additions and 81 deletions
+5 -14
View File
@@ -44,6 +44,7 @@ $(BUILDJS_TARGETS): $(BUILDJS_SOURCES) build.js
MODULE_TARGETS = \
js/lib/id/actions.js \
js/lib/id/behavior.js \
js/lib/id/core.js \
js/lib/id/geo.js \
js/lib/id/modes.js \
@@ -59,6 +60,10 @@ js/lib/id/actions.js: $(shell find modules/actions -type f)
@rm -f $@
node_modules/.bin/rollup -f umd -n iD.actions modules/actions/index.js --no-strict -o $@
js/lib/id/behavior.js: $(shell find modules/behavior -type f)
@rm -f $@
node_modules/.bin/rollup -f umd -n iD.behavior modules/behavior/index.js --no-strict -o $@
js/lib/id/core.js: $(shell find modules/core -type f)
@rm -f $@
node_modules/.bin/rollup -f umd -n iD modules/core/index.js --no-strict -o $@
@@ -122,20 +127,6 @@ dist/iD.js: \
js/id/start.js \
js/id/id.js \
$(MODULE_TARGETS) \
js/id/behavior.js \
js/id/behavior/add_way.js \
js/id/behavior/breathe.js \
js/id/behavior/copy.js \
js/id/behavior/drag.js \
js/id/behavior/draw.js \
js/id/behavior/draw_way.js \
js/id/behavior/edit.js \
js/id/behavior/hash.js \
js/id/behavior/hover.js \
js/id/behavior/lasso.js \
js/id/behavior/paste.js \
js/id/behavior/select.js \
js/id/behavior/tail.js \
js/id/ui.js \
js/id/ui/account.js \
js/id/ui/attribution.js \
+1 -15
View File
@@ -35,6 +35,7 @@
<script src='js/id/id.js'></script>
<script src='js/lib/id/actions.js'></script>
<script src='js/lib/id/behavior.js'></script>
<script src='js/lib/id/core.js'></script>
<script src='js/lib/id/geo.js'></script>
<script src='js/lib/id/modes.js'></script>
@@ -117,21 +118,6 @@
<script src='js/id/ui/intro/line.js'></script>
<script src='js/id/ui/intro/start_editing.js'></script>
<script src='js/id/behavior.js'></script>
<script src='js/id/behavior/add_way.js'></script>
<script src='js/id/behavior/breathe.js'></script>
<script src='js/id/behavior/copy.js'></script>
<script src='js/id/behavior/drag.js'></script>
<script src='js/id/behavior/draw.js'></script>
<script src='js/id/behavior/draw_way.js'></script>
<script src='js/id/behavior/edit.js'></script>
<script src='js/id/behavior/hash.js'></script>
<script src='js/id/behavior/hover.js'></script>
<script src='js/id/behavior/lasso.js'></script>
<script src='js/id/behavior/paste.js'></script>
<script src='js/id/behavior/select.js'></script>
<script src='js/id/behavior/tail.js'></script>
<script src='js/lib/locale.js'></script>
<script src='data/introGraph.js'></script>
</head>
-1
View File
@@ -1 +0,0 @@
iD.behavior = {};
File diff suppressed because it is too large Load Diff
@@ -1,6 +1,8 @@
iD.behavior.AddWay = function(context) {
import { Draw } from './draw';
export function AddWay(context) {
var event = d3.dispatch('start', 'startFromWay', 'startFromNode'),
draw = iD.behavior.Draw(context);
draw = Draw(context);
var addWay = function(surface) {
draw.on('click', event.start)
@@ -33,4 +35,4 @@ iD.behavior.AddWay = function(context) {
};
return d3.rebind(addWay, event, 'on');
};
}
@@ -1,4 +1,4 @@
iD.behavior.Breathe = function() {
export function Breathe(){
var duration = 800,
selector = '.selected.shadow, .selected .shadow',
selected = d3.select(null),
@@ -102,4 +102,4 @@ iD.behavior.Breathe = function() {
};
return breathe;
};
}
@@ -1,4 +1,4 @@
iD.behavior.Copy = function(context) {
export function Copy(context) {
var keybinding = d3.keybinding('copy');
function groupEntities(ids, graph) {
@@ -76,4 +76,4 @@ iD.behavior.Copy = function(context) {
};
return copy;
};
}
@@ -14,7 +14,7 @@
* Delegation is supported via the `delegate` function.
*/
iD.behavior.drag = function() {
export function drag() {
function d3_eventCancel() {
d3.event.stopPropagation();
d3.event.preventDefault();
@@ -91,7 +91,7 @@ iD.behavior.drag = function() {
var p = point(),
dx = p[0] - origin_[0],
dy = p[1] - origin_[1];
if (dx === 0 && dy === 0)
return;
@@ -198,4 +198,4 @@ iD.behavior.drag = function() {
};
return d3.rebind(drag, event, 'on');
};
}
@@ -1,17 +1,21 @@
iD.behavior.Draw = function(context) {
import { Edit } from './edit';
import { Hover } from './hover';
import { Tail } from './tail';
export function Draw(context) {
var event = d3.dispatch('move', 'click', 'clickWay',
'clickNode', 'undo', 'cancel', 'finish'),
keybinding = d3.keybinding('draw'),
hover = iD.behavior.Hover(context)
hover = Hover(context)
.altDisables(true)
.on('hover', context.ui().sidebar.hover),
tail = iD.behavior.Tail(),
edit = iD.behavior.Edit(context),
tail = Tail(),
edit = Edit(context),
closeTolerance = 4,
tolerance = 12,
mouseLeave = false,
lastMouse = null,
cached = iD.behavior.Draw;
cached = Draw;
function datum() {
if (d3.event.altKey) return {};
@@ -200,8 +204,8 @@ iD.behavior.Draw = function(context) {
};
return d3.rebind(draw, event, 'on');
};
}
iD.behavior.Draw.usedTails = {};
iD.behavior.Draw.disableSpace = false;
iD.behavior.Draw.lastSpace = null;
Draw.usedTails = {};
Draw.disableSpace = false;
Draw.lastSpace = null;
@@ -1,11 +1,13 @@
iD.behavior.DrawWay = function(context, wayId, index, mode, baseGraph) {
import { Draw } from './draw';
export function DrawWay(context, wayId, index, mode, baseGraph) {
var way = context.entity(wayId),
isArea = context.geometry(wayId) === 'area',
finished = false,
annotation = t((way.isDegenerate() ?
'operations.start.annotation.' :
'operations.continue.annotation.') + context.geometry(wayId)),
draw = iD.behavior.Draw(context);
draw = Draw(context);
var startIndex = typeof index === 'undefined' ? way.nodes.length - 1 : 0,
start = iD.Node({loc: context.graph().entity(way.nodes[startIndex]).loc}),
@@ -207,4 +209,4 @@ iD.behavior.DrawWay = function(context, wayId, index, mode, baseGraph) {
};
return drawWay;
};
}
@@ -1,4 +1,4 @@
iD.behavior.Edit = function(context) {
export function Edit(context) {
function edit() {
context.map()
.minzoom(context.minEditableZoom());
@@ -10,4 +10,4 @@ iD.behavior.Edit = function(context) {
};
return edit;
};
}
@@ -1,4 +1,4 @@
iD.behavior.Hash = function(context) {
export function Hash(context) {
var s0 = null, // cached location.hash
lat = 90 - 1e-8; // allowable latitude range
@@ -89,4 +89,4 @@ iD.behavior.Hash = function(context) {
};
return hash;
};
}
@@ -7,7 +7,7 @@
Only one of these elements can have the :hover pseudo-class, but all of them will
have the .hover class.
*/
iD.behavior.Hover = function() {
export function Hover() {
var dispatch = d3.dispatch('hover'),
selection,
altDisables,
@@ -124,4 +124,4 @@ iD.behavior.Hover = function() {
};
return d3.rebind(hover, dispatch, 'on');
};
}
+13
View File
@@ -0,0 +1,13 @@
export { AddWay } from './add_way';
export { Breathe } from './breathe';
export { Copy } from './copy';
export { drag } from './drag';
export { DrawWay } from './draw_way';
export { Draw } from './draw';
export { Edit } from './edit';
export { Hash } from './hash';
export { Hover } from './hover';
export { Lasso } from './lasso';
export { Paste } from './paste';
export { Select } from './select';
export { Tail } from './tail';
@@ -1,4 +1,4 @@
iD.behavior.Lasso = function(context) {
export function Lasso(context) {
var behavior = function(selection) {
var lasso;
@@ -69,4 +69,4 @@ iD.behavior.Lasso = function(context) {
};
return behavior;
};
}
@@ -1,4 +1,4 @@
iD.behavior.Paste = function(context) {
export function Paste(context) {
var keybinding = d3.keybinding('paste');
function omitTag(v, k) {
@@ -67,4 +67,4 @@ iD.behavior.Paste = function(context) {
};
return paste;
};
}
@@ -1,4 +1,4 @@
iD.behavior.Select = function(context) {
export function Select(context) {
function keydown() {
if (d3.event && d3.event.shiftKey) {
context.surface()
@@ -61,4 +61,4 @@ iD.behavior.Select = function(context) {
};
return behavior;
};
}
@@ -1,4 +1,4 @@
iD.behavior.Tail = function() {
export function Tail() {
var text,
container,
xmargin = 25,
@@ -79,4 +79,4 @@ iD.behavior.Tail = function() {
};
return tail;
};
}
+1 -15
View File
@@ -43,6 +43,7 @@
<script src='../js/id/id.js'></script>
<script src='../js/lib/id/actions.js'></script>
<script src='../js/lib/id/core.js'></script>
<script src='../js/lib/id/behavior.js'></script>
<script src='../js/lib/id/geo.js'></script>
<script src='../js/lib/id/modes.js'></script>
<script src='../js/lib/id/operations.js'></script>
@@ -102,21 +103,6 @@
<script src='../js/id/ui/preset/localized.js'></script>
<script src='../js/id/ui/preset/wikipedia.js'></script>
<script src='../js/id/behavior.js'></script>
<script src='../js/id/behavior/add_way.js'></script>
<script src='../js/id/behavior/breathe.js'></script>
<script src='../js/id/behavior/copy.js'></script>
<script src='../js/id/behavior/drag.js'></script>
<script src='../js/id/behavior/draw.js'></script>
<script src='../js/id/behavior/draw_way.js'></script>
<script src='../js/id/behavior/edit.js'></script>
<script src='../js/id/behavior/hash.js'></script>
<script src='../js/id/behavior/hover.js'></script>
<script src='../js/id/behavior/lasso.js'></script>
<script src='../js/id/behavior/paste.js'></script>
<script src='../js/id/behavior/select.js'></script>
<script src='../js/id/behavior/tail.js'></script>
<script src='../js/lib/locale.js'></script>
<script src='../data/data_dev.js'></script>