Merge branch 'master' into datepicker

# Conflicts:
#	ui/i18n/datepicker-pt.js
This commit is contained in:
Felix Nagel 2017-08-26 13:08:14 +02:00
commit 1b885ff768
30 changed files with 484 additions and 244 deletions

View File

@ -48,7 +48,7 @@
.autocomplete({ .autocomplete({
delay: 0, delay: 0,
minLength: 0, minLength: 0,
source: $.proxy( this, "_source" ) source: this._source.bind( this )
}) })
.tooltip({ .tooltip({
classes: { classes: {

View File

@ -34,7 +34,7 @@
canvas.width = width; canvas.width = width;
canvas.height = height; canvas.height = height;
var drawHeight = height * 0.8, var drawHeight = height * 0.8,
cradius = 10; cradius = 10,
ctx = canvas.getContext( "2d" ); ctx = canvas.getContext( "2d" );
ctx.fillStyle = "black"; ctx.fillStyle = "black";

View File

@ -181,9 +181,9 @@ function migrateUrl() {
} }
} }
// Load the jQuery 1.7 fixes, if necessary // Load the jQuery fixes, if necessary
if ( parseFloat( parseUrl().jquery ) === 1.7 ) { if ( parseFloat( parseUrl().jquery ) < 3 ) {
modules.push( "ui/jquery-1-7" ); modules.unshift( "ui/jquery-1-7" );
} }
requireTests( modules, noBackCompat ); requireTests( modules, noBackCompat );

View File

@ -59,6 +59,12 @@ domEqual.attributes = [
"title" "title"
]; ];
function camelCase( string ) {
return string.replace( /-([\da-z])/gi, function( all, letter ) {
return letter.toUpperCase();
} );
}
function getElementStyles( elem ) { function getElementStyles( elem ) {
var styles = {}; var styles = {};
var style = elem.ownerDocument.defaultView ? var style = elem.ownerDocument.defaultView ?
@ -71,7 +77,7 @@ function getElementStyles( elem ) {
while ( len-- ) { while ( len-- ) {
key = style[ len ]; key = style[ len ];
if ( typeof style[ key ] === "string" ) { if ( typeof style[ key ] === "string" ) {
styles[ $.camelCase( key ) ] = style[ key ]; styles[ camelCase( key ) ] = style[ key ];
} }
} }

View File

@ -56,6 +56,14 @@
<button id="button1">Button</button> <button id="button1">Button</button>
<a href="#" id="anchor-button">Anchor Button</a> <a href="#" id="anchor-button">Anchor Button</a>
<div class="mixed">
<a href="#" id="mixed-anchor">Anchor</a>
<button id="mixed-button" disabled>Button</button>
<input type="button" value="Button" id="mixed-input">
<input type="checkbox" id="mixed-check" name="check"><label for="mixed-check">Check</label>
<input type="radio" id="mixed-radio" name="radio"><label for="mixed-radio">Radio</label>
</div>
</div> </div>
</body> </body>
</html> </html>

View File

@ -194,4 +194,22 @@ QUnit.test( "icon / icons options properly proxied", function( assert ) {
"Icons secondary option sets iconPosition option to end on init" ); "Icons secondary option sets iconPosition option to end on init" );
} ); } );
QUnit.test( "Calling button on a collection of mixed types works correctly", function( assert ) {
assert.expect( 5 );
var group = $( ".mixed" ).children();
group.button();
$.each( {
anchor: "button",
button: "button",
check: "checkboxradio",
input: "button",
radio: "checkboxradio"
}, function( type, widget ) {
assert.ok( $( "#mixed-" + type )[ widget ]( "instance" ), type + " is a " + widget );
} );
} );
} ); } );

View File

@ -142,7 +142,7 @@ QUnit.test( "uniqueId / removeUniqueId", function( assert ) {
} ); } );
QUnit.test( "Labels", function( assert ) { QUnit.test( "Labels", function( assert ) {
assert.expect( 2 ); assert.expect( 3 );
var expected = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ]; var expected = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ];
var dom = $( "#labels-fragment" ); var dom = $( "#labels-fragment" );
@ -165,6 +165,8 @@ QUnit.test( "Labels", function( assert ) {
// Detach the dom to test on a fragment // Detach the dom to test on a fragment
dom.detach(); dom.detach();
testLabels( "document fragments" ); testLabels( "document fragments" );
assert.equal( $().labels().length, 0, "No element" );
} ); } );
( function() { ( function() {

View File

@ -670,7 +670,9 @@ QUnit.test( "handle keyboard navigation and mouse click on menu with dividers an
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
assert.equal( logOutput(), "keydown,3,4,7", "Keydown focus skips divider and group label" ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
assert.equal( logOutput(), "keydown,1,2,3,4,7", "Keydown focus skips divider and group label" );
ready(); ready();
} }
} ); } );
@ -755,4 +757,26 @@ QUnit.test( "#10571: When typing in a menu, only menu-items should be focused",
} ); } );
} ); } );
QUnit.test( "#15157: Must not focus menu dividers with the keyboard", function( assert ) {
var ready = assert.async();
assert.expect( 6 );
var element = $( "#menu-with-dividers" ).menu( {
focus: function( event, ui ) {
assert.hasClasses( ui.item, "ui-menu-item", "Should have menu item class" );
log( ui.item.text() );
}
} );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
setTimeout( function() {
assert.equal( logOutput(), "beginning,middle,end,beginning,end", "Should wrap around items" );
ready();
} );
} );
} ); } );

View File

@ -323,6 +323,16 @@
<li class="foo"><div>Addyston</div></li> <li class="foo"><div>Addyston</div></li>
<li class="foo"><div>Adelphi</div></li> <li class="foo"><div>Adelphi</div></li>
</ul> </ul>
<ul id="menu-with-dividers">
<li>-</li>
<li>beginning</li>
<li>-</li>
<li>middle</li>
<li>-</li>
<li>end</li>
<li>-</li>
</ul>
</div> </div>
</body> </body>
</html> </html>

View File

@ -434,8 +434,10 @@ QUnit.test( "zIndex, applied to all handles", function( assert ) {
} ); } );
QUnit.test( "setOption handles", function( assert ) { QUnit.test( "setOption handles", function( assert ) {
assert.expect( 15 ); assert.expect( 19 );
// https://bugs.jqueryui.com/ticket/3423
// https://bugs.jqueryui.com/ticket/15084
var target = $( "<div></div>" ).resizable(), var target = $( "<div></div>" ).resizable(),
target2 = $( "<div>" + target2 = $( "<div>" +
"<div class='ui-resizable-handle ui-resizable-e'></div>" + "<div class='ui-resizable-handle ui-resizable-e'></div>" +
@ -470,6 +472,12 @@ QUnit.test( "setOption handles", function( assert ) {
target2.resizable( "option", "handles", "e, s, w" ); target2.resizable( "option", "handles", "e, s, w" );
checkHandles( target2, [ "e", "s", "w" ] ); checkHandles( target2, [ "e", "s", "w" ] );
target.resizable( "destroy" );
checkHandles( target, [ ] );
target2.resizable( "destroy" );
checkHandles( target2, [ "e", "w" ] );
} ); } );
QUnit.test( "alsoResize + containment", function( assert ) { QUnit.test( "alsoResize + containment", function( assert ) {

View File

@ -251,13 +251,13 @@ $.each( [
wrappers = menu.find( "li.ui-menu-item .ui-menu-item-wrapper" ); wrappers = menu.find( "li.ui-menu-item .ui-menu-item-wrapper" );
button.trigger( "click" ); button.trigger( "click" );
wrappers.first().simulate( "mouseover" ).trigger( "click" ); wrappers.first().simulate( "mouseover", { clientX: 2, clientY: 2 } ).trigger( "click" );
assert.equal( element[ 0 ].selectedIndex, 0, "First item is selected" ); assert.equal( element[ 0 ].selectedIndex, 0, "First item is selected" );
button.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); button.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
assert.equal( element[ 0 ].selectedIndex, 0, "No looping beyond first item" ); assert.equal( element[ 0 ].selectedIndex, 0, "No looping beyond first item" );
button.trigger( "click" ); button.trigger( "click" );
wrappers.last().simulate( "mouseover" ).trigger( "click" ); wrappers.last().simulate( "mouseover", { clientX: 3, clientY: 3 } ).trigger( "click" );
assert.equal( element[ 0 ].selectedIndex, wrappers.length - 1, "Last item is selected" ); assert.equal( element[ 0 ].selectedIndex, wrappers.length - 1, "Last item is selected" );
button.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); button.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
assert.equal( element[ 0 ].selectedIndex, wrappers.length - 1, "No looping behind last item" ); assert.equal( element[ 0 ].selectedIndex, wrappers.length - 1, "No looping behind last item" );

View File

@ -89,9 +89,9 @@ QUnit.test( "focus", function( assert ) {
button.trigger( "click" ); button.trigger( "click" );
links = menu.find( "li.ui-menu-item" ); links = menu.find( "li.ui-menu-item" );
optionIndex = 0; optionIndex = 0;
links.eq( optionIndex ).simulate( "mouseover" ); links.eq( optionIndex ).simulate( "mouseover", { clientX: 2, clientY: 2 } );
optionIndex += 1; optionIndex += 1;
links.eq( optionIndex ).simulate( "mouseover" ); links.eq( optionIndex ).simulate( "mouseover", { clientX: 3, clientY: 3 } );
// This tests for unwanted, additional focus event on close // This tests for unwanted, additional focus event on close
that.element.selectmenu( "close" ); that.element.selectmenu( "close" );

View File

@ -5,7 +5,7 @@ define( [
], function( QUnit, $ ) { ], function( QUnit, $ ) {
QUnit.test( "$.widget.extend()", function( assert ) { QUnit.test( "$.widget.extend()", function( assert ) {
assert.expect( 27 ); assert.expect( 28 );
var ret, empty, optionsWithLength, optionsWithDate, myKlass, customObject, optionsWithCustomObject, nullUndef, var ret, empty, optionsWithLength, optionsWithDate, myKlass, customObject, optionsWithCustomObject, nullUndef,
target, recursive, obj, input, output, target, recursive, obj, input, output,
@ -108,6 +108,11 @@ QUnit.test( "$.widget.extend()", function( assert ) {
assert.deepEqual( input, output, "don't clone arrays" ); assert.deepEqual( input, output, "don't clone arrays" );
input.key[ 0 ] = 10; input.key[ 0 ] = 10;
assert.deepEqual( input, output, "don't clone arrays" ); assert.deepEqual( input, output, "don't clone arrays" );
input = Object.create( null );
input.foo = "f";
output = $.widget.extend( {}, input );
assert.deepEqual( input, output, "Object with no prototype" );
} ); } );
} ); } );

View File

@ -17,7 +17,7 @@
z-index: 2; z-index: 2;
width: 1.2em; width: 1.2em;
height: 1.2em; height: 1.2em;
cursor: default; cursor: pointer;
-ms-touch-action: none; -ms-touch-action: none;
touch-action: none; touch-action: none;
} }

View File

@ -23,7 +23,7 @@
factory( jQuery ); factory( jQuery );
} }
} ( function( $ ) { } ( function( $ ) {
return $.extend( $.expr[ ":" ], { return $.extend( $.expr.pseudos, {
data: $.expr.createPseudo ? data: $.expr.createPseudo ?
$.expr.createPseudo( function( dataName ) { $.expr.createPseudo( function( dataName ) {
return function( elem ) { return function( elem ) {

View File

@ -746,6 +746,12 @@ $.each(
} }
); );
function camelCase( string ) {
return string.replace( /-([\da-z])/gi, function( all, letter ) {
return letter.toUpperCase();
} );
}
function getElementStyles( elem ) { function getElementStyles( elem ) {
var key, len, var key, len,
style = elem.ownerDocument.defaultView ? style = elem.ownerDocument.defaultView ?
@ -758,7 +764,7 @@ function getElementStyles( elem ) {
while ( len-- ) { while ( len-- ) {
key = style[ len ]; key = style[ len ];
if ( typeof style[ key ] === "string" ) { if ( typeof style[ key ] === "string" ) {
styles[ $.camelCase( key ) ] = style[ key ]; styles[ camelCase( key ) ] = style[ key ];
} }
} }

View File

@ -73,7 +73,7 @@ function visible( element ) {
return visibility !== "hidden"; return visibility !== "hidden";
} }
$.extend( $.expr[ ":" ], { $.extend( $.expr.pseudos, {
focusable: function( element ) { focusable: function( element ) {
return $.ui.focusable( element, $.attr( element, "tabindex" ) != null ); return $.ui.focusable( element, $.attr( element, "tabindex" ) != null );
} }

14
ui/jquery-1-7.js vendored
View File

@ -1,5 +1,5 @@
/*! /*!
* jQuery UI Support for jQuery core 1.7.x @VERSION * jQuery UI Support for jQuery core 1.7.x and newer @VERSION
* http://jqueryui.com * http://jqueryui.com
* *
* Copyright jQuery Foundation and other contributors * Copyright jQuery Foundation and other contributors
@ -86,4 +86,16 @@ if ( $.fn.jquery.substring( 0, 3 ) === "1.7" ) {
}; };
} }
// Support: jQuery 1.9.x or older
// $.expr[ ":" ] is deprecated.
if ( !$.expr.pseudos ) {
$.expr.pseudos = $.expr[ ":" ];
}
// Support: jQuery 1.11.x or older
// $.unique has been renamed to $.uniqueSort
if ( !$.uniqueSort ) {
$.uniqueSort = $.unique;
}
} ) ); } ) );

View File

@ -27,6 +27,10 @@
return $.fn.labels = function() { return $.fn.labels = function() {
var ancestor, selector, id, labels, ancestors; var ancestor, selector, id, labels, ancestors;
if ( !this.length ) {
return this.pushStack( [] );
}
// Check control.labels first // Check control.labels first
if ( this[ 0 ].labels && this[ 0 ].labels.length ) { if ( this[ 0 ].labels && this[ 0 ].labels.length ) {
return this.pushStack( this[ 0 ].labels ); return this.pushStack( this[ 0 ].labels );

View File

@ -84,9 +84,9 @@ $.position = {
return cachedScrollbarWidth; return cachedScrollbarWidth;
} }
var w1, w2, var w1, w2,
div = $( "<div " + div = $( "<div style=" +
"style='display:block;position:absolute;width:50px;height:50px;overflow:hidden;'>" + "'display:block;position:absolute;width:200px;height:200px;overflow:hidden;'>" +
"<div style='height:100px;width:auto;'></div></div>" ), "<div style='height:300px;width:auto;'></div></div>" ),
innerDiv = div.children()[ 0 ]; innerDiv = div.children()[ 0 ];
$( "body" ).append( div ); $( "body" ).append( div );

View File

@ -24,7 +24,7 @@
} }
} ( function( $ ) { } ( function( $ ) {
return $.extend( $.expr[ ":" ], { return $.extend( $.expr.pseudos, {
tabbable: function( element ) { tabbable: function( element ) {
var tabIndex = $.attr( element, "tabindex" ), var tabIndex = $.attr( element, "tabindex" ),
hasTabindex = tabIndex != null; hasTabindex = tabIndex != null;

View File

@ -26,6 +26,7 @@
}( function( $ ) { }( function( $ ) {
var widgetUuid = 0; var widgetUuid = 0;
var widgetHasOwnProperty = Array.prototype.hasOwnProperty;
var widgetSlice = Array.prototype.slice; var widgetSlice = Array.prototype.slice;
$.cleanData = ( function( orig ) { $.cleanData = ( function( orig ) {
@ -64,7 +65,7 @@ $.widget = function( name, base, prototype ) {
} }
// Create selector for plugin // Create selector for plugin
$.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) { $.expr.pseudos[ fullName.toLowerCase() ] = function( elem ) {
return !!$.data( elem, fullName ); return !!$.data( elem, fullName );
}; };
@ -183,7 +184,7 @@ $.widget.extend = function( target ) {
for ( ; inputIndex < inputLength; inputIndex++ ) { for ( ; inputIndex < inputLength; inputIndex++ ) {
for ( key in input[ inputIndex ] ) { for ( key in input[ inputIndex ] ) {
value = input[ inputIndex ][ key ]; value = input[ inputIndex ][ key ];
if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) { if ( widgetHasOwnProperty.call( input[ inputIndex ], key ) && value !== undefined ) {
// Clone objects // Clone objects
if ( $.isPlainObject( value ) ) { if ( $.isPlainObject( value ) ) {
@ -493,12 +494,30 @@ $.Widget.prototype = {
classes: this.options.classes || {} classes: this.options.classes || {}
}, options ); }, options );
function bindRemoveEvent() {
options.element.each( function( _, element ) {
var isTracked = $.map( that.classesElementLookup, function( elements ) {
return elements;
} )
.some( function( elements ) {
return elements.is( element );
} );
if ( !isTracked ) {
that._on( $( element ), {
remove: "_untrackClassesElement"
} );
}
} );
}
function processClassString( classes, checkOption ) { function processClassString( classes, checkOption ) {
var current, i; var current, i;
for ( i = 0; i < classes.length; i++ ) { for ( i = 0; i < classes.length; i++ ) {
current = that.classesElementLookup[ classes[ i ] ] || $(); current = that.classesElementLookup[ classes[ i ] ] || $();
if ( options.add ) { if ( options.add ) {
current = $( $.unique( current.get().concat( options.element.get() ) ) ); bindRemoveEvent();
current = $( $.uniqueSort( current.get().concat( options.element.get() ) ) );
} else { } else {
current = $( current.not( options.element ).get() ); current = $( current.not( options.element ).get() );
} }
@ -510,10 +529,6 @@ $.Widget.prototype = {
} }
} }
this._on( options.element, {
"remove": "_untrackClassesElement"
} );
if ( options.keys ) { if ( options.keys ) {
processClassString( options.keys.match( /\S+/g ) || [], true ); processClassString( options.keys.match( /\S+/g ) || [], true );
} }
@ -531,6 +546,8 @@ $.Widget.prototype = {
that.classesElementLookup[ key ] = $( value.not( event.target ).get() ); that.classesElementLookup[ key ] = $( value.not( event.target ).get() );
} }
} ); } );
this._off( $( event.target ) );
}, },
_removeClass: function( element, keys, extra ) { _removeClass: function( element, keys, extra ) {
@ -611,7 +628,7 @@ $.Widget.prototype = {
_off: function( element, eventName ) { _off: function( element, eventName ) {
eventName = ( eventName || "" ).split( " " ).join( this.eventNamespace + " " ) + eventName = ( eventName || "" ).split( " " ).join( this.eventNamespace + " " ) +
this.eventNamespace; this.eventNamespace;
element.off( eventName ).off( eventName ); element.off( eventName );
// Clear the stack to avoid memory leaks (#10056) // Clear the stack to avoid memory leaks (#10056)
this.bindings = $( this.bindings.not( element ).get() ); this.bindings = $( this.bindings.not( element ).get() );

View File

@ -447,7 +447,7 @@ $.widget( "ui.autocomplete", {
_response: function() { _response: function() {
var index = ++this.requestIndex; var index = ++this.requestIndex;
return $.proxy( function( content ) { return function( content ) {
if ( index === this.requestIndex ) { if ( index === this.requestIndex ) {
this.__response( content ); this.__response( content );
} }
@ -456,7 +456,7 @@ $.widget( "ui.autocomplete", {
if ( !this.pending ) { if ( !this.pending ) {
this._removeClass( "ui-autocomplete-loading" ); this._removeClass( "ui-autocomplete-loading" );
} }
}, this ); }.bind( this );
}, },
__response: function( content ) { __response: function( content ) {

View File

@ -342,22 +342,81 @@ if ( $.uiBackCompat !== false ) {
} ); } );
$.fn.button = ( function( orig ) { $.fn.button = ( function( orig ) {
return function() { return function( options ) {
if ( !this.length || ( this.length && this[ 0 ].tagName !== "INPUT" ) || var isMethodCall = typeof options === "string";
( this.length && this[ 0 ].tagName === "INPUT" && ( var args = Array.prototype.slice.call( arguments, 1 );
this.attr( "type" ) !== "checkbox" && this.attr( "type" ) !== "radio" var returnValue = this;
) ) ) {
return orig.apply( this, arguments ); if ( isMethodCall ) {
// If this is an empty collection, we need to have the instance method
// return undefined instead of the jQuery instance
if ( !this.length && options === "instance" ) {
returnValue = undefined;
} else {
this.each( function() {
var methodValue;
var type = $( this ).attr( "type" );
var name = type !== "checkbox" && type !== "radio" ?
"button" :
"checkboxradio";
var instance = $.data( this, "ui-" + name );
if ( options === "instance" ) {
returnValue = instance;
return false;
} }
if ( !$.ui.checkboxradio ) {
$.error( "Checkboxradio widget missing" ); if ( !instance ) {
return $.error( "cannot call methods on button" +
" prior to initialization; " +
"attempted to call method '" + options + "'" );
}
if ( !$.isFunction( instance[ options ] ) || options.charAt( 0 ) === "_" ) {
return $.error( "no such method '" + options + "' for button" +
" widget instance" );
}
methodValue = instance[ options ].apply( instance, args );
if ( methodValue !== instance && methodValue !== undefined ) {
returnValue = methodValue && methodValue.jquery ?
returnValue.pushStack( methodValue.get() ) :
methodValue;
return false;
} }
if ( arguments.length === 0 ) {
return this.checkboxradio( {
"icon": false
} ); } );
} }
return this.checkboxradio.apply( this, arguments ); } else {
// Allow multiple hashes to be passed on init
if ( args.length ) {
options = $.widget.extend.apply( null, [ options ].concat( args ) );
}
this.each( function() {
var type = $( this ).attr( "type" );
var name = type !== "checkbox" && type !== "radio" ? "button" : "checkboxradio";
var instance = $.data( this, "ui-" + name );
if ( instance ) {
instance.option( options || {} );
if ( instance._init ) {
instance._init();
}
} else {
if ( name === "button" ) {
orig.call( $( this ), options );
return;
}
$( this ).checkboxradio( $.extend( { icon: false }, options ) );
}
} );
}
return returnValue;
}; };
} )( $.fn.button ); } )( $.fn.button );

View File

@ -150,7 +150,7 @@ return $.widget( "ui.controlgroup", {
} ); } );
} ); } );
this.childWidgets = $( $.unique( childWidgets ) ); this.childWidgets = $( $.uniqueSort( childWidgets ) );
this._addClass( this.childWidgets, "ui-controlgroup-item" ); this._addClass( this.childWidgets, "ui-controlgroup-item" );
}, },

View File

@ -289,7 +289,7 @@ $.widget( "ui.dialog", {
that._trigger( "focus" ); that._trigger( "focus" );
} ); } );
// Track the dialog immediately upon openening in case a focus event // Track the dialog immediately upon opening in case a focus event
// somehow occurs outside of the dialog before an element inside the // somehow occurs outside of the dialog before an element inside the
// dialog is focused (#10152) // dialog is focused (#10152)
this._makeFocusTarget(); this._makeFocusTarget();
@ -863,20 +863,19 @@ $.widget( "ui.dialog", {
if ( !this.document.data( "ui-dialog-overlays" ) ) { if ( !this.document.data( "ui-dialog-overlays" ) ) {
// Prevent use of anchors and inputs // Prevent use of anchors and inputs
// Using _on() for an event handler shared across many instances is // This doesn't use `_on()` because it is a shared event handler
// safe because the dialogs stack and must be closed in reverse order // across all open modal dialogs.
this._on( this.document, { this.document.on( "focusin.ui-dialog", function( event ) {
focusin: function( event ) {
if ( isOpening ) { if ( isOpening ) {
return; return;
} }
if ( !this._allowInteraction( event ) ) { var instance = this._trackingInstances()[ 0 ];
if ( !instance._allowInteraction( event ) ) {
event.preventDefault(); event.preventDefault();
this._trackingInstances()[ 0 ]._focusTabbable(); instance._focusTabbable();
} }
} }.bind( this ) );
} );
} }
this.overlay = $( "<div>" ) this.overlay = $( "<div>" )
@ -899,7 +898,7 @@ $.widget( "ui.dialog", {
var overlays = this.document.data( "ui-dialog-overlays" ) - 1; var overlays = this.document.data( "ui-dialog-overlays" ) - 1;
if ( !overlays ) { if ( !overlays ) {
this._off( this.document, "focusin" ); this.document.off( "focusin.ui-dialog" );
this.document.removeData( "ui-dialog-overlays" ); this.document.removeData( "ui-dialog-overlays" );
} else { } else {
this.document.data( "ui-dialog-overlays", overlays ); this.document.data( "ui-dialog-overlays", overlays );

View File

@ -64,6 +64,7 @@ return $.widget( "ui.menu", {
// Flag used to prevent firing of the click handler // Flag used to prevent firing of the click handler
// as the event bubbles up through nested menus // as the event bubbles up through nested menus
this.mouseHandled = false; this.mouseHandled = false;
this.lastMousePosition = { x: null, y: null };
this.element this.element
.uniqueId() .uniqueId()
.attr( { .attr( {
@ -78,6 +79,8 @@ return $.widget( "ui.menu", {
// them (focus should always stay on UL during navigation). // them (focus should always stay on UL during navigation).
"mousedown .ui-menu-item": function( event ) { "mousedown .ui-menu-item": function( event ) {
event.preventDefault(); event.preventDefault();
this._activateItem( event );
}, },
"click .ui-menu-item": function( event ) { "click .ui-menu-item": function( event ) {
var target = $( event.target ); var target = $( event.target );
@ -107,36 +110,15 @@ return $.widget( "ui.menu", {
} }
} }
}, },
"mouseenter .ui-menu-item": function( event ) { "mouseenter .ui-menu-item": "_activateItem",
"mousemove .ui-menu-item": "_activateItem",
// Ignore mouse events while typeahead is active, see #10458.
// Prevents focusing the wrong item when typeahead causes a scroll while the mouse
// is over an item in the menu
if ( this.previousFilter ) {
return;
}
var actualTarget = $( event.target ).closest( ".ui-menu-item" ),
target = $( event.currentTarget );
// Ignore bubbled events on parent items, see #11641
if ( actualTarget[ 0 ] !== target[ 0 ] ) {
return;
}
// Remove ui-state-active class from siblings of the newly focused menu item
// to avoid a jump caused by adjacent elements both having a class with a border
this._removeClass( target.siblings().children( ".ui-state-active" ),
null, "ui-state-active" );
this.focus( event, target );
},
mouseleave: "collapseAll", mouseleave: "collapseAll",
"mouseleave .ui-menu": "collapseAll", "mouseleave .ui-menu": "collapseAll",
focus: function( event, keepActiveItem ) { focus: function( event, keepActiveItem ) {
// If there's already an active item, keep it active // If there's already an active item, keep it active
// If not, activate the first item // If not, activate the first item
var item = this.active || this.element.find( this.options.items ).eq( 0 ); var item = this.active || this._menuItems().first();
if ( !keepActiveItem ) { if ( !keepActiveItem ) {
this.focus( event, item ); this.focus( event, item );
@ -162,7 +144,7 @@ return $.widget( "ui.menu", {
this._on( this.document, { this._on( this.document, {
click: function( event ) { click: function( event ) {
if ( this._closeOnDocumentClick( event ) ) { if ( this._closeOnDocumentClick( event ) ) {
this.collapseAll( event ); this.collapseAll( event, true );
} }
// Reset the mouseHandled flag // Reset the mouseHandled flag
@ -171,6 +153,46 @@ return $.widget( "ui.menu", {
} ); } );
}, },
_activateItem: function( event ) {
// Ignore mouse events while typeahead is active, see #10458.
// Prevents focusing the wrong item when typeahead causes a scroll while the mouse
// is over an item in the menu
if ( this.previousFilter ) {
return;
}
// If the mouse didn't actually move, but the page was scrolled, ignore the event (#9356)
if ( event.clientX === this.lastMousePosition.x &&
event.clientY === this.lastMousePosition.y ) {
return;
}
this.lastMousePosition = {
x: event.clientX,
y: event.clientY
};
var actualTarget = $( event.target ).closest( ".ui-menu-item" ),
target = $( event.currentTarget );
// Ignore bubbled events on parent items, see #11641
if ( actualTarget[ 0 ] !== target[ 0 ] ) {
return;
}
// If the item is already active, there's nothing to do
if ( target.is( ".ui-state-active" ) ) {
return;
}
// Remove ui-state-active class from siblings of the newly focused menu item
// to avoid a jump caused by adjacent elements both having a class with a border
this._removeClass( target.siblings().children( ".ui-state-active" ),
null, "ui-state-active" );
this.focus( event, target );
},
_destroy: function() { _destroy: function() {
var items = this.element.find( ".ui-menu-item" ) var items = this.element.find( ".ui-menu-item" )
.removeAttr( "role aria-disabled" ), .removeAttr( "role aria-disabled" ),
@ -502,7 +524,7 @@ return $.widget( "ui.menu", {
this._removeClass( currentMenu.find( ".ui-state-active" ), null, "ui-state-active" ); this._removeClass( currentMenu.find( ".ui-state-active" ), null, "ui-state-active" );
this.activeMenu = currentMenu; this.activeMenu = currentMenu;
}, this.delay ); }, all ? 0 : this.delay );
}, },
// With no arguments, closes the currently active menu - if nothing is active // With no arguments, closes the currently active menu - if nothing is active
@ -538,11 +560,7 @@ return $.widget( "ui.menu", {
}, },
expand: function( event ) { expand: function( event ) {
var newItem = this.active && var newItem = this.active && this._menuItems( this.active.children( ".ui-menu" ) ).first();
this.active
.children( ".ui-menu " )
.find( this.options.items )
.first();
if ( newItem && newItem.length ) { if ( newItem && newItem.length ) {
this._open( newItem.parent() ); this._open( newItem.parent() );
@ -570,21 +588,27 @@ return $.widget( "ui.menu", {
return this.active && !this.active.nextAll( ".ui-menu-item" ).length; return this.active && !this.active.nextAll( ".ui-menu-item" ).length;
}, },
_menuItems: function( menu ) {
return ( menu || this.element )
.find( this.options.items )
.filter( ".ui-menu-item" );
},
_move: function( direction, filter, event ) { _move: function( direction, filter, event ) {
var next; var next;
if ( this.active ) { if ( this.active ) {
if ( direction === "first" || direction === "last" ) { if ( direction === "first" || direction === "last" ) {
next = this.active next = this.active
[ direction === "first" ? "prevAll" : "nextAll" ]( ".ui-menu-item" ) [ direction === "first" ? "prevAll" : "nextAll" ]( ".ui-menu-item" )
.eq( -1 ); .last();
} else { } else {
next = this.active next = this.active
[ direction + "All" ]( ".ui-menu-item" ) [ direction + "All" ]( ".ui-menu-item" )
.eq( 0 ); .first();
} }
} }
if ( !next || !next.length || !this.active ) { if ( !next || !next.length || !this.active ) {
next = this.activeMenu.find( this.options.items )[ filter ](); next = this._menuItems( this.activeMenu )[ filter ]();
} }
this.focus( event, next ); this.focus( event, next );
@ -610,7 +634,7 @@ return $.widget( "ui.menu", {
this.focus( event, item ); this.focus( event, item );
} else { } else {
this.focus( event, this.activeMenu.find( this.options.items ) this.focus( event, this._menuItems( this.activeMenu )
[ !this.active ? "first" : "last" ]() ); [ !this.active ? "first" : "last" ]() );
} }
}, },
@ -634,7 +658,7 @@ return $.widget( "ui.menu", {
this.focus( event, item ); this.focus( event, item );
} else { } else {
this.focus( event, this.activeMenu.find( this.options.items ).first() ); this.focus( event, this._menuItems( this.activeMenu ).first() );
} }
}, },

View File

@ -187,15 +187,14 @@ $.widget( "ui.resizable", $.ui.mouse, {
_destroy: function() { _destroy: function() {
this._mouseDestroy(); this._mouseDestroy();
this._addedHandles.remove();
var wrapper, var wrapper,
_destroy = function( exp ) { _destroy = function( exp ) {
$( exp ) $( exp )
.removeData( "resizable" ) .removeData( "resizable" )
.removeData( "ui-resizable" ) .removeData( "ui-resizable" )
.off( ".resizable" ) .off( ".resizable" );
.find( ".ui-resizable-handle" )
.remove();
}; };
// TODO: Unwrap at same DOM position // TODO: Unwrap at same DOM position

View File

@ -195,6 +195,11 @@ return $.widget( "ui.sortable", $.ui.mouse, {
// mouseCapture // mouseCapture
this.refreshPositions(); this.refreshPositions();
//Prepare the dragged items parent
this.appendTo = $( o.appendTo !== "parent" ?
o.appendTo :
this.currentItem.parent() );
//Create and append the visible helper //Create and append the visible helper
this.helper = this._createHelper( event ); this.helper = this._createHelper( event );
@ -209,9 +214,6 @@ return $.widget( "ui.sortable", $.ui.mouse, {
//Cache the margins of the original element //Cache the margins of the original element
this._cacheMargins(); this._cacheMargins();
//Get the next scrolling parent
this.scrollParent = this.helper.scrollParent();
//The element's absolute position on the page minus margins //The element's absolute position on the page minus margins
this.offset = this.currentItem.offset(); this.offset = this.currentItem.offset();
this.offset = { this.offset = {
@ -236,15 +238,6 @@ return $.widget( "ui.sortable", $.ui.mouse, {
this.helper.css( "position", "absolute" ); this.helper.css( "position", "absolute" );
this.cssPosition = this.helper.css( "position" ); this.cssPosition = this.helper.css( "position" );
$.extend( this.offset, {
parent: this._getParentOffset()
} );
//Generate the original position
this.originalPosition = this._generatePosition( event );
this.originalPageX = event.pageX;
this.originalPageY = event.pageY;
//Adjust the mouse offset relative to the helper if "cursorAt" is supplied //Adjust the mouse offset relative to the helper if "cursorAt" is supplied
( o.cursorAt && this._adjustOffsetFromHelper( o.cursorAt ) ); ( o.cursorAt && this._adjustOffsetFromHelper( o.cursorAt ) );
@ -263,6 +256,13 @@ return $.widget( "ui.sortable", $.ui.mouse, {
//Create the placeholder //Create the placeholder
this._createPlaceholder(); this._createPlaceholder();
//Get the next scrolling parent
this.scrollParent = this.placeholder.scrollParent();
$.extend( this.offset, {
parent: this._getParentOffset()
} );
//Set a containment if given in the options //Set a containment if given in the options
if ( o.containment ) { if ( o.containment ) {
this._setContainment(); this._setContainment();
@ -330,28 +330,30 @@ return $.widget( "ui.sortable", $.ui.mouse, {
this._addClass( this.helper, "ui-sortable-helper" ); this._addClass( this.helper, "ui-sortable-helper" );
// Execute the drag once - this causes the helper not to be visiblebefore getting its //Move the helper, if needed
// correct position if ( !this.helper.parent().is( this.appendTo ) ) {
this.helper.detach().appendTo( this.appendTo );
//Update position
this.offset.parent = this._getParentOffset();
}
//Generate the original position
this.position = this.originalPosition = this._generatePosition( event );
this.originalPageX = event.pageX;
this.originalPageY = event.pageY;
this.lastPositionAbs = this.positionAbs = this._convertPositionTo( "absolute" );
this._mouseDrag( event ); this._mouseDrag( event );
return true; return true;
}, },
_mouseDrag: function( event ) { _scroll: function( event ) {
var i, item, itemElement, intersection, var o = this.options,
o = this.options,
scrolled = false; scrolled = false;
//Compute the helpers position
this.position = this._generatePosition( event );
this.positionAbs = this._convertPositionTo( "absolute" );
if ( !this.lastPositionAbs ) {
this.lastPositionAbs = this.positionAbs;
}
//Do scrolling
if ( this.options.scroll ) {
if ( this.scrollParent[ 0 ] !== this.document[ 0 ] && if ( this.scrollParent[ 0 ] !== this.document[ 0 ] &&
this.scrollParent[ 0 ].tagName !== "HTML" ) { this.scrollParent[ 0 ].tagName !== "HTML" ) {
@ -395,12 +397,15 @@ return $.widget( "ui.sortable", $.ui.mouse, {
} }
if ( scrolled !== false && $.ui.ddmanager && !o.dropBehaviour ) { return scrolled;
$.ui.ddmanager.prepareOffsets( this, event ); },
}
}
//Regenerate the absolute position used for position checks _mouseDrag: function( event ) {
var i, item, itemElement, intersection,
o = this.options;
//Compute the helpers position
this.position = this._generatePosition( event );
this.positionAbs = this._convertPositionTo( "absolute" ); this.positionAbs = this._convertPositionTo( "absolute" );
//Set the helper position //Set the helper position
@ -411,6 +416,29 @@ return $.widget( "ui.sortable", $.ui.mouse, {
this.helper[ 0 ].style.top = this.position.top + "px"; this.helper[ 0 ].style.top = this.position.top + "px";
} }
//Post events to containers
this._contactContainers( event );
if ( this.innermostContainer !== null ) {
//Do scrolling
if ( o.scroll ) {
if ( this._scroll( event ) !== false ) {
//Update item positions used in position checks
this._refreshItemPositions( true );
if ( $.ui.ddmanager && !o.dropBehaviour ) {
$.ui.ddmanager.prepareOffsets( this, event );
}
}
}
this.dragDirection = {
vertical: this._getDragVerticalDirection(),
horizontal: this._getDragHorizontalDirection()
};
//Rearrange //Rearrange
for ( i = this.items.length - 1; i >= 0; i-- ) { for ( i = this.items.length - 1; i >= 0; i-- ) {
@ -437,7 +465,8 @@ return $.widget( "ui.sortable", $.ui.mouse, {
// no useless actions that have been done before // no useless actions that have been done before
// no action if the item moved is the parent of the item checked // no action if the item moved is the parent of the item checked
if ( itemElement !== this.currentItem[ 0 ] && if ( itemElement !== this.currentItem[ 0 ] &&
this.placeholder[ intersection === 1 ? "next" : "prev" ]()[ 0 ] !== itemElement && this.placeholder[ intersection === 1 ?
"next" : "prev" ]()[ 0 ] !== itemElement &&
!$.contains( this.placeholder[ 0 ], itemElement ) && !$.contains( this.placeholder[ 0 ], itemElement ) &&
( this.options.type === "semi-dynamic" ? ( this.options.type === "semi-dynamic" ?
!$.contains( this.element[ 0 ], itemElement ) : !$.contains( this.element[ 0 ], itemElement ) :
@ -447,7 +476,8 @@ return $.widget( "ui.sortable", $.ui.mouse, {
this.direction = intersection === 1 ? "down" : "up"; this.direction = intersection === 1 ? "down" : "up";
if ( this.options.tolerance === "pointer" || this._intersectsWithSides( item ) ) { if ( this.options.tolerance === "pointer" ||
this._intersectsWithSides( item ) ) {
this._rearrange( event, item ); this._rearrange( event, item );
} else { } else {
break; break;
@ -457,9 +487,7 @@ return $.widget( "ui.sortable", $.ui.mouse, {
break; break;
} }
} }
}
//Post events to containers
this._contactContainers( event );
//Interconnect with droppables //Interconnect with droppables
if ( $.ui.ddmanager ) { if ( $.ui.ddmanager ) {
@ -663,8 +691,8 @@ return $.widget( "ui.sortable", $.ui.mouse, {
return false; return false;
} }
verticalDirection = this._getDragVerticalDirection(); verticalDirection = this.dragDirection.vertical;
horizontalDirection = this._getDragHorizontalDirection(); horizontalDirection = this.dragDirection.horizontal;
return this.floating ? return this.floating ?
( ( horizontalDirection === "right" || verticalDirection === "down" ) ? 2 : 1 ) ( ( horizontalDirection === "right" || verticalDirection === "down" ) ? 2 : 1 )
@ -678,8 +706,8 @@ return $.widget( "ui.sortable", $.ui.mouse, {
this.offset.click.top, item.top + ( item.height / 2 ), item.height ), this.offset.click.top, item.top + ( item.height / 2 ), item.height ),
isOverRightHalf = this._isOverAxis( this.positionAbs.left + isOverRightHalf = this._isOverAxis( this.positionAbs.left +
this.offset.click.left, item.left + ( item.width / 2 ), item.width ), this.offset.click.left, item.left + ( item.width / 2 ), item.width ),
verticalDirection = this._getDragVerticalDirection(), verticalDirection = this.dragDirection.vertical,
horizontalDirection = this._getDragHorizontalDirection(); horizontalDirection = this.dragDirection.horizontal;
if ( this.floating && horizontalDirection ) { if ( this.floating && horizontalDirection ) {
return ( ( horizontalDirection === "right" && isOverRightHalf ) || return ( ( horizontalDirection === "right" && isOverRightHalf ) ||
@ -821,26 +849,14 @@ return $.widget( "ui.sortable", $.ui.mouse, {
}, },
refreshPositions: function( fast ) { _refreshItemPositions: function( fast ) {
// Determine whether items are being displayed horizontally
this.floating = this.items.length ?
this.options.axis === "x" || this._isFloating( this.items[ 0 ].item ) :
false;
//This has to be redone because due to the item being moved out/into the offsetParent,
// the offsetParent's position will change
if ( this.offsetParent && this.helper ) {
this.offset.parent = this._getParentOffset();
}
var i, item, t, p; var i, item, t, p;
for ( i = this.items.length - 1; i >= 0; i-- ) { for ( i = this.items.length - 1; i >= 0; i-- ) {
item = this.items[ i ]; item = this.items[ i ];
//We ignore calculating positions of all connected containers when we're not over them //We ignore calculating positions of all connected containers when we're not over them
if ( item.instance !== this.currentContainer && this.currentContainer && if ( this.currentContainer && item.instance !== this.currentContainer &&
item.item[ 0 ] !== this.currentItem[ 0 ] ) { item.item[ 0 ] !== this.currentItem[ 0 ] ) {
continue; continue;
} }
@ -858,6 +874,20 @@ return $.widget( "ui.sortable", $.ui.mouse, {
item.left = p.left; item.left = p.left;
item.top = p.top; item.top = p.top;
} }
},
refreshPositions: function( fast ) {
// Determine whether items are being displayed horizontally
this.floating = this.items.length ?
this.options.axis === "x" || this._isFloating( this.items[ 0 ].item ) :
false;
if ( this.innermostContainer !== null ) {
this._refreshItemPositions( fast );
}
var i, p;
if ( this.options.custom && this.options.custom.refreshContainers ) { if ( this.options.custom && this.options.custom.refreshContainers ) {
this.options.custom.refreshContainers.call( this ); this.options.custom.refreshContainers.call( this );
@ -1003,6 +1033,8 @@ return $.widget( "ui.sortable", $.ui.mouse, {
} }
this.innermostContainer = innermostContainer;
// If no intersecting containers found, return // If no intersecting containers found, return
if ( !innermostContainer ) { if ( !innermostContainer ) {
return; return;
@ -1071,6 +1103,15 @@ return $.widget( "ui.sortable", $.ui.mouse, {
//Update the placeholder //Update the placeholder
this.options.placeholder.update( this.currentContainer, this.placeholder ); this.options.placeholder.update( this.currentContainer, this.placeholder );
//Update scrollParent
this.scrollParent = this.placeholder.scrollParent();
//Update overflowOffset
if ( this.scrollParent[ 0 ] !== this.document[ 0 ] &&
this.scrollParent[ 0 ].tagName !== "HTML" ) {
this.overflowOffset = this.scrollParent.offset();
}
this.containers[ innermostIndex ]._trigger( "over", event, this._uiHash( this ) ); this.containers[ innermostIndex ]._trigger( "over", event, this._uiHash( this ) );
this.containers[ innermostIndex ].containerCache.over = 1; this.containers[ innermostIndex ].containerCache.over = 1;
} }
@ -1086,9 +1127,7 @@ return $.widget( "ui.sortable", $.ui.mouse, {
//Add the helper to the DOM if that didn't happen already //Add the helper to the DOM if that didn't happen already
if ( !helper.parents( "body" ).length ) { if ( !helper.parents( "body" ).length ) {
$( o.appendTo !== "parent" ? this.appendTo[ 0 ].appendChild( helper[ 0 ] );
o.appendTo :
this.currentItem[ 0 ].parentNode )[ 0 ].appendChild( helper[ 0 ] );
} }
if ( helper[ 0 ] === this.currentItem[ 0 ] ) { if ( helper[ 0 ] === this.currentItem[ 0 ] ) {

View File

@ -96,7 +96,7 @@ $.widget( "ui.tabs", {
// Take disabling tabs via class attribute from HTML // Take disabling tabs via class attribute from HTML
// into account and update option properly. // into account and update option properly.
if ( $.isArray( options.disabled ) ) { if ( $.isArray( options.disabled ) ) {
options.disabled = $.unique( options.disabled.concat( options.disabled = $.uniqueSort( options.disabled.concat(
$.map( this.tabs.filter( ".ui-state-disabled" ), function( li ) { $.map( this.tabs.filter( ".ui-state-disabled" ), function( li ) {
return that.tabs.index( li ); return that.tabs.index( li );
} ) } )