lib/features/dragging/Dragging.js
function init(event, relativeTo, prefix, options) {

    // only one drag operation may be active, at a time
    if (context) {
      cancel(false);
    }

    if (typeof relativeTo === 'string') {
      options = prefix;
      prefix = relativeTo;
      relativeTo = null;
    }

    options = assign({}, defaultOptions, options || {});

    var data = options.data || {},
        originalEvent,
        globalStart,
        localStart,
        endDrag,
        isTouch;

    if (options.trapClick) {
      endDrag = trapClickAndEnd;
    } else {
      endDrag = end;
    }

    if (event) {
      originalEvent = getOriginal(event) || event;
      globalStart = toPoint(event);

      stopPropagation(event);

      // prevent default browser dragging behavior
      if (originalEvent.type === 'dragstart') {
        preventDefault(originalEvent);
      }
    } else {
      originalEvent = null;
      globalStart = { x: 0, y: 0 };
    }

    localStart = toLocalPoint(globalStart);

    if (!relativeTo) {
      relativeTo = localStart;
    }

    isTouch = isTouchEvent(originalEvent);

    context = assign({
      prefix: prefix,
      data: data,
      payload: {},
      globalStart: globalStart,
      displacement: deltaPos(relativeTo, localStart),
      localStart: localStart,
      isTouch: isTouch
    }, options);

    // skip dom registration if trigger
    // is set to manual (during testing)
    if (!options.manual) {

      // add dom listeners

      if (isTouch) {
        domEvent.bind(document, 'touchstart', trapTouch, true);
        domEvent.bind(document, 'touchcancel', cancel, true);
        domEvent.bind(document, 'touchmove', move, true);
        domEvent.bind(document, 'touchend', end, true);
      } else {
        // assume we use the mouse to interact per default
        domEvent.bind(document, 'mousemove', move);

        // prevent default browser drag and text selection behavior
        domEvent.bind(document, 'dragstart', preventDefault);
        domEvent.bind(document, 'selectstart', preventDefault);

        domEvent.bind(document, 'mousedown', endDrag, true);
        domEvent.bind(document, 'mouseup', endDrag, true);
      }

      domEvent.bind(document, 'keyup', checkCancel);

      eventBus.on('element.hover', hover);
      eventBus.on('element.out', out);
    }

    fire('init');

    if (options.autoActivate) {
      move(event, true);
    }
  }
function init(event, relativeTo, prefix, options) {

    // only one drag operation may be active, at a time
    if (context) {
      cancel(false);
    }

    if (typeof relativeTo === 'string') {
      options = prefix;
      prefix = relativeTo;
      relativeTo = null;
    }

    options = assign({}, defaultOptions, options || {});

    var data = options.data || {},
        originalEvent,
        globalStart,
        localStart,
        endDrag,
        isTouch;

    if (options.trapClick) {
      endDrag = trapClickAndEnd;
    } else {
      endDrag = end;
    }

    if (event) {
      originalEvent = getOriginal(event) || event;
      globalStart = toPoint(event);

      stopPropagation(event);

      // prevent default browser dragging behavior
      if (originalEvent.type === 'dragstart') {
        preventDefault(originalEvent);
      }
    } else {
      originalEvent = null;
      globalStart = { x: 0, y: 0 };
    }

    localStart = toLocalPoint(globalStart);

    if (!relativeTo) {
      relativeTo = localStart;
    }

    isTouch = isTouchEvent(originalEvent);

    context = assign({
      prefix: prefix,
      data: data,
      payload: {},
      globalStart: globalStart,
      displacement: deltaPos(relativeTo, localStart),
      localStart: localStart,
      isTouch: isTouch
    }, options);

    // skip dom registration if trigger
    // is set to manual (during testing)
    if (!options.manual) {

      // add dom listeners

      if (isTouch) {
        domEvent.bind(document, 'touchstart', trapTouch, true);
        domEvent.bind(document, 'touchcancel', cancel, true);
        domEvent.bind(document, 'touchmove', move, true);
        domEvent.bind(document, 'touchend', end, true);
      } else {
        // assume we use the mouse to interact per default
        domEvent.bind(document, 'mousemove', move);

        // prevent default browser drag and text selection behavior
        domEvent.bind(document, 'dragstart', preventDefault);
        domEvent.bind(document, 'selectstart', preventDefault);

        domEvent.bind(document, 'mousedown', endDrag, true);
        domEvent.bind(document, 'mouseup', endDrag, true);
      }

      domEvent.bind(document, 'keyup', checkCancel);

      eventBus.on('element.hover', hover);
      eventBus.on('element.out', out);
    }

    fire('init');

    if (options.autoActivate) {
      move(event, true);
    }
  }
function init ( event , relativeTo , prefix , options ) { // only one drag operation may be active, at a time if ( context ) { cancel ( false ) ; } if ( typeof relativeTo === 'string' ) { options = prefix ; prefix = relativeTo ; relativeTo = null ; } options = assign ( { } , defaultOptions , options || { } ) ; var data = options . data || { } , originalEvent , globalStart , localStart , endDrag , isTouch ; if ( options . trapClick ) { endDrag = trapClickAndEnd ; } else { endDrag = end ; } if ( event ) { originalEvent = getOriginal ( event ) || event ; globalStart = toPoint ( event ) ; stopPropagation ( event ) ; // prevent default browser dragging behavior if ( originalEvent . type === 'dragstart' ) { preventDefault ( originalEvent ) ; } } else { originalEvent = null ; globalStart = { x : 0 , y : 0 } ; } localStart = toLocalPoint ( globalStart ) ; if ( ! relativeTo ) { relativeTo = localStart ; } isTouch = isTouchEvent ( originalEvent ) ; context = assign ( { prefix : prefix , data : data , payload : { } , globalStart : globalStart , displacement : deltaPos ( relativeTo , localStart ) , localStart : localStart , isTouch : isTouch } , options ) ; // skip dom registration if trigger // is set to manual (during testing) if ( ! options . manual ) { // add dom listeners if ( isTouch ) { domEvent . bind ( document , 'touchstart' , trapTouch , true ) ; domEvent . bind ( document , 'touchcancel' , cancel , true ) ; domEvent . bind ( document , 'touchmove' , move , true ) ; domEvent . bind ( document , 'touchend' , end , true ) ; } else { // assume we use the mouse to interact per default domEvent . bind ( document , 'mousemove' , move ) ; // prevent default browser drag and text selection behavior domEvent . bind ( document , 'dragstart' , preventDefault ) ; domEvent . bind ( document , 'selectstart' , preventDefault ) ; domEvent . bind ( document , 'mousedown' , endDrag , true ) ; domEvent . bind ( document , 'mouseup' , endDrag , true ) ; } domEvent . bind ( document , 'keyup' , checkCancel ) ; eventBus . on ( 'element.hover' , hover ) ; eventBus . on ( 'element.out' , out ) ; } fire ( 'init' ) ; if ( options . autoActivate ) { move ( event , true ) ; } }
Initialize a drag operation.

If `localPosition` is given, drag events will be emitted
relative to it.

@param {MouseEvent|TouchEvent} [event]
@param {Point} [localPosition] actual diagram local position this drag operation should start at
@param {String} prefix
@param {Object} [options]
Initialize a drag operation .