Widget: Style updates

Ref #14246
This commit is contained in:
Alexander Schmitz 2015-08-24 09:32:13 -04:00
parent 14b3b607e5
commit e021e4d6e2
5 changed files with 317 additions and 298 deletions

View File

@ -3,7 +3,7 @@ define( [
"ui/widget"
], function( $ ) {
module( "widget animation", (function() {
module( "widget animation", ( function() {
var show = $.fn.show,
fadeIn = $.fn.fadeIn,
slideDown = $.fn.slideDown;
@ -16,7 +16,7 @@ module( "widget animation", (function() {
show: function( fn ) {
this._show( this.element, this.options.show, fn );
}
});
} );
$.effects = { effect: { testEffect: $.noop } };
},
teardown: function() {
@ -27,7 +27,7 @@ module( "widget animation", (function() {
$.fn.slideDown = slideDown;
}
};
}()));
}() ) );
asyncTest( "show: null", function() {
expect( 4 );
@ -41,223 +41,223 @@ asyncTest( "show: null", function() {
element
.delay( 50 )
.queue(function( next ) {
.queue( function( next ) {
ok( !hasRun, "queue before show" );
next();
})
} )
.testWidget( "show", function() {
hasRun = true;
})
.queue(function( next ) {
} )
.queue( function( next ) {
ok( hasRun, "queue after show" );
start();
next();
});
});
} );
} );
asyncTest( "show: true", function() {
expect( 4 );
var element = $( "#widget" ).testWidget({
var element = $( "#widget" ).testWidget( {
show: true
}),
} ),
hasRun = false;
$.fn.fadeIn = function( duration, easing, complete ) {
return this.queue(function( next ) {
return this.queue( function( next ) {
strictEqual( duration, undefined, "duration" );
strictEqual( easing, undefined, "easing" );
complete();
next();
});
} );
};
element
.delay( 50 )
.queue(function( next ) {
.queue( function( next ) {
ok( !hasRun, "queue before show" );
next();
})
} )
.testWidget( "show", function() {
hasRun = true;
})
.queue(function( next ) {
} )
.queue( function( next ) {
ok( hasRun, "queue after show" );
start();
next();
});
});
} );
} );
asyncTest( "show: number", function() {
expect( 4 );
var element = $( "#widget" ).testWidget({
var element = $( "#widget" ).testWidget( {
show: 123
}),
} ),
hasRun = false;
$.fn.fadeIn = function( duration, easing, complete ) {
return this.queue(function( next ) {
return this.queue( function( next ) {
strictEqual( duration, 123, "duration" );
strictEqual( easing, undefined, "easing" );
complete();
next();
});
} );
};
element
.delay( 50 )
.queue(function( next ) {
.queue( function( next ) {
ok( !hasRun, "queue before show" );
next();
})
} )
.testWidget( "show", function() {
hasRun = true;
})
.queue(function( next ) {
} )
.queue( function( next ) {
ok( hasRun, "queue after show" );
start();
next();
});
});
} );
} );
asyncTest( "show: core animation", function() {
expect( 4 );
var element = $( "#widget" ).testWidget({
var element = $( "#widget" ).testWidget( {
show: "slideDown"
}),
} ),
hasRun = false;
$.fn.slideDown = function( duration, easing, complete ) {
return this.queue(function( next ) {
return this.queue( function( next ) {
strictEqual( duration, undefined, "duration" );
strictEqual( easing, undefined, "easing" );
complete();
next();
});
} );
};
element
.delay( 50 )
.queue(function( next ) {
.queue( function( next ) {
ok( !hasRun, "queue before show" );
next();
})
} )
.testWidget( "show", function() {
hasRun = true;
})
.queue(function( next ) {
} )
.queue( function( next ) {
ok( hasRun, "queue after show" );
start();
next();
});
});
} );
} );
asyncTest( "show: effect", function() {
expect( 5 );
var element = $( "#widget" ).testWidget({
var element = $( "#widget" ).testWidget( {
show: "testEffect"
}),
} ),
hasRun = false;
$.fn.show = function( options ) {
return this.queue(function( next ) {
return this.queue( function( next ) {
equal( options.effect, "testEffect", "effect" );
ok( !("duration" in options), "duration" );
ok( !("easing" in options), "easing" );
ok( !( "duration" in options ), "duration" );
ok( !( "easing" in options ), "easing" );
options.complete();
next();
});
} );
};
element
.delay( 50 )
.queue(function( next ) {
.queue( function( next ) {
ok( !hasRun, "queue before show" );
next();
})
} )
.testWidget( "show", function() {
hasRun = true;
})
.queue(function( next ) {
} )
.queue( function( next ) {
ok( hasRun, "queue after show" );
start();
next();
});
});
} );
} );
asyncTest( "show: object(core animation)", function() {
expect( 4 );
var element = $( "#widget" ).testWidget({
var element = $( "#widget" ).testWidget( {
show: {
effect: "slideDown",
duration: 123,
easing: "testEasing"
}
}),
} ),
hasRun = false;
$.fn.slideDown = function( duration, easing, complete ) {
return this.queue(function( next ) {
return this.queue( function( next ) {
equal( duration, 123, "duration" );
equal( easing, "testEasing", "easing" );
complete();
next();
});
} );
};
element
.delay( 50 )
.queue(function( next ) {
.queue( function( next ) {
ok( !hasRun, "queue before show" );
next();
})
} )
.testWidget( "show", function() {
hasRun = true;
})
.queue(function( next ) {
} )
.queue( function( next ) {
ok( hasRun, "queue after show" );
start();
next();
});
});
} );
} );
asyncTest( "show: object(effect)", function() {
expect( 3 );
var element = $( "#widget" ).testWidget({
var element = $( "#widget" ).testWidget( {
show: {
effect: "testEffect",
duration: 123,
easing: "testEasing"
}
}),
} ),
hasRun = false;
$.fn.show = function( options ) {
return this.queue(function( next ) {
return this.queue( function( next ) {
deepEqual( options, {
effect: "testEffect",
duration: 123,
easing: "testEasing",
complete: options.complete
});
} );
options.complete();
next();
});
} );
};
element
.delay( 50 )
.queue(function( next ) {
.queue( function( next ) {
ok( !hasRun, "queue before show" );
next();
})
} )
.testWidget( "show", function() {
hasRun = true;
})
.queue(function( next ) {
} )
.queue( function( next ) {
ok( hasRun, "queue after show" );
start();
next();
});
});
} );
} );
} );

View File

@ -48,13 +48,13 @@ module( "widget factory classes", {
this.span.remove();
this.element.unwrap();
}
});
} );
},
teardown: function() {
delete $.ui.classesWidget;
delete $.fn.classesWidget;
}
});
} );
function elementHasClasses( widget, method, assert ) {
var toggle = method === "toggle" ? ( ", true" ) : "";
@ -96,13 +96,13 @@ test( ".option() - classes setter", function( assert ) {
elementHasClasses( testWidget.element, "add", assert );
testWidget.option({
testWidget.option( {
classes: {
"ui-classes-span": "custom-theme-span",
"ui-classes-widget": "ui-theme-widget custom-theme-widget",
"ui-classes-element": "ui-theme-element-2"
}
});
} );
assert.lacksClasses( testWidget.element, "ui-theme-element",
"Removing a class from the value removes the class" );
@ -116,15 +116,15 @@ test( ".option() - classes setter", function( assert ) {
"Adding a class to an empty value works as expected" );
assert.hasClasses( testWidget.wrapper, "ui-classes-widget custom-theme-widget",
"Appending a class to the current value works as expected" );
});
} );
test( ".destroy() - class removal", function( assert ) {
expect( 1 );
assert.domEqual( "#widget", function() {
$( "#widget" ).classesWidget().classesWidget( "destroy" );
});
});
} );
} );
test( "._add/_remove/_toggleClass()", function( assert ) {
expect( 24 );
@ -141,6 +141,6 @@ test( "._add/_remove/_toggleClass()", function( assert ) {
widget.classesWidget( "removeClasses" );
elementLacksClasses( widget, "remove", assert );
});
} );
} );

File diff suppressed because it is too large Load Diff

View File

@ -16,7 +16,7 @@ test( "$.widget.extend()", function() {
deep2 = { foo: { baz: true }, foo2: document },
deep2copy = { foo: { baz: true }, foo2: document },
deepmerged = { foo: { bar: true, baz: true }, foo2: document },
arr = [1, 2, 3],
arr = [ 1, 2, 3 ],
nestedarray = { arr: arr },
defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
@ -35,8 +35,8 @@ test( "$.widget.extend()", function() {
deepEqual( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" );
equal( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" );
strictEqual( $.widget.extend({}, nestedarray).arr, arr, "Don't clone arrays" );
ok( $.isPlainObject( $.widget.extend({ arr: arr }, { arr: {} }).arr ), "Cloned object heve to be an plain object" );
strictEqual( $.widget.extend( {}, nestedarray ).arr, arr, "Don't clone arrays" );
ok( $.isPlainObject( $.widget.extend( { arr: arr }, { arr: {} } ).arr ), "Cloned object heve to be an plain object" );
empty = {};
optionsWithLength = { foo: { length: -1 } };
@ -56,29 +56,29 @@ test( "$.widget.extend()", function() {
strictEqual( empty.foo.date, customObject, "Custom objects copy correctly (no methods)" );
// Makes the class a little more realistic
myKlass.prototype = { someMethod: function(){} };
myKlass.prototype = { someMethod: function() {} };
empty = {};
$.widget.extend( empty, optionsWithCustomObject );
strictEqual( empty.foo.date, customObject, "Custom objects copy correctly" );
ret = $.widget.extend({ foo: 4 }, { foo: Number(5) } );
ret = $.widget.extend( { foo: 4 }, { foo: Number( 5 ) } );
equal( ret.foo, 5, "Wrapped numbers copy correctly" );
nullUndef = $.widget.extend( {}, options, { xnumber2: null } );
strictEqual( nullUndef.xnumber2, null, "Check to make sure null values are copied");
strictEqual( nullUndef.xnumber2, null, "Check to make sure null values are copied" );
nullUndef = $.widget.extend( {}, options, { xnumber2: undefined } );
strictEqual( nullUndef.xnumber2, options.xnumber2, "Check to make sure undefined values are not copied");
strictEqual( nullUndef.xnumber2, options.xnumber2, "Check to make sure undefined values are not copied" );
nullUndef = $.widget.extend( {}, options, { xnumber0: null } );
strictEqual( nullUndef.xnumber0, null, "Check to make sure null values are inserted");
strictEqual( nullUndef.xnumber0, null, "Check to make sure null values are inserted" );
target = {};
recursive = { foo:target, bar:5 };
$.widget.extend( target, recursive );
deepEqual( target, { foo: {}, bar: 5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
ret = $.widget.extend( { foo: [] }, { foo: [0] } ); // 1907
ret = $.widget.extend( { foo: [] }, { foo: [ 0 ] } ); // 1907
equal( ret.foo.length, 1, "Check to make sure a value with coersion 'false' copies over when necessary to fix #1907" );
ret = $.widget.extend( { foo: "1,2,3" }, { foo: [ 1, 2, 3 ] } );
@ -105,8 +105,8 @@ test( "$.widget.extend()", function() {
};
output = $.widget.extend( {}, input );
deepEqual( input, output, "don't clone arrays" );
input.key[0] = 10;
input.key[ 0 ] = 10;
deepEqual( input, output, "don't clone arrays" );
});
} );
} );

View File

@ -87,6 +87,7 @@ return $.widget( "ui.accordion", {
}
this._processPanels();
// handle negative values
if ( options.active < 0 ) {
options.active += this.headers.length;
@ -147,6 +148,7 @@ return $.widget( "ui.accordion", {
_setOption: function( key, value ) {
if ( key === "active" ) {
// _activate() will handle invalid values and update this.options
this._activate( value );
return;
@ -238,21 +240,27 @@ return $.widget( "ui.accordion", {
if ( ( options.active === false && options.collapsible === true ) || !this.headers.length ) {
options.active = false;
this.active = $();
// active false only when collapsible is true
} else if ( options.active === false ) {
this._activate( 0 );
// was active, but active panel is gone
} else if ( this.active.length && !$.contains( this.element[ 0 ], this.active[ 0 ] ) ) {
// all remaining panel are disabled
if ( this.headers.length === this.headers.find( ".ui-state-disabled" ).length ) {
options.active = false;
this.active = $();
// activate previous panel
} else {
this._activate( Math.max( 0, options.active - 1 ) );
}
// was active, active panel still exists
} else {
// make sure active index is correct
options.active = this.headers.index( this.active );
}
@ -427,8 +435,10 @@ return $.widget( "ui.accordion", {
event.preventDefault();
if (
// click on active header, but not collapsible
( clickedIsActive && !options.collapsible ) ||
// allow canceling activation
( this._trigger( "beforeActivate", event, eventData ) === false ) ) {
return;
@ -487,6 +497,7 @@ return $.widget( "ui.accordion", {
"aria-selected": "false",
"aria-expanded": "false"
} );
// if we're switching panels, remove the old header from the tab order
// if we're opening from collapsed state, remove the previous header from the tab order
// if we're collapsing, then keep the collapsing header in the tab order
@ -531,6 +542,7 @@ return $.widget( "ui.accordion", {
if ( typeof options === "string" ) {
easing = options;
}
// fall back from options to animation in case of partial down settings
easing = easing || options.easing || animate.easing;
duration = duration || options.duration || animate.duration;