Merge branch 'master' into selectmenu

This commit is contained in:
Felix Nagel 2013-05-30 21:28:15 +02:00
commit 57fa48281c
6 changed files with 231 additions and 145 deletions

View File

@ -192,6 +192,34 @@ asyncTest( "handle race condition", function() {
}
});
asyncTest( "simultaneous searches (#9334)", function() {
expect( 2 );
var element = $( "#autocomplete" ).autocomplete({
source: function( request, response ) {
setTimeout(function() {
response([ request.term ]);
});
},
response: function() {
ok( true, "response from first instance" );
}
}),
element2 = $( "#autocomplete-textarea" ).autocomplete({
source: function( request, response ) {
setTimeout(function() {
response([ request.term ]);
});
},
response: function() {
ok( true, "response from second instance" );
start();
}
});
element.autocomplete( "search", "test" );
element2.autocomplete( "search", "test" );
});
test( "ARIA", function() {
expect( 7 );
var element = $( "#autocomplete" ).autocomplete({

View File

@ -170,4 +170,51 @@ test("stop", function() {
});
test( "resize (containment) works with parent with negative offset", function() {
expect( 1 );
var widthBefore, widthAfter,
handle = ".ui-resizable-e",
target = $( "#resizable1" ),
absoluteContainer = target.wrap( "<div />" ).parent(),
fixedContainer = absoluteContainer.wrap( "<div />" ).parent(),
increaseWidthBy = 50;
// position fixed container in window top left
fixedContainer.css({
width: 400,
height: 100,
position: "fixed",
top: 0,
left: 0
});
// position absolute container within fixed on slightly outside window
absoluteContainer.css({
width: 400,
height: 100,
position: "absolute",
top: 0,
left: -50
});
// set up resizable to be contained within absolute container
target.resizable({
handles: "all",
containment: "parent"
}).css({
width: 300
});
widthBefore = target.width();
TestHelpers.resizable.drag( handle, increaseWidthBy, 0 );
widthAfter = target.width();
equal( widthAfter, ( widthBefore + increaseWidthBy ), "resizable width should be increased by the value dragged" );
});
})(jQuery);

View File

@ -19,9 +19,6 @@
.ui-accordion .ui-accordion-icons {
padding-left: 2.2em;
}
.ui-accordion .ui-accordion-noicons {
padding-left: .7em;
}
.ui-accordion .ui-accordion-icons .ui-accordion-icons {
padding-left: 2.2em;
}

View File

@ -41,6 +41,7 @@ $.widget( "ui.autocomplete", {
select: null
},
requestIndex: 0,
pending: 0,
_create: function() {
@ -414,24 +415,20 @@ $.widget( "ui.autocomplete", {
this.source( { term: value }, this._response() );
},
_response: (function() {
var requestIndex = 0;
_response: function() {
var index = ++this.requestIndex;
return function() {
var index = ++requestIndex;
return $.proxy(function( content ) {
if ( index === this.requestIndex ) {
this.__response( content );
}
return $.proxy(function( content ) {
if ( index === requestIndex ) {
this.__response( content );
}
this.pending--;
if ( !this.pending ) {
this.element.removeClass( "ui-autocomplete-loading" );
}
}, this );
};
})(),
this.pending--;
if ( !this.pending ) {
this.element.removeClass( "ui-autocomplete-loading" );
}
}, this );
},
__response: function( content ) {
if ( content ) {

View File

@ -20,7 +20,7 @@ function isOverAxis( x, reference, size ) {
return ( x >= reference ) && ( x < ( reference + size ) );
}
$.widget("ui.droppable", {
$.widget( "ui.droppable", {
version: "@VERSION",
widgetEventPrefix: "drop",
options: {
@ -41,138 +41,151 @@ $.widget("ui.droppable", {
},
_create: function() {
var o = this.options,
var proportions,
o = this.options,
accept = o.accept;
this.isover = false;
this.isout = true;
this.accept = $.isFunction(accept) ? accept : function(d) {
return d.is(accept);
this.accept = $.isFunction( accept ) ? accept : function( d ) {
return d.is( accept );
};
//Store the droppable's proportions
this.proportions = { width: this.element[0].offsetWidth, height: this.element[0].offsetHeight };
this.proportions = function( /* valueToWrite */ ) {
if ( arguments.length ) {
// Store the droppable's proportions
proportions = arguments[ 0 ];
} else {
// Retrieve or derive the droppable's proportions
return proportions ?
proportions :
proportions = {
width: this.element[ 0 ].offsetWidth,
height: this.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);
$.ui.ddmanager.droppables[ o.scope ] = $.ui.ddmanager.droppables[ o.scope ] || [];
$.ui.ddmanager.droppables[ o.scope ].push( this );
(o.addClasses && this.element.addClass("ui-droppable"));
o.addClasses && this.element.addClass( "ui-droppable" );
},
_destroy: function() {
var i = 0,
drop = $.ui.ddmanager.droppables[this.options.scope];
drop = $.ui.ddmanager.droppables[ this.options.scope ];
for ( ; i < drop.length; i++ ) {
if ( drop[i] === this ) {
drop.splice(i, 1);
if ( drop[ i ] === this ) {
drop.splice( i, 1 );
}
}
this.element.removeClass("ui-droppable ui-droppable-disabled");
this.element.removeClass( "ui-droppable ui-droppable-disabled" );
},
_setOption: function(key, value) {
_setOption: function( key, value ) {
if(key === "accept") {
this.accept = $.isFunction(value) ? value : function(d) {
return d.is(value);
if ( key === "accept" ) {
this.accept = $.isFunction( value ) ? value : function( d ) {
return d.is( value );
};
}
this._super( key, value );
},
_activate: function(event) {
_activate: function( event ) {
var draggable = $.ui.ddmanager.current;
if(this.options.activeClass) {
this.element.addClass(this.options.activeClass);
if ( this.options.activeClass ) {
this.element.addClass( this.options.activeClass );
}
if(draggable){
this._trigger("activate", event, this.ui(draggable));
if ( draggable ){
this._trigger( "activate", event, this.ui( draggable ) );
}
},
_deactivate: function(event) {
_deactivate: function( event ) {
var draggable = $.ui.ddmanager.current;
if(this.options.activeClass) {
this.element.removeClass(this.options.activeClass);
if ( this.options.activeClass ) {
this.element.removeClass( this.options.activeClass );
}
if(draggable){
this._trigger("deactivate", event, this.ui(draggable));
if ( draggable ){
this._trigger( "deactivate", event, this.ui( draggable ) );
}
},
_over: function(event) {
_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]) {
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);
if ( this.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));
this._trigger( "over", event, this.ui( draggable ) );
}
},
_out: function(event) {
_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]) {
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);
if ( this.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));
this._trigger( "out", event, this.ui( draggable ) );
}
},
_drop: function(event,custom) {
_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]) {
if ( !draggable || ( draggable.currentItem || draggable.element )[ 0 ] === this.element[ 0 ] ) {
return false;
}
this.element.find(":data(ui-droppable)").not(".ui-draggable-dragging").each(function() {
this.element.find( ":data(ui-droppable)" ).not( ".ui-draggable-dragging" ).each(function() {
var inst = $( this ).droppable( "instance" );
if(
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, { offset: inst.element.offset() }), inst.options.tolerance)
inst.accept.call( inst.element[ 0 ], ( draggable.currentItem || draggable.element ) ) &&
$.ui.intersect( draggable, $.extend( inst, { offset: inst.element.offset() } ), inst.options.tolerance )
) { childrenIntersection = true; return false; }
});
if(childrenIntersection) {
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.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);
if ( this.options.hoverClass ) {
this.element.removeClass( this.options.hoverClass );
}
this._trigger("drop", event, this.ui(draggable));
this._trigger( "drop", event, this.ui( draggable ) );
return this.element;
}
@ -180,9 +193,9 @@ $.widget("ui.droppable", {
},
ui: function(c) {
ui: function( c ) {
return {
draggable: (c.currentItem || c.element),
draggable: ( c.currentItem || c.element ),
helper: c.helper,
position: c.position,
offset: c.positionAbs
@ -191,39 +204,43 @@ $.widget("ui.droppable", {
});
$.ui.intersect = function(draggable, droppable, toleranceMode) {
$.ui.intersect = function( draggable, droppable, toleranceMode ) {
if (!droppable.offset) {
if ( !droppable.offset ) {
return false;
}
var draggableLeft, draggableTop,
x1 = (draggable.positionAbs || draggable.position.absolute).left, x2 = x1 + draggable.helperProportions.width,
y1 = (draggable.positionAbs || draggable.position.absolute).top, y2 = y1 + draggable.helperProportions.height,
l = droppable.offset.left, r = l + droppable.proportions.width,
t = droppable.offset.top, b = t + droppable.proportions.height;
x1 = ( draggable.positionAbs || draggable.position.absolute ).left,
y1 = ( draggable.positionAbs || draggable.position.absolute ).top,
x2 = x1 + draggable.helperProportions.width,
y2 = y1 + draggable.helperProportions.height,
l = droppable.offset.left,
t = droppable.offset.top,
r = l + droppable.proportions().width,
b = t + droppable.proportions().height;
switch (toleranceMode) {
switch ( toleranceMode ) {
case "fit":
return (l <= x1 && x2 <= r && t <= y1 && y2 <= b);
return ( l <= x1 && x2 <= r && t <= y1 && y2 <= b );
case "intersect":
return (l < x1 + (draggable.helperProportions.width / 2) && // Right Half
x2 - (draggable.helperProportions.width / 2) < r && // Left Half
t < y1 + (draggable.helperProportions.height / 2) && // Bottom Half
y2 - (draggable.helperProportions.height / 2) < b ); // Top Half
return ( l < x1 + ( draggable.helperProportions.width / 2 ) && // Right Half
x2 - ( draggable.helperProportions.width / 2 ) < r && // Left Half
t < y1 + ( draggable.helperProportions.height / 2 ) && // Bottom Half
y2 - ( draggable.helperProportions.height / 2 ) < b ); // 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 isOverAxis( draggableTop, t, droppable.proportions.height ) && isOverAxis( draggableLeft, l, droppable.proportions.width );
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 isOverAxis( draggableTop, t, droppable.proportions().height ) && isOverAxis( draggableLeft, l, droppable.proportions().width );
case "touch":
return (
(y1 >= t && y1 <= b) || // Top edge touching
(y2 >= t && y2 <= b) || // Bottom edge touching
(y1 < t && y2 > b) // Surrounded vertically
( y1 >= t && y1 <= b ) || // Top edge touching
( y2 >= t && y2 <= b ) || // Bottom edge touching
( y1 < t && y2 > b ) // Surrounded vertically
) && (
(x1 >= l && x1 <= r) || // Left edge touching
(x2 >= l && x2 <= r) || // Right edge touching
(x1 < l && x2 > r) // Surrounded horizontally
( x1 >= l && x1 <= r ) || // Left edge touching
( x2 >= l && x2 <= r ) || // Right edge touching
( x1 < l && x2 > r ) // Surrounded horizontally
);
default:
return false;
@ -237,61 +254,61 @@ $.ui.intersect = function(draggable, droppable, toleranceMode) {
$.ui.ddmanager = {
current: null,
droppables: { "default": [] },
prepareOffsets: function(t, event) {
prepareOffsets: function( t, event ) {
var i, j,
m = $.ui.ddmanager.droppables[t.options.scope] || [],
m = $.ui.ddmanager.droppables[ t.options.scope ] || [],
type = event ? event.type : null, // workaround for #2317
list = (t.currentItem || t.element).find(":data(ui-droppable)").addBack();
list = ( t.currentItem || t.element ).find( ":data(ui-droppable)" ).addBack();
droppablesLoop: for (i = 0; i < m.length; i++) {
droppablesLoop: for ( i = 0; i < m.length; i++ ) {
//No disabled and non-accepted
if(m[i].options.disabled || (t && !m[i].accept.call(m[i].element[0],(t.currentItem || t.element)))) {
// No disabled and non-accepted
if ( m[ i ].options.disabled || ( t && !m[ i ].accept.call( m[ i ].element[ 0 ], ( t.currentItem || t.element ) ) ) ) {
continue;
}
// Filter out elements in the current dragged item
for (j=0; j < list.length; j++) {
if(list[j] === m[i].element[0]) {
m[i].proportions.height = 0;
for ( j=0; j < list.length; j++ ) {
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) {
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);
// 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 = { width: m[i].element[0].offsetWidth, height: m[i].element[0].offsetHeight };
m[ i ].offset = m[ i ].element.offset();
m[ i ].proportions({ width: m[ i ].element[ 0 ].offsetWidth, height: m[ i ].element[ 0 ].offsetHeight });
}
},
drop: function(draggable, event) {
drop: function( draggable, event ) {
var dropped = false;
// Create a copy of the droppables in case the list changes during the drop (#9116)
$.each(($.ui.ddmanager.droppables[draggable.options.scope] || []).slice(), function() {
$.each( ( $.ui.ddmanager.droppables[ draggable.options.scope ] || [] ).slice(), function() {
if(!this.options) {
if ( !this.options ) {
return;
}
if (!this.options.disabled && this.visible && $.ui.intersect(draggable, this, this.options.tolerance)) {
dropped = this._drop.call(this, event) || dropped;
if ( !this.options.disabled && this.visible && $.ui.intersect( draggable, this, this.options.tolerance ) ) {
dropped = this._drop.call( this, event ) || dropped;
}
if (!this.options.disabled && this.visible && this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
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(this, event);
this._deactivate.call( this, event );
}
});
@ -299,74 +316,74 @@ $.ui.ddmanager = {
},
dragStart: function( draggable, event ) {
//Listen for scrolling so that if the dragging causes scrolling the position of the droppables can be recalculated (see #5003)
// 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 ) {
if ( !draggable.options.refreshPositions ) {
$.ui.ddmanager.prepareOffsets( draggable, event );
}
});
},
drag: function(draggable, event) {
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, 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, event );
}
//Run through all droppables and check their positions based on specific tolerance options
$.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() {
// 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) {
if ( this.options.disabled || this.greedyChild || !this.visible ) {
return;
}
var parentInstance, scope, parent,
intersects = $.ui.intersect(draggable, this, this.options.tolerance),
c = !intersects && this.isover ? "isout" : (intersects && !this.isover ? "isover" : null);
if(!c) {
intersects = $.ui.intersect( draggable, this, this.options.tolerance ),
c = !intersects && this.isover ? "isout" : ( intersects && !this.isover ? "isover" : null );
if ( !c ) {
return;
}
if (this.options.greedy) {
if ( this.options.greedy ) {
// find droppable parents with same scope
scope = this.options.scope;
parent = this.element.parents(":data(ui-droppable)").filter(function () {
return $(this).droppable( "instance" ).options.scope === scope;
parent = this.element.parents( ":data(ui-droppable)" ).filter(function () {
return $( this ).droppable( "instance" ).options.scope === scope;
});
if (parent.length) {
if ( parent.length ) {
parentInstance = $( parent[ 0 ] ).droppable( "instance" );
parentInstance.greedyChild = (c === "isover");
parentInstance.greedyChild = ( c === "isover" );
}
}
// we just moved into a greedy child
if (parentInstance && c === "isover") {
if ( parentInstance && c === "isover" ) {
parentInstance.isover = false;
parentInstance.isout = true;
parentInstance._out.call(parentInstance, event);
parentInstance._out.call( parentInstance, event );
}
this[c] = true;
this[ c ] = true;
this[c === "isout" ? "isover" : "isout"] = false;
this[c === "isover" ? "_over" : "_out"].call(this, event);
this[c === "isover" ? "_over" : "_out"].call( this, event );
// we just moved out of a greedy child
if (parentInstance && c === "isout") {
if ( parentInstance && c === "isout" ) {
parentInstance.isout = false;
parentInstance.isover = true;
parentInstance._over.call(parentInstance, event);
parentInstance._over.call( parentInstance, event );
}
});
},
dragStop: function( draggable, event ) {
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 ) {
// 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.prepareOffsets( draggable, event );
}
}
};
})(jQuery);
})( jQuery );

View File

@ -797,8 +797,8 @@ $.ui.plugin.add("resizable", "containment", {
isParent = that.containerElement.get(0) === that.element.parent().get(0);
isOffsetRelative = /relative|absolute/.test(that.containerElement.css("position"));
if(isParent && isOffsetRelative) {
woset -= that.parentData.left;
if ( isParent && isOffsetRelative ) {
woset -= Math.abs( that.parentData.left );
}
if (woset + that.size.width >= that.parentData.width) {