milo

Drag

declaration
 Drag 

milo.registry.facets.get('Drag')
Facet for components that can be dragged
Drag facet supports the following configuration parameters:

  • meta: object with properties
    • params: object of key-value pairs that will be passed in metadata data type (can also be function or method name that returns this object). See config.dragDrop.dataTypes.componentMetaTemplate
    • data: data that will be stored in the above meta data type (or function)
  • allowedEffects: string (or function) as specified here: https://developer.mozilla.org/en-US/docs/DragDrop/Drag_Operations#dragstart
  • dragImage:
    • url: path to image to display when dragging, instead of the owner element
    • x: x offset for the image
    • y: y offset for the image
  • dragCls: CSS class to apply to the component being dragged
  • dataTypes: map of additional data types the component will supply to data transfer object, key is data type, value is a function that returns it, component will be passed as the context to this function

If function is specified in any parameter it will be called with the component as the context

var Drag = _.createSubclass(ComponentFacet, 'Drag');

_.extendProto(Drag, {
    init: Drag$init,
    start: Drag$start,
    setHandle: Drag$setHandle
});

facetsRegistry.add(Drag);

module.exports = Drag;


function Drag$init() {
    ComponentFacet.prototype.init.apply(this, arguments);

    this._createMessageSourceWithAPI(DOMEventsSource);
    this._dragData = {};

    var dataTypeInfo = this.config._dataTypeInfo || '';
    this._dataTypeInfo = typeof dataTypeInfo == 'function'
                            ? dataTypeInfo
                            : function() { return dataTypeInfo; };
}

Drag$setHandle

function
 Drag$setHandle() 

Option name Type Description
handleEl Element

Drag facet instance method
Sets the drag handle element of component. This element has to be dragged for the component to be dragged.

function Drag$setHandle(handleEl) {
    if (! this.owner.el.contains(handleEl))
        return logger.warn('drag handle should be inside element to be dragged');
    this._dragHandle = handleEl;
}


function Drag$start() {
    ComponentFacet.prototype.start.apply(this, arguments);
    _addDragAttribute.call(this);
    _createDragImage.call(this);
    _toggleDragCls.call(this, false);

    this.onMessages({
        'mousedown': onMouseDown,
        'mouseenter mouseleave mousemove': onMouseMovement,
        'dragstart': onDragStart,
        'drag': onDragging,
        'dragend': onDragEnd
    });

    this.owner.onMessages({
        'getstatestarted': _removeDragAttribute,
        'getstatecompleted': _addDragAttribute
    });
}