function click()

in modules/ui/fields/restrictions.js [313:402]


        function click(d3_event) {
            surface
                .call(breathe.off)
                .call(breathe);

            var datum = d3_event.target.__data__;
            var entity = datum && datum.properties && datum.properties.entity;
            if (entity) {
                datum = entity;
            }

            if (datum instanceof osmWay && (datum.__from || datum.__via)) {
                _fromWayID = datum.id;
                _oldTurns = null;
                redraw();

            } else if (datum instanceof osmTurn) {
                var actions, extraActions, turns, i;
                var restrictionType = osmInferRestriction(vgraph, datum, projection);

                if (datum.restrictionID && !datum.direct) {
                    return;

                } else if (datum.restrictionID && !datum.only) {    // NO -> ONLY
                    var seen = {};
                    var datumOnly = JSON.parse(JSON.stringify(datum));   // deep clone the datum
                    datumOnly.only = true;                               // but change this property
                    restrictionType = restrictionType.replace(/^no/, 'only');

                    // Adding an ONLY restriction should destroy all other direct restrictions from the FROM towards the VIA.
                    // We will remember them in _oldTurns, and restore them if the user clicks again.
                    turns = _intersection.turns(_fromWayID, 2);
                    extraActions = [];
                    _oldTurns = [];
                    for (i = 0; i < turns.length; i++) {
                        var turn = turns[i];
                        if (seen[turn.restrictionID]) continue;  // avoid deleting the turn twice (#4968, #4928)

                        if (turn.direct && turn.path[1] === datum.path[1]) {
                            seen[turns[i].restrictionID] = true;
                            turn.restrictionType = osmInferRestriction(vgraph, turn, projection);
                            _oldTurns.push(turn);
                            extraActions.push(actionUnrestrictTurn(turn));
                        }
                    }

                    actions = _intersection.actions.concat(extraActions, [
                        actionRestrictTurn(datumOnly, restrictionType),
                        t('operations.restriction.annotation.create')
                    ]);

                } else if (datum.restrictionID) {   // ONLY -> Allowed
                    // Restore whatever restrictions we might have destroyed by cycling thru the ONLY state.
                    // This relies on the assumption that the intersection was already split up when we
                    // performed the previous action (NO -> ONLY), so the IDs in _oldTurns shouldn't have changed.
                    turns = _oldTurns || [];
                    extraActions = [];
                    for (i = 0; i < turns.length; i++) {
                        if (turns[i].key !== datum.key) {
                            extraActions.push(actionRestrictTurn(turns[i], turns[i].restrictionType));
                        }
                    }
                    _oldTurns = null;

                    actions = _intersection.actions.concat(extraActions, [
                        actionUnrestrictTurn(datum),
                        t('operations.restriction.annotation.delete')
                    ]);

                } else {    // Allowed -> NO
                    actions = _intersection.actions.concat([
                        actionRestrictTurn(datum, restrictionType),
                        t('operations.restriction.annotation.create')
                    ]);
                }

                context.perform.apply(context, actions);

                // At this point the datum will be changed, but will have same key..
                // Refresh it and update the help..
                var s = surface.selectAll('.' + datum.key);
                datum = s.empty() ? null : s.datum();
                updateHints(datum);

            } else {
                _fromWayID = null;
                _oldTurns = null;
                redraw();
            }
        }