Вход Регистрация
Файл: ui/development-bundle/ui/jquery.ui.droppable.js
Строк: 420
<?php
/*!
 * jQuery UI Droppable 1.10.0
 * http://jqueryui.com
 *
 * Copyright 2013 jQuery Foundation and other contributors
 * Released under the MIT license.
 * http://jquery.org/license
 *
 * http://api.jqueryui.com/droppable/
 *
 * Depends:
 *    jquery.ui.core.js
 *    jquery.ui.widget.js
 *    jquery.ui.mouse.js
 *    jquery.ui.draggable.js
 */
(function( $, undefined ) {

function 
isOverAxisxreferencesize ) {
    return ( 
reference ) && ( < ( reference size ) );
}

$.
widget("ui.droppable", {
    
version"1.10.0",
    
widgetEventPrefix"drop",
    
options: {
        
accept"*",
        
activeClassfalse,
        
addClassestrue,
        
greedyfalse,
        
hoverClassfalse,
        
scope"default",
        
tolerance"intersect",

        
// callbacks
        
activatenull,
        
deactivatenull,
        
dropnull,
        
outnull,
        
overnull
    
},
    
_create: function() {

        var 
this.options,
            
accept o.accept;

        
this.isover false;
        
this.isout true;

        
this.accept = $.isFunction(accept) ? accept : function(d) {
            return 
d.is(accept);
        };

        
//Store the droppable's proportions
        
this.proportions = { widththis.element[0].offsetWidthheightthis.element[0].offsetHeight };

        
// Add the reference and positions to the manager
        
$.ui.ddmanager.droppables[o.scope] = $.ui.ddmanager.droppables[o.scope] || [];
        $.
ui.ddmanager.droppables[o.scope].push(this);

        (
o.addClasses && this.element.addClass("ui-droppable"));

    },

    
_destroy: function() {
        var 
0,
            
drop = $.ui.ddmanager.droppables[this.options.scope];

        for ( ; 
drop.lengthi++ ) {
            if ( 
drop[i] === this ) {
                
drop.splice(i1);
            }
        }

        
this.element.removeClass("ui-droppable ui-droppable-disabled");
    },

    
_setOption: function(keyvalue) {

        if(
key === "accept") {
            
this.accept = $.isFunction(value) ? value : function(d) {
                return 
d.is(value);
            };
        }
        $.
Widget.prototype._setOption.apply(thisarguments);
    },

    
_activate: function(event) {
        var 
draggable = $.ui.ddmanager.current;
        if(
this.options.activeClass) {
            
this.element.addClass(this.options.activeClass);
        }
        if(
draggable){
            
this._trigger("activate"eventthis.ui(draggable));
        }
    },

    
_deactivate: function(event) {
        var 
draggable = $.ui.ddmanager.current;
        if(
this.options.activeClass) {
            
this.element.removeClass(this.options.activeClass);
        }
        if(
draggable){
            
this._trigger("deactivate"eventthis.ui(draggable));
        }
    },

    
_over: function(event) {

        var 
draggable = $.ui.ddmanager.current;

        
// Bail if draggable and droppable are same element
        
if (!draggable || (draggable.currentItem || draggable.element)[0] === this.element[0]) {
            return;
        }

        if (
this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
            if(
this.options.hoverClass) {
                
this.element.addClass(this.options.hoverClass);
            }
            
this._trigger("over"eventthis.ui(draggable));
        }

    },

    
_out: function(event) {

        var 
draggable = $.ui.ddmanager.current;

        
// Bail if draggable and droppable are same element
        
if (!draggable || (draggable.currentItem || draggable.element)[0] === this.element[0]) {
            return;
        }

        if (
this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
            if(
this.options.hoverClass) {
                
this.element.removeClass(this.options.hoverClass);
            }
            
this._trigger("out"eventthis.ui(draggable));
        }

    },

    
_drop: function(event,custom) {

        var 
draggable custom || $.ui.ddmanager.current,
            
childrenIntersection false;

        
// Bail if draggable and droppable are same element
        
if (!draggable || (draggable.currentItem || draggable.element)[0] === this.element[0]) {
            return 
false;
        }

        
this.element.find(":data(ui-droppable)").not(".ui-draggable-dragging").each(function() {
            var 
inst = $.data(this"ui-droppable");
            if(
                
inst.options.greedy &&
                !
inst.options.disabled &&
                
inst.options.scope === draggable.options.scope &&
                
inst.accept.call(inst.element[0], (draggable.currentItem || draggable.element)) &&
                $.
ui.intersect(draggable, $.extend(inst, { offsetinst.element.offset() }), inst.options.tolerance)
            ) { 
childrenIntersection true; return false; }
        });
        if(
childrenIntersection) {
            return 
false;
        }

        if(
this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
            if(
this.options.activeClass) {
                
this.element.removeClass(this.options.activeClass);
            }
            if(
this.options.hoverClass) {
                
this.element.removeClass(this.options.hoverClass);
            }
            
this._trigger("drop"eventthis.ui(draggable));
            return 
this.element;
        }

        return 
false;

    },

    
ui: function(c) {
        return {
            
draggable: (c.currentItem || c.element),
            
helperc.helper,
            
positionc.position,
            
offsetc.positionAbs
        
};
    }

});

$.
ui.intersect = function(draggabledroppabletoleranceMode) {

    if (!
droppable.offset) {
        return 
false;
    }

    var 
draggableLeftdraggableTop,
        
x1 = (draggable.positionAbs || draggable.position.absolute).leftx2 x1 draggable.helperProportions.width,
        
y1 = (draggable.positionAbs || draggable.position.absolute).topy2 y1 draggable.helperProportions.height,
        
droppable.offset.leftdroppable.proportions.width,
        
droppable.offset.topdroppable.proportions.height;

    switch (
toleranceMode) {
        case 
"fit":
            return (
<= x1 && x2 <= && <= y1 && y2 <= b);
        case 
"intersect":
            return (
x1 + (draggable.helperProportions.width 2) && // Right Half
                
x2 - (draggable.helperProportions.width 2) < && // Left Half
                
y1 + (draggable.helperProportions.height 2) && // Bottom Half
                
y2 - (draggable.helperProportions.height 2) < ); // Top Half
        
case "pointer":
            
draggableLeft = ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left);
            
draggableTop = ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top);
            return 
isOverAxisdraggableToptdroppable.proportions.height ) && isOverAxisdraggableLeftldroppable.proportions.width );
        case 
"touch":
            return (
                (
y1 >= && y1 <= b) ||    // Top edge touching
                
(y2 >= && y2 <= b) ||    // Bottom edge touching
                
(y1 && y2 b)        // Surrounded vertically
            
) && (
                (
x1 >= && x1 <= r) ||    // Left edge touching
                
(x2 >= && x2 <= r) ||    // Right edge touching
                
(x1 && x2 r)        // Surrounded horizontally
            
);
        default:
            return 
false;
        }

};

/*
    This manager tracks offsets of draggables and droppables
*/
$.ui.ddmanager = {
    
currentnull,
    
droppables: { "default": [] },
    
prepareOffsets: function(tevent) {

        var 
ij,
            
= $.ui.ddmanager.droppables[t.options.scope] || [],
            
type event event.type null// workaround for #2317
            
list = (t.currentItem || t.element).find(":data(ui-droppable)").addBack();

        
droppablesLoop: for (0m.lengthi++) {

            
//No disabled and non-accepted
            
if(m[i].options.disabled || (&& !m[i].accept.call(m[i].element[0],(t.currentItem || t.element)))) {
                continue;
            }

            
// Filter out elements in the current dragged item
            
for (j=0< list.lengthj++) {
                if(list[
j] === m[i].element[0]) {
                    
m[i].proportions.height 0;
                    continue 
droppablesLoop;
                }
            }

            
m[i].visible m[i].element.css("display") !== "none";
            if(!
m[i].visible) {
                continue;
            }

            
//Activate the droppable if used directly from draggables
            
if(type === "mousedown") {
                
m[i]._activate.call(m[i], event);
            }

            
m[i].offset m[i].element.offset();
            
m[i].proportions = { widthm[i].element[0].offsetWidthheightm[i].element[0].offsetHeight };

        }

    },
    
drop: function(draggableevent) {

        var 
dropped false;
        $.
each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() {

            if(!
this.options) {
                return;
            }
            if (!
this.options.disabled && this.visible && $.ui.intersect(draggablethisthis.options.tolerance)) {
                
dropped this._drop.call(thisevent) || dropped;
            }

            if (!
this.options.disabled && this.visible && this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
                
this.isout true;
                
this.isover false;
                
this._deactivate.call(thisevent);
            }

        });
        return 
dropped;

    },
    
dragStart: function( draggableevent ) {
        
//Listen for scrolling so that if the dragging causes scrolling the position of the droppables can be recalculated (see #5003)
        
draggable.element.parentsUntil"body" ).bind"scroll.droppable", function() {
            if( !
draggable.options.refreshPositions ) {
                $.
ui.ddmanager.prepareOffsetsdraggableevent );
            }
        });
    },
    
drag: function(draggableevent) {

        
//If you have a highly dynamic page, you might try this option. It renders positions every time you move the mouse.
        
if(draggable.options.refreshPositions) {
            $.
ui.ddmanager.prepareOffsets(draggableevent);
        }

        
//Run through all droppables and check their positions based on specific tolerance options
        
$.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() {

            if(
this.options.disabled || this.greedyChild || !this.visible) {
                return;
            }

            var 
parentInstancescopeparent,
                
intersects = $.ui.intersect(draggablethisthis.options.tolerance),
                
= !intersects && this.isover "isout" : (intersects && !this.isover "isover" null);
            if(!
c) {
                return;
            }

            if (
this.options.greedy) {
                
// find droppable parents with same scope
                
scope this.options.scope;
                
parent this.element.parents(":data(ui-droppable)").filter(function () {
                    return $.
data(this"ui-droppable").options.scope === scope;
                });

                if (
parent.length) {
                    
parentInstance = $.data(parent[0], "ui-droppable");
                    
parentInstance.greedyChild = (=== "isover");
                }
            }

            
// we just moved into a greedy child
            
if (parentInstance && === "isover") {
                
parentInstance.isover false;
                
parentInstance.isout true;
                
parentInstance._out.call(parentInstanceevent);
            }

            
this[c] = true;
            
this[=== "isout" "isover" "isout"] = false;
            
this[=== "isover" "_over" "_out"].call(thisevent);

            
// we just moved out of a greedy child
            
if (parentInstance && === "isout") {
                
parentInstance.isout false;
                
parentInstance.isover true;
                
parentInstance._over.call(parentInstanceevent);
            }
        });

    },
    
dragStop: function( draggableevent ) {
        
draggable.element.parentsUntil"body" ).unbind"scroll.droppable" );
        
//Call prepareOffsets one final time since IE does not fire return scroll events when overflow was caused by drag (see #5003)
        
if( !draggable.options.refreshPositions ) {
            $.
ui.ddmanager.prepareOffsetsdraggableevent );
        }
    }
};

})(
jQuery);
?>
Онлайн: 0
Реклама