mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Widget: Add classes option and _add/_remove/_toggleClass methods
Fixes #7053 Closes gh-1411
This commit is contained in:
parent
4959c81d80
commit
c192d4086d
@ -2,6 +2,7 @@ TestHelpers.commonWidgetTests( "accordion", {
|
|||||||
defaults: {
|
defaults: {
|
||||||
active: 0,
|
active: 0,
|
||||||
animate: {},
|
animate: {},
|
||||||
|
classes: {},
|
||||||
collapsible: false,
|
collapsible: false,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
event: "click",
|
event: "click",
|
||||||
|
@ -2,6 +2,7 @@ TestHelpers.commonWidgetTests( "autocomplete", {
|
|||||||
defaults: {
|
defaults: {
|
||||||
appendTo: null,
|
appendTo: null,
|
||||||
autoFocus: false,
|
autoFocus: false,
|
||||||
|
classes: {},
|
||||||
delay: 300,
|
delay: 300,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
messages: {
|
messages: {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
TestHelpers.commonWidgetTests( "button", {
|
TestHelpers.commonWidgetTests( "button", {
|
||||||
defaults: {
|
defaults: {
|
||||||
|
classes: {},
|
||||||
disabled: null,
|
disabled: null,
|
||||||
icons: {
|
icons: {
|
||||||
primary: null,
|
primary: null,
|
||||||
|
@ -3,6 +3,7 @@ TestHelpers.commonWidgetTests( "dialog", {
|
|||||||
appendTo: "body",
|
appendTo: "body",
|
||||||
autoOpen: true,
|
autoOpen: true,
|
||||||
buttons: [],
|
buttons: [],
|
||||||
|
classes: {},
|
||||||
closeOnEscape: true,
|
closeOnEscape: true,
|
||||||
closeText: "Close",
|
closeText: "Close",
|
||||||
disabled: false,
|
disabled: false,
|
||||||
|
@ -3,6 +3,7 @@ TestHelpers.commonWidgetTests( "draggable", {
|
|||||||
appendTo: "parent",
|
appendTo: "parent",
|
||||||
axis: false,
|
axis: false,
|
||||||
cancel: "input,textarea,button,select,option",
|
cancel: "input,textarea,button,select,option",
|
||||||
|
classes: {},
|
||||||
connectToSortable: false,
|
connectToSortable: false,
|
||||||
containment: false,
|
containment: false,
|
||||||
cursor: "auto",
|
cursor: "auto",
|
||||||
|
@ -3,6 +3,7 @@ TestHelpers.commonWidgetTests( "droppable", {
|
|||||||
accept: "*",
|
accept: "*",
|
||||||
activeClass: false,
|
activeClass: false,
|
||||||
addClasses: true,
|
addClasses: true,
|
||||||
|
classes: {},
|
||||||
disabled: false,
|
disabled: false,
|
||||||
greedy: false,
|
greedy: false,
|
||||||
hoverClass: false,
|
hoverClass: false,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
TestHelpers.commonWidgetTests( "menu", {
|
TestHelpers.commonWidgetTests( "menu", {
|
||||||
defaults: {
|
defaults: {
|
||||||
|
classes: {},
|
||||||
disabled: false,
|
disabled: false,
|
||||||
icons: {
|
icons: {
|
||||||
submenu: "ui-icon-caret-1-e"
|
submenu: "ui-icon-caret-1-e"
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
TestHelpers.commonWidgetTests( "progressbar", {
|
TestHelpers.commonWidgetTests( "progressbar", {
|
||||||
defaults: {
|
defaults: {
|
||||||
|
classes: {},
|
||||||
disabled: false,
|
disabled: false,
|
||||||
max: 100,
|
max: 100,
|
||||||
value: 0,
|
value: 0,
|
||||||
|
@ -7,6 +7,7 @@ TestHelpers.commonWidgetTests( "resizable", {
|
|||||||
aspectRatio: false,
|
aspectRatio: false,
|
||||||
autoHide: false,
|
autoHide: false,
|
||||||
cancel: "input,textarea,button,select,option",
|
cancel: "input,textarea,button,select,option",
|
||||||
|
classes: {},
|
||||||
containment: false,
|
containment: false,
|
||||||
delay: 0,
|
delay: 0,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
|
@ -3,6 +3,7 @@ TestHelpers.commonWidgetTests("selectable", {
|
|||||||
appendTo: "body",
|
appendTo: "body",
|
||||||
autoRefresh: true,
|
autoRefresh: true,
|
||||||
cancel: "input,textarea,button,select,option",
|
cancel: "input,textarea,button,select,option",
|
||||||
|
classes: {},
|
||||||
delay: 0,
|
delay: 0,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
distance: 0,
|
distance: 0,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
TestHelpers.commonWidgetTests( "selectmenu", {
|
TestHelpers.commonWidgetTests( "selectmenu", {
|
||||||
defaults: {
|
defaults: {
|
||||||
appendTo: null,
|
appendTo: null,
|
||||||
|
classes: {},
|
||||||
disabled: null,
|
disabled: null,
|
||||||
icons: {
|
icons: {
|
||||||
button: "ui-icon-triangle-1-s"
|
button: "ui-icon-triangle-1-s"
|
||||||
|
@ -2,6 +2,7 @@ TestHelpers.commonWidgetTests( "slider", {
|
|||||||
defaults: {
|
defaults: {
|
||||||
animate: false,
|
animate: false,
|
||||||
cancel: "input,textarea,button,select,option",
|
cancel: "input,textarea,button,select,option",
|
||||||
|
classes: {},
|
||||||
delay: 0,
|
delay: 0,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
distance: 0,
|
distance: 0,
|
||||||
|
@ -3,6 +3,7 @@ TestHelpers.commonWidgetTests( "sortable", {
|
|||||||
appendTo: "parent",
|
appendTo: "parent",
|
||||||
axis: false,
|
axis: false,
|
||||||
cancel: "input,textarea,button,select,option",
|
cancel: "input,textarea,button,select,option",
|
||||||
|
classes: {},
|
||||||
connectWith: false,
|
connectWith: false,
|
||||||
containment: false,
|
containment: false,
|
||||||
cursor: "auto",
|
cursor: "auto",
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
TestHelpers.commonWidgetTests( "spinner", {
|
TestHelpers.commonWidgetTests( "spinner", {
|
||||||
defaults: {
|
defaults: {
|
||||||
|
classes: {},
|
||||||
culture: null,
|
culture: null,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
icons: {
|
icons: {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
TestHelpers.commonWidgetTests( "tabs", {
|
TestHelpers.commonWidgetTests( "tabs", {
|
||||||
defaults: {
|
defaults: {
|
||||||
active: null,
|
active: null,
|
||||||
|
classes: {},
|
||||||
collapsible: false,
|
collapsible: false,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
event: "click",
|
event: "click",
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
TestHelpers.commonWidgetTests( "tooltip", {
|
TestHelpers.commonWidgetTests( "tooltip", {
|
||||||
defaults: {
|
defaults: {
|
||||||
|
classes: {},
|
||||||
content: function() {},
|
content: function() {},
|
||||||
disabled: false,
|
disabled: false,
|
||||||
hide: true,
|
hide: true,
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
<script src="../../../external/qunit/qunit.js"></script>
|
<script src="../../../external/qunit/qunit.js"></script>
|
||||||
<script src="../../../external/jquery-simulate/jquery.simulate.js"></script>
|
<script src="../../../external/jquery-simulate/jquery.simulate.js"></script>
|
||||||
<script src="../testsuite.js"></script>
|
<script src="../testsuite.js"></script>
|
||||||
|
<script src="../../../external/qunit-assert-classes/qunit-assert-classes.js"></script>
|
||||||
<script>
|
<script>
|
||||||
TestHelpers.loadResources({
|
TestHelpers.loadResources({
|
||||||
css: [ "core" ],
|
css: [ "core" ],
|
||||||
@ -21,6 +22,7 @@
|
|||||||
<script src="widget_core.js"></script>
|
<script src="widget_core.js"></script>
|
||||||
<script src="widget_extend.js"></script>
|
<script src="widget_extend.js"></script>
|
||||||
<script src="widget_animation.js"></script>
|
<script src="widget_animation.js"></script>
|
||||||
|
<script src="widget_classes.js"></script>
|
||||||
|
|
||||||
<script src="../swarminject.js"></script>
|
<script src="../swarminject.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
143
tests/unit/widget/widget_classes.js
Normal file
143
tests/unit/widget/widget_classes.js
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
(function( $ ) {
|
||||||
|
|
||||||
|
module( "widget factory classes", {
|
||||||
|
setup: function() {
|
||||||
|
$.widget( "ui.classesWidget", {
|
||||||
|
options: {
|
||||||
|
classes: {
|
||||||
|
"ui-classes-widget": "ui-theme-widget",
|
||||||
|
"ui-classes-element": "ui-theme-element ui-theme-element-2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_create: function() {
|
||||||
|
this.span = $( "<span>" )
|
||||||
|
.appendTo( this.element );
|
||||||
|
|
||||||
|
this.element.wrap( "<div>" );
|
||||||
|
|
||||||
|
this.wrapper = this.element.parent();
|
||||||
|
|
||||||
|
this._addClass( "ui-classes-element", "ui-core-element" )
|
||||||
|
._addClass( "ui-classes-element-2" )
|
||||||
|
._addClass( null, "ui-core-element-null" )
|
||||||
|
._addClass( this.span, null, "ui-core-span-null" )
|
||||||
|
._addClass( this.span, "ui-classes-span", "ui-core-span" )
|
||||||
|
._addClass( this.wrapper, "ui-classes-widget" );
|
||||||
|
|
||||||
|
},
|
||||||
|
toggleClasses: function( bool ) {
|
||||||
|
this._toggleClass( "ui-classes-element", "ui-core-element", bool )
|
||||||
|
._toggleClass( "ui-classes-element-2", null, bool )
|
||||||
|
._toggleClass( null, "ui-core-element-null", bool )
|
||||||
|
._toggleClass( this.span, null, "ui-core-span-null", bool )
|
||||||
|
._toggleClass( this.span, "ui-classes-span", "ui-core-span", bool )
|
||||||
|
._toggleClass( this.wrapper, "ui-classes-widget", null, bool );
|
||||||
|
},
|
||||||
|
removeClasses: function() {
|
||||||
|
this._removeClass( "ui-classes-element", "ui-core-element" )
|
||||||
|
._removeClass( "ui-classes-element-2" )
|
||||||
|
._removeClass( null, "ui-core-element-null" )
|
||||||
|
._removeClass( this.span, null, "ui-core-span-null" )
|
||||||
|
._removeClass( this.span, "ui-classes-span", "ui-core-span" )
|
||||||
|
._removeClass( this.wrapper, "ui-classes-widget" );
|
||||||
|
},
|
||||||
|
_destroy: function() {
|
||||||
|
this.span.remove();
|
||||||
|
this.element.unwrap();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
teardown: function() {
|
||||||
|
delete $.ui.classesWidget;
|
||||||
|
delete $.fn.classesWidget;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function elementHasClasses( widget, method, assert ) {
|
||||||
|
var toggle = method === "toggle" ? ( ", true" ) : "";
|
||||||
|
|
||||||
|
assert.hasClasses( widget, "ui-classes-element ui-theme-element ui-theme-element-2",
|
||||||
|
"_" + method + "Class works with ( keys, extra" + toggle + " )" );
|
||||||
|
assert.hasClasses( widget, "ui-classes-element-2",
|
||||||
|
"_" + method + "Class works with ( keys, null" + toggle + " )" );
|
||||||
|
assert.hasClasses( widget, "ui-core-element-null",
|
||||||
|
"_" + method + "Class works with ( null, extra" + toggle + " )" );
|
||||||
|
assert.hasClasses( widget.parent(), "ui-classes-widget ui-theme-widget",
|
||||||
|
"_" + method + "Class works with ( element, null, extra" + toggle + " )" );
|
||||||
|
assert.hasClasses( widget.find( "span" ), "ui-classes-span ui-core-span",
|
||||||
|
"_" + method + "Class works with ( element, keys, extra" + toggle + " )" );
|
||||||
|
assert.hasClasses( widget.find( "span" ), "ui-core-span-null",
|
||||||
|
"_" + method + "Class works with ( element, keys, null" + toggle + " )" );
|
||||||
|
}
|
||||||
|
function elementLacksClasses( widget, method, assert ) {
|
||||||
|
var toggle = method === "toggle" ? ( ", false" ) : "";
|
||||||
|
|
||||||
|
assert.lacksClasses( widget, "ui-classes-element ui-theme-element ui-theme-element-2",
|
||||||
|
"_" + method + "Class works with ( keys, extra" + toggle + " )" );
|
||||||
|
assert.lacksClasses( widget, "ui-classes-element-2",
|
||||||
|
"_" + method + "Class works with ( keys, null" + toggle + " )" );
|
||||||
|
assert.lacksClasses( widget, "ui-core-element-null",
|
||||||
|
"_" + method + "Class works with ( null, extra" + toggle + " )" );
|
||||||
|
assert.lacksClasses( widget.parent(), "ui-classes-widget ui-theme-widget",
|
||||||
|
"_" + method + "Class works with ( element, null, extra" + toggle + " )" );
|
||||||
|
assert.lacksClasses( widget.find( "span" ), "ui-classes-span ui-core-span",
|
||||||
|
"_" + method + "Class works with ( element, keys, extra" + toggle + " )" );
|
||||||
|
assert.lacksClasses( widget.find( "span" ), "ui-core-span-null",
|
||||||
|
"_" + method + "Class works with ( element, keys, null" + toggle + " )" );
|
||||||
|
}
|
||||||
|
|
||||||
|
test( ".option() - classes setter", function( assert ) {
|
||||||
|
expect( 11 );
|
||||||
|
|
||||||
|
var testWidget = $.ui.classesWidget();
|
||||||
|
|
||||||
|
elementHasClasses( testWidget.element, "add", assert );
|
||||||
|
|
||||||
|
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" );
|
||||||
|
|
||||||
|
testWidget.option( "classes.ui-classes-element", "" );
|
||||||
|
assert.hasClasses( testWidget.element, "ui-classes-element",
|
||||||
|
"Setting to empty value leaves structure class" );
|
||||||
|
assert.lacksClasses( testWidget.element, "ui-theme-element-2",
|
||||||
|
"Setting empty value removes previous value classes" );
|
||||||
|
assert.hasClasses( testWidget.span, "ui-classes-span custom-theme-span",
|
||||||
|
"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() {
|
||||||
|
expect( 1 );
|
||||||
|
|
||||||
|
domEqual( "#widget", function() {
|
||||||
|
$( "#widget" ).classesWidget().classesWidget( "destroy" );
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test( "._add/_remove/_toggleClass()", function( assert ) {
|
||||||
|
expect( 24 );
|
||||||
|
|
||||||
|
var widget = $( "#widget" ).classesWidget();
|
||||||
|
|
||||||
|
elementHasClasses( widget, "add", assert );
|
||||||
|
|
||||||
|
widget.classesWidget( "toggleClasses", false );
|
||||||
|
elementLacksClasses( widget, "toggle", assert );
|
||||||
|
|
||||||
|
widget.classesWidget( "toggleClasses", true );
|
||||||
|
elementHasClasses( widget, "toggle", assert );
|
||||||
|
|
||||||
|
widget.classesWidget( "removeClasses" );
|
||||||
|
elementLacksClasses( widget, "remove", assert );
|
||||||
|
});
|
||||||
|
|
||||||
|
}( jQuery ) );
|
@ -227,6 +227,7 @@ test( "merge multiple option arguments", function() {
|
|||||||
$.widget( "ui.testWidget", {
|
$.widget( "ui.testWidget", {
|
||||||
_create: function() {
|
_create: function() {
|
||||||
deepEqual( this.options, {
|
deepEqual( this.options, {
|
||||||
|
classes: {},
|
||||||
create: null,
|
create: null,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
option1: "value1",
|
option1: "value1",
|
||||||
@ -281,6 +282,7 @@ test( "._getCreateOptions()", function() {
|
|||||||
},
|
},
|
||||||
_create: function() {
|
_create: function() {
|
||||||
deepEqual( this.options, {
|
deepEqual( this.options, {
|
||||||
|
classes: {},
|
||||||
create: null,
|
create: null,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
option1: "override1",
|
option1: "override1",
|
||||||
@ -485,10 +487,11 @@ test( ".option() - getter", function() {
|
|||||||
|
|
||||||
options = div.testWidget( "option" );
|
options = div.testWidget( "option" );
|
||||||
deepEqual( options, {
|
deepEqual( options, {
|
||||||
|
baz: 5,
|
||||||
|
classes: {},
|
||||||
create: null,
|
create: null,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
foo: "bar",
|
foo: "bar",
|
||||||
baz: 5,
|
|
||||||
qux: [ "quux", "quuux" ]
|
qux: [ "quux", "quuux" ]
|
||||||
}, "full options hash returned" );
|
}, "full options hash returned" );
|
||||||
options.foo = "notbar";
|
options.foo = "notbar";
|
||||||
|
121
ui/widget.js
121
ui/widget.js
@ -250,6 +250,7 @@ $.Widget.prototype = {
|
|||||||
widgetEventPrefix: "",
|
widgetEventPrefix: "",
|
||||||
defaultElement: "<div>",
|
defaultElement: "<div>",
|
||||||
options: {
|
options: {
|
||||||
|
classes: {},
|
||||||
disabled: false,
|
disabled: false,
|
||||||
|
|
||||||
// callbacks
|
// callbacks
|
||||||
@ -264,6 +265,7 @@ $.Widget.prototype = {
|
|||||||
this.bindings = $();
|
this.bindings = $();
|
||||||
this.hoverable = $();
|
this.hoverable = $();
|
||||||
this.focusable = $();
|
this.focusable = $();
|
||||||
|
this.classesElementLookup = {};
|
||||||
|
|
||||||
if ( element !== this ) {
|
if ( element !== this ) {
|
||||||
$.data( element, this.widgetFullName, this );
|
$.data( element, this.widgetFullName, this );
|
||||||
@ -297,7 +299,13 @@ $.Widget.prototype = {
|
|||||||
_init: $.noop,
|
_init: $.noop,
|
||||||
|
|
||||||
destroy: function() {
|
destroy: function() {
|
||||||
|
var that = this;
|
||||||
|
|
||||||
this._destroy();
|
this._destroy();
|
||||||
|
$.each( this.classesElementLookup, function( key, value ) {
|
||||||
|
that._removeClass( value, key );
|
||||||
|
});
|
||||||
|
|
||||||
// we can probably remove the unbind calls in 2.0
|
// we can probably remove the unbind calls in 2.0
|
||||||
// all event bindings should go through this._on()
|
// all event bindings should go through this._on()
|
||||||
this.element
|
this.element
|
||||||
@ -305,15 +313,10 @@ $.Widget.prototype = {
|
|||||||
.removeData( this.widgetFullName );
|
.removeData( this.widgetFullName );
|
||||||
this.widget()
|
this.widget()
|
||||||
.unbind( this.eventNamespace )
|
.unbind( this.eventNamespace )
|
||||||
.removeAttr( "aria-disabled" )
|
.removeAttr( "aria-disabled" );
|
||||||
.removeClass(
|
|
||||||
this.widgetFullName + "-disabled " +
|
|
||||||
"ui-state-disabled" );
|
|
||||||
|
|
||||||
// clean up events and states
|
// clean up events and states
|
||||||
this.bindings.unbind( this.eventNamespace );
|
this.bindings.unbind( this.eventNamespace );
|
||||||
this.hoverable.removeClass( "ui-state-hover" );
|
|
||||||
this.focusable.removeClass( "ui-state-focus" );
|
|
||||||
},
|
},
|
||||||
_destroy: $.noop,
|
_destroy: $.noop,
|
||||||
|
|
||||||
@ -370,21 +373,54 @@ $.Widget.prototype = {
|
|||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
_setOption: function( key, value ) {
|
_setOption: function( key, value ) {
|
||||||
|
if ( key === "classes" ) {
|
||||||
|
this._setOptionClasses( value );
|
||||||
|
}
|
||||||
|
|
||||||
this.options[ key ] = value;
|
this.options[ key ] = value;
|
||||||
|
|
||||||
if ( key === "disabled" ) {
|
if ( key === "disabled" ) {
|
||||||
this.widget()
|
this._toggleClass( this.widget(), this.widgetFullName + "-disabled", null, !!value );
|
||||||
.toggleClass( this.widgetFullName + "-disabled", !!value );
|
|
||||||
|
|
||||||
// If the widget is becoming disabled, then nothing is interactive
|
// If the widget is becoming disabled, then nothing is interactive
|
||||||
if ( value ) {
|
if ( value ) {
|
||||||
this.hoverable.removeClass( "ui-state-hover" );
|
this._removeClass( this.hoverable, null, "ui-state-hover" );
|
||||||
this.focusable.removeClass( "ui-state-focus" );
|
this._removeClass( this.focusable, null, "ui-state-focus" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
_setOptionClasses: function( value ) {
|
||||||
|
var classKey, elements, currentElements;
|
||||||
|
|
||||||
|
for ( classKey in value ) {
|
||||||
|
currentElements = this.classesElementLookup[ classKey ];
|
||||||
|
if ( value[ classKey ] === this.options.classes[ classKey ] ||
|
||||||
|
!currentElements ||
|
||||||
|
!currentElements.length ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We are doing this to create a new jQuery object because the _removeClass() call
|
||||||
|
// on the next line is going to destroy the reference to the current elements being
|
||||||
|
// tracked. We need to save a copy of this collection so that we can add the new classes
|
||||||
|
// below.
|
||||||
|
elements = $( currentElements.get() );
|
||||||
|
this._removeClass( currentElements, classKey );
|
||||||
|
|
||||||
|
// We don't use _addClass() here, because that uses this.options.classes
|
||||||
|
// for generating the string of classes. We want to use the value passed in from
|
||||||
|
// _setOption(), this is the new value of the classes option which was passed to
|
||||||
|
// _setOption(). We pass this value directly to _classes().
|
||||||
|
elements.addClass( this._classes({
|
||||||
|
element: elements,
|
||||||
|
keys: classKey,
|
||||||
|
classes: value,
|
||||||
|
add: true
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
enable: function() {
|
enable: function() {
|
||||||
return this._setOptions({ disabled: false });
|
return this._setOptions({ disabled: false });
|
||||||
@ -393,6 +429,63 @@ $.Widget.prototype = {
|
|||||||
return this._setOptions({ disabled: true });
|
return this._setOptions({ disabled: true });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_classes: function( options ) {
|
||||||
|
var full = [],
|
||||||
|
that = this;
|
||||||
|
|
||||||
|
options = $.extend({
|
||||||
|
element: this.element,
|
||||||
|
classes: this.options.classes || {}
|
||||||
|
}, options );
|
||||||
|
|
||||||
|
function processClassString( classes, checkOption ) {
|
||||||
|
var current, i;
|
||||||
|
for ( i = 0; i < classes.length; i++ ) {
|
||||||
|
current = that.classesElementLookup[ classes[ i ] ] || $();
|
||||||
|
if ( options.add ) {
|
||||||
|
current = $( $.unique( current.get().concat( options.element.get() ) ) );
|
||||||
|
} else {
|
||||||
|
current = $( current.not( options.element ).get() );
|
||||||
|
}
|
||||||
|
that.classesElementLookup[ classes[ i ] ] = current;
|
||||||
|
full.push( classes[ i ] );
|
||||||
|
if ( checkOption && options.classes[ classes[ i ] ] ) {
|
||||||
|
full.push( options.classes[ classes[ i ] ] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( options.keys ) {
|
||||||
|
processClassString( options.keys.match( /\S+/g ) || [], true );
|
||||||
|
}
|
||||||
|
if ( options.extra ) {
|
||||||
|
processClassString( options.extra.match( /\S+/g ) || [] );
|
||||||
|
}
|
||||||
|
|
||||||
|
return full.join( " " );
|
||||||
|
},
|
||||||
|
|
||||||
|
_removeClass: function( element, keys, extra ) {
|
||||||
|
return this._toggleClass( element, keys, extra, false );
|
||||||
|
},
|
||||||
|
|
||||||
|
_addClass: function( element, keys, extra ) {
|
||||||
|
return this._toggleClass( element, keys, extra, true );
|
||||||
|
},
|
||||||
|
|
||||||
|
_toggleClass: function( element, keys, extra, add ) {
|
||||||
|
add = ( typeof add === "boolean" ) ? add : extra;
|
||||||
|
var shift = ( typeof element === "string" || element === null ),
|
||||||
|
options = {
|
||||||
|
extra: shift ? keys : extra,
|
||||||
|
keys: shift ? element : keys,
|
||||||
|
element: shift ? this.element : element,
|
||||||
|
add: add
|
||||||
|
};
|
||||||
|
options.element.toggleClass( this._classes( options ), add );
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
|
||||||
_on: function( suppressDisabledCheck, element, handlers ) {
|
_on: function( suppressDisabledCheck, element, handlers ) {
|
||||||
var delegateElement,
|
var delegateElement,
|
||||||
instance = this;
|
instance = this;
|
||||||
@ -469,10 +562,10 @@ $.Widget.prototype = {
|
|||||||
this.hoverable = this.hoverable.add( element );
|
this.hoverable = this.hoverable.add( element );
|
||||||
this._on( element, {
|
this._on( element, {
|
||||||
mouseenter: function( event ) {
|
mouseenter: function( event ) {
|
||||||
$( event.currentTarget ).addClass( "ui-state-hover" );
|
this._addClass( $( event.currentTarget ), null, "ui-state-hover" );
|
||||||
},
|
},
|
||||||
mouseleave: function( event ) {
|
mouseleave: function( event ) {
|
||||||
$( event.currentTarget ).removeClass( "ui-state-hover" );
|
this._removeClass( $( event.currentTarget ), null, "ui-state-hover" );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -481,10 +574,10 @@ $.Widget.prototype = {
|
|||||||
this.focusable = this.focusable.add( element );
|
this.focusable = this.focusable.add( element );
|
||||||
this._on( element, {
|
this._on( element, {
|
||||||
focusin: function( event ) {
|
focusin: function( event ) {
|
||||||
$( event.currentTarget ).addClass( "ui-state-focus" );
|
this._addClass( $( event.currentTarget ), null, "ui-state-focus" );
|
||||||
},
|
},
|
||||||
focusout: function( event ) {
|
focusout: function( event ) {
|
||||||
$( event.currentTarget ).removeClass( "ui-state-focus" );
|
this._removeClass( $( event.currentTarget ), null, "ui-state-focus" );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user