aboutsummaryrefslogtreecommitdiffstats
path: root/template-common/lib/ui/ui.droppable.js
diff options
context:
space:
mode:
authornikrou <nikrou@piwigo.org>2010-02-20 19:56:36 +0000
committernikrou <nikrou@piwigo.org>2010-02-20 19:56:36 +0000
commit6acc3ff7909dd7f070973c112ebd9291862982f8 (patch)
tree20a0875d668206917f88b73983d7021038b43170 /template-common/lib/ui/ui.droppable.js
parent0c4bdbe01325869a62380c1d2804c34e8a31c1dd (diff)
Feature 1442 : update jquery
* update jquery to 1.4.1 * update jquery ui to 1.7.2 git-svn-id: http://piwigo.org/svn/trunk@4918 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'template-common/lib/ui/ui.droppable.js')
-rw-r--r--template-common/lib/ui/ui.droppable.js283
1 files changed, 142 insertions, 141 deletions
diff --git a/template-common/lib/ui/ui.droppable.js b/template-common/lib/ui/ui.droppable.js
index 6d3e159fa..8e7be33c5 100644
--- a/template-common/lib/ui/ui.droppable.js
+++ b/template-common/lib/ui/ui.droppable.js
@@ -1,10 +1,10 @@
/*
- * jQuery UI Droppable
+ * jQuery UI Droppable 1.7.2
*
- * Copyright (c) 2008 Paul Bakaus
+ * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
- *
+ *
* http://docs.jquery.com/UI/Droppables
*
* Depends:
@@ -14,125 +14,147 @@
(function($) {
$.widget("ui.droppable", {
- init: function() {
- this.element.addClass("ui-droppable");
- this.isover = 0; this.isout = 1;
-
- //Prepare the passed options
+ _init: function() {
+
var o = this.options, accept = o.accept;
- o = $.extend(o, {
- accept: o.accept && o.accept.constructor == Function ? o.accept : function(d) {
- return $(d).is(accept);
- }
- });
-
+ this.isover = 0; this.isout = 1;
+
+ this.options.accept = this.options.accept && $.isFunction(this.options.accept) ? this.options.accept : function(d) {
+ return d.is(accept);
+ };
+
//Store the droppable's proportions
this.proportions = { width: this.element[0].offsetWidth, height: this.element[0].offsetHeight };
-
+
// Add the reference and positions to the manager
- $.ui.ddmanager.droppables.push(this);
-
- },
- plugins: {},
- ui: function(c) {
- return {
- draggable: (c.currentItem || c.element),
- helper: c.helper,
- position: c.position,
- absolutePosition: c.positionAbs,
- options: this.options,
- element: this.element
- };
+ $.ui.ddmanager.droppables[this.options.scope] = $.ui.ddmanager.droppables[this.options.scope] || [];
+ $.ui.ddmanager.droppables[this.options.scope].push(this);
+
+ (this.options.addClasses && this.element.addClass("ui-droppable"));
+
},
+
destroy: function() {
- var drop = $.ui.ddmanager.droppables;
+ var drop = $.ui.ddmanager.droppables[this.options.scope];
for ( var i = 0; i < drop.length; i++ )
if ( drop[i] == this )
drop.splice(i, 1);
-
+
this.element
.removeClass("ui-droppable ui-droppable-disabled")
.removeData("droppable")
.unbind(".droppable");
},
- over: function(e) {
-
+
+ _setData: function(key, value) {
+
+ if(key == 'accept') {
+ this.options.accept = value && $.isFunction(value) ? value : function(d) {
+ return d.is(value);
+ };
+ } else {
+ $.widget.prototype._setData.apply(this, arguments);
+ }
+
+ },
+
+ _activate: function(event) {
+ var draggable = $.ui.ddmanager.current;
+ if(this.options.activeClass) this.element.addClass(this.options.activeClass);
+ (draggable && this._trigger('activate', event, this.ui(draggable)));
+ },
+
+ _deactivate: function(event) {
+ var draggable = $.ui.ddmanager.current;
+ if(this.options.activeClass) this.element.removeClass(this.options.activeClass);
+ (draggable && this._trigger('deactivate', event, this.ui(draggable)));
+ },
+
+ _over: function(event) {
+
var draggable = $.ui.ddmanager.current;
if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element
-
- if (this.options.accept.call(this.element,(draggable.currentItem || draggable.element))) {
- $.ui.plugin.call(this, 'over', [e, this.ui(draggable)]);
- this.element.triggerHandler("dropover", [e, this.ui(draggable)], this.options.over);
+
+ if (this.options.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
+ if(this.options.hoverClass) this.element.addClass(this.options.hoverClass);
+ this._trigger('over', event, this.ui(draggable));
}
-
+
},
- out: function(e) {
-
+
+ _out: function(event) {
+
var draggable = $.ui.ddmanager.current;
if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element
-
- if (this.options.accept.call(this.element,(draggable.currentItem || draggable.element))) {
- $.ui.plugin.call(this, 'out', [e, this.ui(draggable)]);
- this.element.triggerHandler("dropout", [e, this.ui(draggable)], this.options.out);
+
+ if (this.options.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
+ if(this.options.hoverClass) this.element.removeClass(this.options.hoverClass);
+ this._trigger('out', event, this.ui(draggable));
}
-
+
},
- drop: function(e,custom) {
-
+
+ _drop: function(event,custom) {
+
var draggable = custom || $.ui.ddmanager.current;
if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return false; // Bail if draggable and droppable are same element
-
+
var childrenIntersection = false;
- this.element.find(".ui-droppable").not(".ui-draggable-dragging").each(function() {
+ this.element.find(":data(droppable)").not(".ui-draggable-dragging").each(function() {
var inst = $.data(this, 'droppable');
if(inst.options.greedy && $.ui.intersect(draggable, $.extend(inst, { offset: inst.element.offset() }), inst.options.tolerance)) {
childrenIntersection = true; return false;
}
});
if(childrenIntersection) return false;
-
- if(this.options.accept.call(this.element,(draggable.currentItem || draggable.element))) {
- $.ui.plugin.call(this, 'drop', [e, this.ui(draggable)]);
- this.element.triggerHandler("drop", [e, this.ui(draggable)], this.options.drop);
- return true;
+
+ if(this.options.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', event, this.ui(draggable));
+ return this.element;
}
-
+
return false;
-
- },
- activate: function(e) {
-
- var draggable = $.ui.ddmanager.current;
- $.ui.plugin.call(this, 'activate', [e, this.ui(draggable)]);
- if(draggable) this.element.triggerHandler("dropactivate", [e, this.ui(draggable)], this.options.activate);
-
+
},
- deactivate: function(e) {
-
- var draggable = $.ui.ddmanager.current;
- $.ui.plugin.call(this, 'deactivate', [e, this.ui(draggable)]);
- if(draggable) this.element.triggerHandler("dropdeactivate", [e, this.ui(draggable)], this.options.deactivate);
-
+
+ ui: function(c) {
+ return {
+ draggable: (c.currentItem || c.element),
+ helper: c.helper,
+ position: c.position,
+ absolutePosition: c.positionAbs, //deprecated
+ offset: c.positionAbs
+ };
}
+
});
$.extend($.ui.droppable, {
+ version: "1.7.2",
+ eventPrefix: 'drop',
defaults: {
- disabled: false,
+ accept: '*',
+ activeClass: false,
+ addClasses: true,
+ greedy: false,
+ hoverClass: false,
+ scope: 'default',
tolerance: 'intersect'
}
});
$.ui.intersect = function(draggable, droppable, toleranceMode) {
-
+
if (!droppable.offset) return false;
-
+
var x1 = (draggable.positionAbs || draggable.position.absolute).left, x2 = x1 + draggable.helperProportions.width,
y1 = (draggable.positionAbs || draggable.position.absolute).top, y2 = y1 + draggable.helperProportions.height;
var l = droppable.offset.left, r = l + droppable.proportions.width,
t = droppable.offset.top, b = t + droppable.proportions.height;
-
+
switch (toleranceMode) {
case 'fit':
return (l < x1 && x2 < r
@@ -145,8 +167,10 @@ $.ui.intersect = function(draggable, droppable, toleranceMode) {
&& y2 - (draggable.helperProportions.height / 2) < b ); // Top Half
break;
case 'pointer':
- return (l < ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left) && ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left) < r
- && t < ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top) && ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top) < b);
+ var 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),
+ isOver = $.ui.isOver(draggableTop, draggableLeft, t, l, droppable.proportions.height, droppable.proportions.width);
+ return isOver;
break;
case 'touch':
return (
@@ -163,7 +187,7 @@ $.ui.intersect = function(draggable, droppable, toleranceMode) {
return false;
break;
}
-
+
};
/*
@@ -171,111 +195,88 @@ $.ui.intersect = function(draggable, droppable, toleranceMode) {
*/
$.ui.ddmanager = {
current: null,
- droppables: [],
- prepareOffsets: function(t, e) {
-
- var m = $.ui.ddmanager.droppables;
- var type = e ? e.type : null; // workaround for #2317
-
- for (var i = 0; i < m.length; i++) {
- if(m[i].options.disabled || (t && !m[i].options.accept.call(m[i].element,(t.currentItem || t.element)))) continue;
- m[i].visible = m[i].element.css("display") != "none"; if(!m[i].visible) continue; //If the element is not visible, continue
+ droppables: { 'default': [] },
+ prepareOffsets: function(t, event) {
+
+ var m = $.ui.ddmanager.droppables[t.options.scope];
+ var type = event ? event.type : null; // workaround for #2317
+ var list = (t.currentItem || t.element).find(":data(droppable)").andSelf();
+
+ droppablesLoop: for (var i = 0; i < m.length; i++) {
+
+ if(m[i].options.disabled || (t && !m[i].options.accept.call(m[i].element[0],(t.currentItem || t.element)))) continue; //No disabled and non-accepted
+ for (var j=0; j < list.length; j++) { if(list[j] == m[i].element[0]) { m[i].proportions.height = 0; continue droppablesLoop; } }; //Filter out elements in the current dragged item
+ m[i].visible = m[i].element.css("display") != "none"; if(!m[i].visible) continue; //If the element is not visible, continue
+
m[i].offset = m[i].element.offset();
m[i].proportions = { width: m[i].element[0].offsetWidth, height: m[i].element[0].offsetHeight };
-
- if(type == "dragstart" || type == "sortactivate") m[i].activate.call(m[i], e); //Activate the droppable if used directly from draggables
+
+ if(type == "mousedown") m[i]._activate.call(m[i], event); //Activate the droppable if used directly from draggables
+
}
-
+
},
- drop: function(draggable, e) {
-
+ drop: function(draggable, event) {
+
var dropped = false;
- $.each($.ui.ddmanager.droppables, function() {
-
+ $.each($.ui.ddmanager.droppables[draggable.options.scope], function() {
+
if(!this.options) return;
if (!this.options.disabled && this.visible && $.ui.intersect(draggable, this, this.options.tolerance))
- dropped = this.drop.call(this, e);
-
- if (!this.options.disabled && this.visible && this.options.accept.call(this.element,(draggable.currentItem || draggable.element))) {
+ dropped = this._drop.call(this, event);
+
+ if (!this.options.disabled && this.visible && this.options.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
this.isout = 1; this.isover = 0;
- this.deactivate.call(this, e);
+ this._deactivate.call(this, event);
}
-
+
});
return dropped;
-
+
},
- drag: function(draggable, e) {
-
+ drag: function(draggable, event) {
+
//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(draggable, e);
-
+ if(draggable.options.refreshPositions) $.ui.ddmanager.prepareOffsets(draggable, event);
+
//Run through all droppables and check their positions based on specific tolerance options
- $.each($.ui.ddmanager.droppables, function() {
-
+ $.each($.ui.ddmanager.droppables[draggable.options.scope], function() {
+
if(this.options.disabled || this.greedyChild || !this.visible) return;
var intersects = $.ui.intersect(draggable, this, this.options.tolerance);
-
+
var c = !intersects && this.isover == 1 ? 'isout' : (intersects && this.isover == 0 ? 'isover' : null);
if(!c) return;
-
+
var parentInstance;
if (this.options.greedy) {
- var parent = this.element.parents('.ui-droppable:eq(0)');
+ var parent = this.element.parents(':data(droppable):eq(0)');
if (parent.length) {
parentInstance = $.data(parent[0], 'droppable');
parentInstance.greedyChild = (c == 'isover' ? 1 : 0);
}
}
-
+
// we just moved into a greedy child
if (parentInstance && c == 'isover') {
parentInstance['isover'] = 0;
parentInstance['isout'] = 1;
- parentInstance.out.call(parentInstance, e);
+ parentInstance._out.call(parentInstance, event);
}
-
+
this[c] = 1; this[c == 'isout' ? 'isover' : 'isout'] = 0;
- this[c == "isover" ? "over" : "out"].call(this, e);
-
+ this[c == "isover" ? "_over" : "_out"].call(this, event);
+
// we just moved out of a greedy child
if (parentInstance && c == 'isout') {
parentInstance['isout'] = 0;
parentInstance['isover'] = 1;
- parentInstance.over.call(parentInstance, e);
+ parentInstance._over.call(parentInstance, event);
}
});
-
- }
-};
-/*
- * Droppable Extensions
- */
-
-$.ui.plugin.add("droppable", "activeClass", {
- activate: function(e, ui) {
- $(this).addClass(ui.options.activeClass);
- },
- deactivate: function(e, ui) {
- $(this).removeClass(ui.options.activeClass);
- },
- drop: function(e, ui) {
- $(this).removeClass(ui.options.activeClass);
}
-});
-
-$.ui.plugin.add("droppable", "hoverClass", {
- over: function(e, ui) {
- $(this).addClass(ui.options.hoverClass);
- },
- out: function(e, ui) {
- $(this).removeClass(ui.options.hoverClass);
- },
- drop: function(e, ui) {
- $(this).removeClass(ui.options.hoverClass);
- }
-});
+};
})(jQuery);