aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2019-12-08 22:23:08 +0100
committerMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2019-12-08 22:23:08 +0100
commit98b539171b6e805fa79346a5e9896865e5213b9c (patch)
treef6c296195f081c538f90c96f43f28012670960a5 /ui
parent74f8a0ac952f6f45f773312292baef1c26d81300 (diff)
downloadjquery-ui-98b539171b6e805fa79346a5e9896865e5213b9c.tar.gz
jquery-ui-98b539171b6e805fa79346a5e9896865e5213b9c.zip
All: Migrate away from deprecated/removed Core APIs
Summary of the changes: * Build: Add jQuery 3.2.0-3.4.1 to versions UI can be tested against * Build: Load jQuery & Migrate via HTTPS * Build: Add package-lock.json to .gitignore * Build: Update jQuery Migrate from 3.0.0 to 3.1.0 * Build: Allow to run tests against jQuery 3.x-git * Build: Fix formatting according to JSCS rules * Build: Disable JSCS for the inlined jQuery Color * All: Switch from $.isArray to Array.isArray (jQuery.isArray will be removed in jQuery 4.0) * All: Switch from `$.isFunction( x )` to `typeof x === "function"` (jQuery.isFunction will be removed in jQuery 4.0) * All: Inline jQuery.isWindow as it'll be removed in jQuery 4.0 * Effects: Fix a timing issue in a variable declaration. Previously, a jQuery object was created, chained & assigned to a variable that was then accessed in a callback used inside of this chained definition. Due to a timing difference in when the callback fired for the first time in latest jQuery master, it was being called before the variable was defined. * Tests: Make dialog & draggable unit tests less strict (newest jQuery returns fractional results in some cases, making comparisons fail when there's a tiny difference) * All: Migrate from $.trim to bare String.prototype.trim (jQuery.trim will be deprecated in jQuery 3.5) Closes gh-1901
Diffstat (limited to 'ui')
-rw-r--r--ui/effect.js50
-rw-r--r--ui/position.js12
-rw-r--r--ui/widget.js9
-rw-r--r--ui/widgets/autocomplete.js4
-rw-r--r--ui/widgets/button.js3
-rw-r--r--ui/widgets/controlgroup.js2
-rw-r--r--ui/widgets/dialog.js4
-rw-r--r--ui/widgets/draggable.js6
-rw-r--r--ui/widgets/droppable.js4
-rw-r--r--ui/widgets/menu.js3
-rw-r--r--ui/widgets/resizable.js2
-rw-r--r--ui/widgets/slider.js6
-rw-r--r--ui/widgets/sortable.js12
-rw-r--r--ui/widgets/spinner.js2
-rw-r--r--ui/widgets/tabs.js8
-rw-r--r--ui/widgets/tooltip.js4
16 files changed, 72 insertions, 59 deletions
diff --git a/ui/effect.js b/ui/effect.js
index 2d17affd1..f237556cf 100644
--- a/ui/effect.js
+++ b/ui/effect.js
@@ -39,6 +39,8 @@ $.effects = {
effect: {}
};
+// jscs:disable
+
/*!
* jQuery Color Animations v2.1.2
* https://github.com/jquery/jquery-color
@@ -716,6 +718,8 @@ colors = jQuery.Color.names = {
} )( jQuery );
+// jscs:enable
+
/******************************************************************************/
/****************************** CLASS ANIMATIONS ******************************/
/******************************************************************************/
@@ -1290,7 +1294,7 @@ function _normalizeArguments( effect, options, speed, callback ) {
}
// Catch (effect, callback)
- if ( $.isFunction( options ) ) {
+ if ( typeof options === "function" ) {
callback = options;
speed = null;
options = {};
@@ -1304,7 +1308,7 @@ function _normalizeArguments( effect, options, speed, callback ) {
}
// Catch (effect, options, callback)
- if ( $.isFunction( speed ) ) {
+ if ( typeof speed === "function" ) {
callback = speed;
speed = null;
}
@@ -1338,7 +1342,7 @@ function standardAnimationOption( option ) {
}
// Complete callback
- if ( $.isFunction( option ) ) {
+ if ( typeof option === "function" ) {
return true;
}
@@ -1383,7 +1387,7 @@ $.fn.extend( {
$.effects.saveStyle( el );
}
- if ( $.isFunction( next ) ) {
+ if ( typeof next === "function" ) {
next();
}
};
@@ -1418,11 +1422,11 @@ $.fn.extend( {
}
function done() {
- if ( $.isFunction( complete ) ) {
+ if ( typeof complete === "function" ) {
complete.call( elem[ 0 ] );
}
- if ( $.isFunction( next ) ) {
+ if ( typeof next === "function" ) {
next();
}
}
@@ -1531,22 +1535,24 @@ $.fn.extend( {
width: target.innerWidth()
},
startPosition = element.offset(),
- transfer = $( "<div class='ui-effects-transfer'></div>" )
- .appendTo( "body" )
- .addClass( options.className )
- .css( {
- top: startPosition.top - fixTop,
- left: startPosition.left - fixLeft,
- height: element.innerHeight(),
- width: element.innerWidth(),
- position: targetFixed ? "fixed" : "absolute"
- } )
- .animate( animation, options.duration, options.easing, function() {
- transfer.remove();
- if ( $.isFunction( done ) ) {
- done();
- }
- } );
+ transfer = $( "<div class='ui-effects-transfer'></div>" );
+
+ transfer
+ .appendTo( "body" )
+ .addClass( options.className )
+ .css( {
+ top: startPosition.top - fixTop,
+ left: startPosition.left - fixLeft,
+ height: element.innerHeight(),
+ width: element.innerWidth(),
+ position: targetFixed ? "fixed" : "absolute"
+ } )
+ .animate( animation, options.duration, options.easing, function() {
+ transfer.remove();
+ if ( typeof done === "function" ) {
+ done();
+ }
+ } );
}
} );
diff --git a/ui/position.js b/ui/position.js
index 3994e9acc..2d1969599 100644
--- a/ui/position.js
+++ b/ui/position.js
@@ -48,6 +48,10 @@ function parseCss( element, property ) {
return parseInt( $.css( element, property ), 10 ) || 0;
}
+function isWindow( obj ) {
+ return obj != null && obj === obj.window;
+}
+
function getDimensions( elem ) {
var raw = elem[ 0 ];
if ( raw.nodeType === 9 ) {
@@ -57,7 +61,7 @@ function getDimensions( elem ) {
offset: { top: 0, left: 0 }
};
}
- if ( $.isWindow( raw ) ) {
+ if ( isWindow( raw ) ) {
return {
width: elem.width(),
height: elem.height(),
@@ -119,12 +123,12 @@ $.position = {
},
getWithinInfo: function( element ) {
var withinElement = $( element || window ),
- isWindow = $.isWindow( withinElement[ 0 ] ),
+ isElemWindow = isWindow( withinElement[ 0 ] ),
isDocument = !!withinElement[ 0 ] && withinElement[ 0 ].nodeType === 9,
- hasOffset = !isWindow && !isDocument;
+ hasOffset = !isElemWindow && !isDocument;
return {
element: withinElement,
- isWindow: isWindow,
+ isWindow: isElemWindow,
isDocument: isDocument,
offset: hasOffset ? $( element ).offset() : { left: 0, top: 0 },
scrollLeft: withinElement.scrollLeft(),
diff --git a/ui/widget.js b/ui/widget.js
index c101e59d4..30034f592 100644
--- a/ui/widget.js
+++ b/ui/widget.js
@@ -60,7 +60,7 @@ $.widget = function( name, base, prototype ) {
base = $.Widget;
}
- if ( $.isArray( prototype ) ) {
+ if ( Array.isArray( prototype ) ) {
prototype = $.extend.apply( null, [ {} ].concat( prototype ) );
}
@@ -105,7 +105,7 @@ $.widget = function( name, base, prototype ) {
// inheriting from
basePrototype.options = $.widget.extend( {}, basePrototype.options );
$.each( prototype, function( prop, value ) {
- if ( !$.isFunction( value ) ) {
+ if ( typeof value !== "function" ) {
proxiedPrototype[ prop ] = value;
return;
}
@@ -233,7 +233,8 @@ $.widget.bridge = function( name, object ) {
"attempted to call method '" + options + "'" );
}
- if ( !$.isFunction( instance[ options ] ) || options.charAt( 0 ) === "_" ) {
+ if ( typeof instance[ options ] !== "function" ||
+ options.charAt( 0 ) === "_" ) {
return $.error( "no such method '" + options + "' for " + name +
" widget instance" );
}
@@ -694,7 +695,7 @@ $.Widget.prototype = {
}
this.element.trigger( event, data );
- return !( $.isFunction( callback ) &&
+ return !( typeof callback === "function" &&
callback.apply( this.element[ 0 ], [ event ].concat( data ) ) === false ||
event.isDefaultPrevented() );
}
diff --git a/ui/widgets/autocomplete.js b/ui/widgets/autocomplete.js
index 60d326544..66756820b 100644
--- a/ui/widgets/autocomplete.js
+++ b/ui/widgets/autocomplete.js
@@ -263,7 +263,7 @@ $.widget( "ui.autocomplete", {
// Announce the value in the liveRegion
label = ui.item.attr( "aria-label" ) || item.value;
- if ( label && $.trim( label ).length ) {
+ if ( label && String.prototype.trim.call( label ).length ) {
this.liveRegion.children().hide();
$( "<div>" ).text( label ).appendTo( this.liveRegion );
}
@@ -375,7 +375,7 @@ $.widget( "ui.autocomplete", {
_initSource: function() {
var array, url,
that = this;
- if ( $.isArray( this.options.source ) ) {
+ if ( Array.isArray( this.options.source ) ) {
array = this.options.source;
this.source = function( request, response ) {
response( $.ui.autocomplete.filter( array, request.term ) );
diff --git a/ui/widgets/button.js b/ui/widgets/button.js
index 42cfec06d..3def0f9aa 100644
--- a/ui/widgets/button.js
+++ b/ui/widgets/button.js
@@ -373,7 +373,8 @@ if ( $.uiBackCompat !== false ) {
"attempted to call method '" + options + "'" );
}
- if ( !$.isFunction( instance[ options ] ) || options.charAt( 0 ) === "_" ) {
+ if ( typeof instance[ options ] !== "function" ||
+ options.charAt( 0 ) === "_" ) {
return $.error( "no such method '" + options + "' for button" +
" widget instance" );
}
diff --git a/ui/widgets/controlgroup.js b/ui/widgets/controlgroup.js
index c79f3fcaf..019abbec9 100644
--- a/ui/widgets/controlgroup.js
+++ b/ui/widgets/controlgroup.js
@@ -234,7 +234,7 @@ return $.widget( "ui.controlgroup", {
var result = {};
$.each( classes, function( key ) {
var current = instance.options.classes[ key ] || "";
- current = $.trim( current.replace( controlgroupCornerRegex, "" ) );
+ current = String.prototype.trim.call( current.replace( controlgroupCornerRegex, "" ) );
result[ key ] = ( current + " " + classes[ key ] ).replace( /\s+/g, " " );
} );
return result;
diff --git a/ui/widgets/dialog.js b/ui/widgets/dialog.js
index 01780daf3..e4798e0d7 100644
--- a/ui/widgets/dialog.js
+++ b/ui/widgets/dialog.js
@@ -481,14 +481,14 @@ $.widget( "ui.dialog", {
this.uiDialogButtonPane.remove();
this.uiButtonSet.empty();
- if ( $.isEmptyObject( buttons ) || ( $.isArray( buttons ) && !buttons.length ) ) {
+ if ( $.isEmptyObject( buttons ) || ( Array.isArray( buttons ) && !buttons.length ) ) {
this._removeClass( this.uiDialog, "ui-dialog-buttons" );
return;
}
$.each( buttons, function( name, props ) {
var click, buttonOptions;
- props = $.isFunction( props ) ?
+ props = typeof props === "function" ?
{ click: props, text: name } :
props;
diff --git a/ui/widgets/draggable.js b/ui/widgets/draggable.js
index 9e46c81bb..5f41d2408 100644
--- a/ui/widgets/draggable.js
+++ b/ui/widgets/draggable.js
@@ -296,7 +296,7 @@ $.widget( "ui.draggable", $.ui.mouse, {
if ( ( this.options.revert === "invalid" && !dropped ) ||
( this.options.revert === "valid" && dropped ) ||
- this.options.revert === true || ( $.isFunction( this.options.revert ) &&
+ this.options.revert === true || ( typeof this.options.revert === "function" &&
this.options.revert.call( this.element, dropped ) )
) {
$( this.helper ).animate(
@@ -368,7 +368,7 @@ $.widget( "ui.draggable", $.ui.mouse, {
_createHelper: function( event ) {
var o = this.options,
- helperIsFunction = $.isFunction( o.helper ),
+ helperIsFunction = typeof o.helper === "function",
helper = helperIsFunction ?
$( o.helper.apply( this.element[ 0 ], [ event ] ) ) :
( o.helper === "clone" ?
@@ -407,7 +407,7 @@ $.widget( "ui.draggable", $.ui.mouse, {
if ( typeof obj === "string" ) {
obj = obj.split( " " );
}
- if ( $.isArray( obj ) ) {
+ if ( Array.isArray( obj ) ) {
obj = { left: +obj[ 0 ], top: +obj[ 1 ] || 0 };
}
if ( "left" in obj ) {
diff --git a/ui/widgets/droppable.js b/ui/widgets/droppable.js
index 89bff2511..f98ff2714 100644
--- a/ui/widgets/droppable.js
+++ b/ui/widgets/droppable.js
@@ -57,7 +57,7 @@ $.widget( "ui.droppable", {
this.isover = false;
this.isout = true;
- this.accept = $.isFunction( accept ) ? accept : function( d ) {
+ this.accept = typeof accept === "function" ? accept : function( d ) {
return d.is( accept );
};
@@ -109,7 +109,7 @@ $.widget( "ui.droppable", {
_setOption: function( key, value ) {
if ( key === "accept" ) {
- this.accept = $.isFunction( value ) ? value : function( d ) {
+ this.accept = typeof value === "function" ? value : function( d ) {
return d.is( value );
};
} else if ( key === "scope" ) {
diff --git a/ui/widgets/menu.js b/ui/widgets/menu.js
index 302d202ae..7706ee578 100644
--- a/ui/widgets/menu.js
+++ b/ui/widgets/menu.js
@@ -689,7 +689,8 @@ return $.widget( "ui.menu", {
.filter( ".ui-menu-item" )
.filter( function() {
return regex.test(
- $.trim( $( this ).children( ".ui-menu-item-wrapper" ).text() ) );
+ String.prototype.trim.call(
+ $( this ).children( ".ui-menu-item-wrapper" ).text() ) );
} );
}
} );
diff --git a/ui/widgets/resizable.js b/ui/widgets/resizable.js
index 36dd12514..cb0b1b11d 100644
--- a/ui/widgets/resizable.js
+++ b/ui/widgets/resizable.js
@@ -261,7 +261,7 @@ $.widget( "ui.resizable", $.ui.mouse, {
for ( i = 0; i < n.length; i++ ) {
- handle = $.trim( n[ i ] );
+ handle = String.prototype.trim.call( n[ i ] );
hname = "ui-resizable-" + handle;
axis = $( "<div>" );
this._addClass( axis, "ui-resizable-handle " + hname );
diff --git a/ui/widgets/slider.js b/ui/widgets/slider.js
index 8b0f907f5..e5004573a 100644
--- a/ui/widgets/slider.js
+++ b/ui/widgets/slider.js
@@ -132,7 +132,7 @@ return $.widget( "ui.slider", $.ui.mouse, {
options.values = [ this._valueMin(), this._valueMin() ];
} else if ( options.values.length && options.values.length !== 2 ) {
options.values = [ options.values[ 0 ], options.values[ 0 ] ];
- } else if ( $.isArray( options.values ) ) {
+ } else if ( Array.isArray( options.values ) ) {
options.values = options.values.slice( 0 );
}
}
@@ -395,7 +395,7 @@ return $.widget( "ui.slider", $.ui.mouse, {
}
if ( arguments.length ) {
- if ( $.isArray( arguments[ 0 ] ) ) {
+ if ( Array.isArray( arguments[ 0 ] ) ) {
vals = this.options.values;
newValues = arguments[ 0 ];
for ( i = 0; i < vals.length; i += 1 ) {
@@ -429,7 +429,7 @@ return $.widget( "ui.slider", $.ui.mouse, {
}
}
- if ( $.isArray( this.options.values ) ) {
+ if ( Array.isArray( this.options.values ) ) {
valsLength = this.options.values.length;
}
diff --git a/ui/widgets/sortable.js b/ui/widgets/sortable.js
index 78fad26b9..b7daf00bf 100644
--- a/ui/widgets/sortable.js
+++ b/ui/widgets/sortable.js
@@ -756,7 +756,7 @@ return $.widget( "ui.sortable", $.ui.mouse, {
for ( j = cur.length - 1; j >= 0; j-- ) {
inst = $.data( cur[ j ], this.widgetFullName );
if ( inst && inst !== this && !inst.options.disabled ) {
- queries.push( [ $.isFunction( inst.options.items ) ?
+ queries.push( [ typeof inst.options.items === "function" ?
inst.options.items.call( inst.element ) :
$( inst.options.items, inst.element )
.not( ".ui-sortable-helper" )
@@ -766,7 +766,7 @@ return $.widget( "ui.sortable", $.ui.mouse, {
}
}
- queries.push( [ $.isFunction( this.options.items ) ?
+ queries.push( [ typeof this.options.items === "function" ?
this.options.items
.call( this.element, null, { options: this.options, item: this.currentItem } ) :
$( this.options.items, this.element )
@@ -806,7 +806,7 @@ return $.widget( "ui.sortable", $.ui.mouse, {
var i, j, cur, inst, targetData, _queries, item, queriesLength,
items = this.items,
- queries = [ [ $.isFunction( this.options.items ) ?
+ queries = [ [ typeof this.options.items === "function" ?
this.options.items.call( this.element[ 0 ], event, { item: this.currentItem } ) :
$( this.options.items, this.element ), this ] ],
connectWith = this._connectWith();
@@ -818,7 +818,7 @@ return $.widget( "ui.sortable", $.ui.mouse, {
for ( j = cur.length - 1; j >= 0; j-- ) {
inst = $.data( cur[ j ], this.widgetFullName );
if ( inst && inst !== this && !inst.options.disabled ) {
- queries.push( [ $.isFunction( inst.options.items ) ?
+ queries.push( [ typeof inst.options.items === "function" ?
inst.options.items
.call( inst.element[ 0 ], event, { item: this.currentItem } ) :
$( inst.options.items, inst.element ), inst ] );
@@ -1121,7 +1121,7 @@ return $.widget( "ui.sortable", $.ui.mouse, {
_createHelper: function( event ) {
var o = this.options,
- helper = $.isFunction( o.helper ) ?
+ helper = typeof o.helper === "function" ?
$( o.helper.apply( this.element[ 0 ], [ event, this.currentItem ] ) ) :
( o.helper === "clone" ? this.currentItem.clone() : this.currentItem );
@@ -1155,7 +1155,7 @@ return $.widget( "ui.sortable", $.ui.mouse, {
if ( typeof obj === "string" ) {
obj = obj.split( " " );
}
- if ( $.isArray( obj ) ) {
+ if ( Array.isArray( obj ) ) {
obj = { left: +obj[ 0 ], top: +obj[ 1 ] || 0 };
}
if ( "left" in obj ) {
diff --git a/ui/widgets/spinner.js b/ui/widgets/spinner.js
index 0bc1db230..6b860e785 100644
--- a/ui/widgets/spinner.js
+++ b/ui/widgets/spinner.js
@@ -344,7 +344,7 @@ $.widget( "ui.spinner", {
var incremental = this.options.incremental;
if ( incremental ) {
- return $.isFunction( incremental ) ?
+ return typeof incremental === "function" ?
incremental( i ) :
Math.floor( i * i * i / 50000 - i * i / 500 + 17 * i / 200 + 1 );
}
diff --git a/ui/widgets/tabs.js b/ui/widgets/tabs.js
index 14f94ae83..0eb69ebe1 100644
--- a/ui/widgets/tabs.js
+++ b/ui/widgets/tabs.js
@@ -95,7 +95,7 @@ $.widget( "ui.tabs", {
// Take disabling tabs via class attribute from HTML
// into account and update option properly.
- if ( $.isArray( options.disabled ) ) {
+ if ( Array.isArray( options.disabled ) ) {
options.disabled = $.uniqueSort( options.disabled.concat(
$.map( this.tabs.filter( ".ui-state-disabled" ), function( li ) {
return that.tabs.index( li );
@@ -502,7 +502,7 @@ $.widget( "ui.tabs", {
_setOptionDisabled: function( disabled ) {
var currentItem, li, i;
- if ( $.isArray( disabled ) ) {
+ if ( Array.isArray( disabled ) ) {
if ( !disabled.length ) {
disabled = false;
} else if ( disabled.length === this.anchors.length ) {
@@ -790,7 +790,7 @@ $.widget( "ui.tabs", {
disabled = false;
} else {
index = this._getIndex( index );
- if ( $.isArray( disabled ) ) {
+ if ( Array.isArray( disabled ) ) {
disabled = $.map( disabled, function( num ) {
return num !== index ? num : null;
} );
@@ -816,7 +816,7 @@ $.widget( "ui.tabs", {
if ( $.inArray( index, disabled ) !== -1 ) {
return;
}
- if ( $.isArray( disabled ) ) {
+ if ( Array.isArray( disabled ) ) {
disabled = $.merge( [ index ], disabled ).sort();
} else {
disabled = [ index ];
diff --git a/ui/widgets/tooltip.js b/ui/widgets/tooltip.js
index 9a3a59063..d466410d7 100644
--- a/ui/widgets/tooltip.js
+++ b/ui/widgets/tooltip.js
@@ -72,7 +72,7 @@ $.widget( "ui.tooltip", {
describedby.push( id );
elem
.data( "ui-tooltip-id", id )
- .attr( "aria-describedby", $.trim( describedby.join( " " ) ) );
+ .attr( "aria-describedby", String.prototype.trim.call( describedby.join( " " ) ) );
},
_removeDescribedBy: function( elem ) {
@@ -85,7 +85,7 @@ $.widget( "ui.tooltip", {
}
elem.removeData( "ui-tooltip-id" );
- describedby = $.trim( describedby.join( " " ) );
+ describedby = String.prototype.trim.call( describedby.join( " " ) );
if ( describedby ) {
elem.attr( "aria-describedby", describedby );
} else {