Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag.Move.Collide.js #17

Open
jnbdz opened this issue Nov 9, 2015 · 0 comments
Open

Drag.Move.Collide.js #17

jnbdz opened this issue Nov 9, 2015 · 0 comments
Labels

Comments

@jnbdz
Copy link
Member

jnbdz commented Nov 9, 2015

/*

description: The Drag.Move.Collide class makes it easy to detect when two or more elements collide when dragging another element.

authors:

license:

  • MIT-style license

requires:

  • core/1.4: '*'
  • more:1.4.0.1/Drag
  • more:1.4.0.1/Drag.Move
  • Element.collide/0.5

provides:

  • Drag.Move.Collide
    ...
    */

Drag.Move.Collide = new Class({

    Extends: Drag.Move,

    options: {/*
            onCollide: function(thisElement, thisOvered){},
            onLeaveCollision: function(thisElement, overed){},*/
            checkDroppables: false,
            checkCollision: true
    },

    initialize: function(element, options){
        this.parent(element, options);
        if (this.options.checkCollision) this.addEvent('start', this.checkCollision, true); 
        this.overed = null;
    },

    checkDroppables: function() {
        if(this.options.checkDroppables) this.parent();
    },

    checkCollision: function(){

        var overed = this.droppables.filter(function(el, i){

            return el.collide(this.element);

        }, this);

        if (this.overed != overed){
            if (this.overed) this.fireEvent('leaveCollision', [this.element, this.overed]);
            if (overed) this.fireEvent('collide', [this.element, overed]);
            this.overed = overed;
        }

    },

    drag: function(event){
        this.parent(event);
        if (this.options.checkCollision && this.droppables.length) this.checkCollision();
    },

    stop: function(event){
        if (this.options.checkCollision && this.droppables.length) this.checkCollision();
        this.fireEvent('drop', [this.element, this.overed, event]);
        this.overed = null;
        var events = {
            mousemove: this.bound.drag,
            mouseup: this.bound.stop
        };
        events[this.selection] = this.bound.eventStop;
        this.document.removeEvents(events);
        if (event) this.fireEvent('complete', [this.element, event]);
    }

});
@jnbdz jnbdz added the Proposal label Nov 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant