示例#1
0
文件: select.js 项目: iandees/iD
        function dblclick() {
            var target = d3_select(d3_event.target);

            var datum = target.datum();
            var entity = datum && datum.properties && datum.properties.entity;
            if (!entity) return;

            if (entity instanceof osmWay && target.classed('target')) {
                var choice = geoChooseEdge(context.childNodes(entity), context.mouse(), context.projection);
                var prev = entity.nodes[choice.index - 1];
                var next = entity.nodes[choice.index];

                context.perform(
                    actionAddMidpoint({loc: choice.loc, edge: [prev, next]}, osmNode()),
                    t('operations.add.annotation.vertex')
                );

                d3_event.preventDefault();
                d3_event.stopPropagation();

            } else if (entity.type === 'midpoint') {
                context.perform(
                    actionAddMidpoint({loc: entity.loc, edge: entity.edge}, osmNode()),
                    t('operations.add.annotation.vertex'));

                d3_event.preventDefault();
                d3_event.stopPropagation();
            }
        }
示例#2
0
            .on('click', function () {
                d3_event.stopPropagation();
                d3_event.preventDefault();
                this.blur();    // avoid keeping focus on the button - #4641

                var container = d3_select(this.parentNode.parentNode.parentNode);
                var info = container.selectAll('.issue-info');
                var isExpanded = info.classed('expanded');

                if (isExpanded) {
                    info
                        .transition()
                        .duration(200)
                        .style('max-height', '0px')
                        .style('opacity', '0')
                        .on('end', function () {
                            info.classed('expanded', false);
                        });
                } else {
                    info
                        .classed('expanded', true)
                        .transition()
                        .duration(200)
                        .style('max-height', '200px')
                        .style('opacity', '1');
                }
            });
    return function(data, index) {
        const elem = this;

        selectAll(".d3-context-menu")
            .html("");
        var list = selectAll(".d3-context-menu")
            .on("contextmenu", function(d) {
                select(".d3-context-menu").style("display", "none");
                event.preventDefault();
                event.stopPropagation();
            })
            .append("ul");

        list.selectAll("li")
            .data(typeof menu === "function" ? menu(data, elem, index) : menu)
            .enter()
            .append("li")
            .classed("is-divider", d => d.divider)
            .classed("is-disabled", d => d.disabled)
            .classed("is-header", d => !d.action)
            .classed("is-action", d => d.action != null)
            .html((d) => {
                if (d.divider) {
                    return "<hr>";
                }
                if (!d.title) {
                    console.error("No title attribute set. Check the spelling of your options.");
                }
                return (typeof d.title === "string") ? d.title : d.title(data);
            })
            .on("click", (d, i) => {
                if (d.disabled) return; // do nothing if disabled
                if (!d.action) return; // headers have no "action"
                const result = d.action(elem, data, index);
                select(".d3-context-menu")
                    .style("display", "none");

                if (closeCallback) {
                    closeCallback(result);
                }
            });

        // the openCallback allows an action to fire before the menu is displayed
        // an example usage would be closing a tooltip
        if (openCallback) {
            if (openCallback(data, index) === false) {
                return;
            }
        }

        // display context menu
        select(".d3-context-menu")
            .style("left", (event.pageX - 2) + "px")
            .style("top", (event.pageY - 2) + "px")
            .style("display", "block");

        event.preventDefault();
        event.stopPropagation();
    };
示例#4
0
文件: welcome.js 项目: Stalfur/iD
 function keydown() {
     if (d3_event.keyCode === 93)  {   // context menu
         d3_event.preventDefault();
         d3_event.stopPropagation();
         down.menu = d3_event.timeStamp;
         tooltip.classed('rightclick', true);
     }
 }
示例#5
0
            .on('click', function () {
                d3_event.stopPropagation();
                d3_event.preventDefault();

                context.presets().toggleFavorite(preset, geom);

                update();
            });
示例#6
0
文件: map_data.js 项目: grischard/iD
 function toggleWireframe() {
     if (d3_event) {
         d3_event.preventDefault();
         d3_event.stopPropagation();
     }
     setFill((fillSelected === 'wireframe' ? fillDefault : 'wireframe'));
     context.map().pan([0,0]);  // trigger a redraw
 }
示例#7
0
 function quickSwitch() {
     if (d3_event) {
         d3_event.stopImmediatePropagation();
         d3_event.preventDefault();
     }
     if (_previousBackground) {
         chooseBackground(_previousBackground);
     }
 }
示例#8
0
文件: background.js 项目: 1ec5/iD
 function quickSwitch() {
     if (d3_event) {
         d3_event.stopImmediatePropagation();
         d3_event.preventDefault();
     }
     if (previous) {
         clickSetSource(previous);
     }
 }
示例#9
0
 .on('click', function () {
     d3_event.stopPropagation();
     d3_event.preventDefault();
     if (_body.classed('hide')) {
         show();
     } else {
         hide();
     }
 });
示例#10
0
文件: check.js 项目: Stalfur/iD
 .on('click', function() {
     d3_event.preventDefault();
     d3_event.stopPropagation();
     context.perform(
         actionReverse(_entityID),
         t('operations.reverse.annotation')
     );
     d3_select(this)
         .call(reverserSetText);
 });
示例#11
0
文件: field.js 项目: 1ec5/iD
    function remove(d) {
        d3_event.stopPropagation();
        d3_event.preventDefault();

        var t = {};
        d.keys.forEach(function(key) {
            t[key] = undefined;
        });

        dispatch.call('change', d, t);
    }
示例#12
0
文件: welcome.js 项目: Stalfur/iD
 function contextmenu() {
     d3_event.preventDefault();
     d3_event.stopPropagation();
     if (!down[2] && !down.menu) {
         tooltip.classed('rightclick', true);
         window.setTimeout(function() {
             tooltip.classed('rightclick', false);
         }, minTime);
         dispatch.call('click', this, 'right');
     }
 }
示例#13
0
 function keydown() {
     // down arrow
     if (d3_event.keyCode === utilKeybinding.keyCodes['↓'] &&
         // if insertion point is at the end of the string
         search.node().selectionStart === search.property('value').length) {
         d3_event.preventDefault();
         d3_event.stopPropagation();
         // move focus to the first item in the preset list
         var buttons = list.selectAll('.preset-list-button');
         if (!buttons.empty()) buttons.nodes()[0].focus();
     }
 }
示例#14
0
文件: d3.combobox.js 项目: Stalfur/iD
 .on('mousedown', function () {
     // prevent the form element from blurring. it blurs
     // on mousedown
     d3_event.stopPropagation();
     d3_event.preventDefault();
     if (!shown) {
         input.node().focus();
         fetch('', render);
     } else {
         hide();
     }
 });
示例#15
0
文件: field.js 项目: 1ec5/iD
    function revert(d) {
        d3_event.stopPropagation();
        d3_event.preventDefault();
        if (!entity) return false;

        var original = context.graph().base().entities[entity.id],
            t = {};
        d.keys.forEach(function(key) {
            t[key] = original ? original.tags[key] : undefined;
        });

        dispatch.call('change', d, t);
    }
示例#16
0
    function toggleWireframe() {
        if (d3_event) {
            d3_event.preventDefault();
            d3_event.stopPropagation();
        }

        if (_fillSelected === 'wireframe') {
            _fillSelected = context.storage('area-fill-toggle') || 'partial';
        } else {
            _fillSelected = 'wireframe';
        }

        setFill(_fillSelected);
        context.map().pan([0,0]);  // trigger a redraw
    }
 /**
  * Call on event in order to reset the container view.
  */
 function reset() {
   if (focus !== null) {
     focus = null;
     transform(0, 0, 1);
   }
   event.stopPropagation();
 }
示例#18
0
文件: copy.js 项目: openstreetmap/iD
    function doCopy() {
        if (!getSelectionText()) {
            d3_event.preventDefault();
        }

        var graph = context.graph();
        var selected = groupEntities(context.selectedIDs(), graph);
        var canCopy = [];
        var skip = {};
        var entity;
        var i;

        for (i = 0; i < selected.relation.length; i++) {
            entity = selected.relation[i];
            if (!skip[entity.id] && entity.isComplete(graph)) {
                canCopy.push(entity.id);
                skip = getDescendants(entity.id, graph, skip);
            }
        }
        for (i = 0; i < selected.way.length; i++) {
            entity = selected.way[i];
            if (!skip[entity.id]) {
                canCopy.push(entity.id);
                skip = getDescendants(entity.id, graph, skip);
            }
        }
        for (i = 0; i < selected.node.length; i++) {
            entity = selected.node[i];
            if (!skip[entity.id]) {
                canCopy.push(entity.id);
            }
        }

        context.copyIDs(canCopy);
    }
示例#19
0
文件: background.js 项目: 1ec5/iD
 .on('click', function() {
     if (d3_event.button !== 0) return;
     var exp = d3_select(this).classed('expanded');
     nudgeContainer.style('display', exp ? 'none' : 'block');
     d3_select(this).classed('expanded', !exp);
     d3_event.preventDefault();
 });
示例#20
0
    function click() {
        d3_event.preventDefault();

        var osm = context.connection();
        if (!osm) return;

        if (context.inIntro()) return;

        if (context.history().hasChanges() &&
            !window.confirm(t('source_switch.lose_changes'))) return;

        var isLive = d3_select(this)
            .classed('live');

        isLive = !isLive;
        context.enter(modeBrowse(context));
        context.history().clearSaved();          // remove saved history
        context.flush();                         // remove stored data

        d3_select(this)
            .text(isLive ? t('source_switch.live') : t('source_switch.dev'))
            .classed('live', isLive);

        osm.switch(isLive ? keys[0] : keys[1]);  // switch connection (warning: dispatches 'change' event)
    }
示例#21
0
        function toggle() {
            if (d3_event) d3_event.preventDefault();

            isHidden = !isHidden;

            d3_select('.minimap-toggle-item')
                .classed('active', !isHidden)
                .select('input')
                .property('checked', !isHidden);

            if (isHidden) {
                wrap
                    .style('display', 'block')
                    .style('opacity', '1')
                    .transition()
                    .duration(200)
                    .style('opacity', '0')
                    .on('end', function() {
                        selection.selectAll('.map-in-map')
                            .style('display', 'none');
                    });
            } else {
                wrap
                    .style('display', 'block')
                    .style('opacity', '0')
                    .transition()
                    .duration(200)
                    .style('opacity', '1')
                    .on('end', function() {
                        redraw();
                    });
            }
        }
示例#22
0
export default function() {
  event.on("drag.noclick", null).on("end.noclick", function() {
    var click = "click.noclick-" + event.identifier,
        view = select(event.sourceEvent.view).on(click, cancel, true);
    setTimeout(function() { view.on(click, null); }, 0);
  });
}
示例#23
0
文件: welcome.js 项目: Stalfur/iD
    function keyup() {
        if (d3_event.keyCode === 93)  {   // context menu
            d3_event.preventDefault();
            d3_event.stopPropagation();
            var endTime = d3_event.timeStamp,
                startTime = down.menu || endTime,
                delay = (endTime - startTime < minTime) ? minTime : 0;

            window.setTimeout(function() {
                tooltip.classed('rightclick', false);
                down.menu = undefined;  // delayed, for Windows
            }, delay);

            dispatch.call('click', this, 'right');
        }
    }
示例#24
0
文件: background.js 项目: 1ec5/iD
 function toggle() {
     if (d3_event) {
         d3_event.preventDefault();
     }
     tooltipBehavior.hide(button);
     setVisible(!button.classed('active'));
 }
示例#25
0
        function focusSearch() {
            var mode = context.mode() && context.mode().id;
            if (mode !== 'browse') return;

            d3_event.preventDefault();
            search.node().focus();
        }
示例#26
0
function noselectstart() {
  var selectstart = "selectstart.noselect-" + event.identifier,
      view = select(event.sourceEvent.view).on(selectstart, cancel, true);
  event.on("end.noselect", function() {
    view.on(selectstart, null);
  });
}
示例#27
0
        // fast submit if user presses cmd+enter
        function keydown() {
            if (!(d3_event.keyCode === 13 && d3_event.metaKey)) return;

            var osm = services.osm;
            if (!osm) return;

            var hasAuth = osm.authenticated();
            if (!hasAuth) return;

            if (!_note.newComment) return;

            d3_event.preventDefault();

            d3_select(this)
                .on('keydown.note-input', null);

            // focus on button and submit
            window.setTimeout(function() {
                if (_note.isNew()) {
                    noteSave.selectAll('.save-button').node().focus();
                    clickSave(_note);
                } else  {
                    noteSave.selectAll('.comment-button').node().focus();
                    clickComment(_note);
                }
            }, 10);
        }
示例#28
0
文件: operation.js 项目: Stalfur/iD
            keybinding.on(_operation.keys, function() {
                d3_event.preventDefault();
                var disabled = _operation.disabled();
                var flash;

                if (disabled) {
                    flash = uiFlash()
                        .duration(4000)
                        .iconName('#iD-operation-' + _operation.id)
                        .iconClass('operation disabled')
                        .text(_operation.tooltip);

                    flash();

                } else {
                    flash = uiFlash()
                        .duration(2000)
                        .iconName('#iD-operation-' + _operation.id)
                        .iconClass('operation')
                        .text(_operation.annotation() || _operation.title);

                    flash();
                    _operation();
                }
            });
示例#29
0
文件: nodrag.js 项目: hickeye/d3-drag
export default function() {
  var dragstart = "dragstart.nodrag-" + event.identifier,
      view = select(event.sourceEvent.view).on(dragstart, cancel, true);
  event.on("end.nodrag", function() {
    view.on(dragstart, null);
  });
}
示例#30
0
文件: background.js 项目: 1ec5/iD
        function dragOffset() {
            if (d3_event.button !== 0) return;
            var origin = [d3_event.clientX, d3_event.clientY];

            context.container()
                .append('div')
                .attr('class', 'nudge-surface');

            d3_select(window)
                .on('mousemove.offset', function() {
                    var latest = [d3_event.clientX, d3_event.clientY];
                    var d = [
                        -(origin[0] - latest[0]) / 4,
                        -(origin[1] - latest[1]) / 4
                    ];

                    origin = latest;
                    nudge(d);
                })
                .on('mouseup.offset', function() {
                    if (d3_event.button !== 0) return;
                    d3_selectAll('.nudge-surface')
                        .remove();

                    d3_select(window)
                        .on('mousemove.offset', null)
                        .on('mouseup.offset', null);
                });

            d3_event.preventDefault();
        }