mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Merge branch 'data-naming'
This commit is contained in:
commit
f65d6b92cc
@ -32,28 +32,28 @@ test( "element normalization", function() {
|
||||
// workaround for core ticket #8381
|
||||
this.element.appendTo( "#qunit-fixture" );
|
||||
ok( this.element.is( "div" ), "generated div" );
|
||||
deepEqual( this.element.data( "testWidget" ), this, "intance stored in .data()" );
|
||||
deepEqual( this.element.data( "ui-testWidget" ), this, "instance stored in .data()" );
|
||||
};
|
||||
$.ui.testWidget();
|
||||
|
||||
$.ui.testWidget.prototype.defaultElement = "<span data-test='pass'></span>";
|
||||
$.ui.testWidget.prototype._create = function() {
|
||||
ok( this.element.is( "span[data-test=pass]" ), "generated span with properties" );
|
||||
deepEqual( this.element.data( "testWidget" ), this, "instace stored in .data()" );
|
||||
deepEqual( this.element.data( "ui-testWidget" ), this, "instace stored in .data()" );
|
||||
};
|
||||
$.ui.testWidget();
|
||||
|
||||
elem = $( "<input>" );
|
||||
$.ui.testWidget.prototype._create = function() {
|
||||
deepEqual( this.element[ 0 ], elem[ 0 ], "from element" );
|
||||
deepEqual( elem.data( "testWidget" ), this, "instace stored in .data()" );
|
||||
deepEqual( elem.data( "ui-testWidget" ), this, "instace stored in .data()" );
|
||||
};
|
||||
$.ui.testWidget( {}, elem[ 0 ] );
|
||||
|
||||
elem = $( "<div>" );
|
||||
$.ui.testWidget.prototype._create = function() {
|
||||
deepEqual( this.element[ 0 ], elem[ 0 ], "from jQuery object" );
|
||||
deepEqual( elem.data( "testWidget" ), this, "instace stored in .data()" );
|
||||
deepEqual( elem.data( "ui-testWidget" ), this, "instace stored in .data()" );
|
||||
};
|
||||
$.ui.testWidget( {}, elem );
|
||||
|
||||
@ -61,7 +61,7 @@ test( "element normalization", function() {
|
||||
.appendTo( "#qunit-fixture" );
|
||||
$.ui.testWidget.prototype._create = function() {
|
||||
deepEqual( this.element[ 0 ], elem[ 0 ], "from selector" );
|
||||
deepEqual( elem.data( "testWidget" ), this, "instace stored in .data()" );
|
||||
deepEqual( elem.data( "ui-testWidget" ), this, "instace stored in .data()" );
|
||||
};
|
||||
$.ui.testWidget( {}, "#element-normalization-selector" );
|
||||
|
||||
@ -73,8 +73,16 @@ test( "element normalization", function() {
|
||||
$.ui.testWidget();
|
||||
});
|
||||
|
||||
test( "custom selector expression", function() {
|
||||
var elem = $( "<div>" ).appendTo( "#qunit-fixture" );
|
||||
$.widget( "ui.testWidget", {} );
|
||||
elem.testWidget();
|
||||
deepEqual( $( ":ui-testWidget" )[0], elem[0] );
|
||||
elem.testWidget( "destroy" );
|
||||
});
|
||||
|
||||
test( "jQuery usage", function() {
|
||||
expect( 13 );
|
||||
expect( 16 );
|
||||
|
||||
var shouldCreate = false;
|
||||
|
||||
@ -112,12 +120,18 @@ test( "jQuery usage", function() {
|
||||
.testWidget();
|
||||
shouldCreate = false;
|
||||
|
||||
var instance = elem.data( "testWidget" );
|
||||
var instance = elem.data( "ui-testWidget" );
|
||||
equal( typeof instance, "object", "instance stored in .data(pluginName)" );
|
||||
equal( instance.element[0], elem[0], "element stored on widget" );
|
||||
var ret = elem.testWidget( "methodWithParams", "value1", "value2" );
|
||||
equal( ret, elem, "jQuery object returned from method call" );
|
||||
|
||||
// 1.9 BC for #7810
|
||||
// TODO remove
|
||||
var bcInstance = elem.data("testWidget");
|
||||
equal( typeof bcInstance, "object", "instance stored in .data(pluginName)" );
|
||||
equal( bcInstance.element[0], elem[0], "element stored on widget" );
|
||||
|
||||
ret = elem.testWidget( "getterSetterMethod" );
|
||||
equal( ret, 5, "getter/setter can act as getter" );
|
||||
ret = elem.testWidget( "getterSetterMethod", 30 );
|
||||
@ -126,6 +140,9 @@ test( "jQuery usage", function() {
|
||||
ret = elem.testWidget( "jQueryObject" );
|
||||
equal( ret[ 0 ], document.body, "returned jQuery object" );
|
||||
equal( ret.end(), elem, "stack preserved" );
|
||||
|
||||
elem.testWidget( "destroy" );
|
||||
equal( elem.data( "ui-testWidget" ), null );
|
||||
});
|
||||
|
||||
test( "direct usage", function() {
|
||||
@ -160,7 +177,7 @@ test( "direct usage", function() {
|
||||
var instance = new $.ui.testWidget( {}, elem );
|
||||
shouldCreate = false;
|
||||
|
||||
equal( $( elem ).data( "testWidget" ), instance,
|
||||
equal( $( elem ).data( "ui-testWidget" ), instance,
|
||||
"instance stored in .data(pluginName)" );
|
||||
equal( instance.element[ 0 ], elem, "element stored on widget" );
|
||||
|
||||
@ -374,7 +391,7 @@ test( "._super()", function() {
|
||||
}
|
||||
});
|
||||
|
||||
instance = $( "<div>" ).testWidget3().data( "testWidget3" );
|
||||
instance = $( "<div>" ).testWidget3().data( "ui-testWidget3" );
|
||||
instance.method( 5 );
|
||||
delete $.ui.testWidget3;
|
||||
delete $.ui.testWidget2;
|
||||
@ -411,7 +428,7 @@ test( "._superApply()", function() {
|
||||
}
|
||||
});
|
||||
|
||||
instance = $( "<div>" ).testWidget3().data( "testWidget3" );
|
||||
instance = $( "<div>" ).testWidget3().data( "ui-testWidget3" );
|
||||
instance.method( 5, 10 );
|
||||
delete $.ui.testWidget3;
|
||||
delete $.ui.testWidget2;
|
||||
@ -521,7 +538,7 @@ test( ".option() - deep option setter", function() {
|
||||
$.widget( "ui.testWidget", {} );
|
||||
var div = $( "<div>" ).testWidget();
|
||||
function deepOption( from, to, msg ) {
|
||||
div.data( "testWidget" ).options.foo = from;
|
||||
div.data( "ui-testWidget" ).options.foo = from;
|
||||
$.ui.testWidget.prototype._setOption = function( key, value ) {
|
||||
deepEqual( key, "foo", msg + ": key" );
|
||||
deepEqual( value, to, msg + ": value" );
|
||||
@ -804,7 +821,7 @@ test( "._trigger() - no event, no ui", function() {
|
||||
deepEqual( ui, {}, "empty ui hash passed" );
|
||||
handlers.push( this );
|
||||
});
|
||||
deepEqual( $( "#widget" ).data( "testWidget" )._trigger( "foo" ), true,
|
||||
deepEqual( $( "#widget" ).data( "ui-testWidget" )._trigger( "foo" ), true,
|
||||
"_trigger returns true when event is not cancelled" );
|
||||
deepEqual( handlers, [
|
||||
$( "#widget" )[ 0 ],
|
||||
@ -832,7 +849,7 @@ test( "._trigger() - cancelled event", function() {
|
||||
ok( true, "event was triggered" );
|
||||
return false;
|
||||
});
|
||||
deepEqual( $( "#widget" ).data( "testWidget" )._trigger( "foo" ), false,
|
||||
deepEqual( $( "#widget" ).data( "ui-testWidget" )._trigger( "foo" ), false,
|
||||
"_trigger returns false when event is cancelled" );
|
||||
});
|
||||
|
||||
@ -846,7 +863,7 @@ test( "._trigger() - cancelled callback", function() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
deepEqual( $( "#widget" ).data( "testWidget" )._trigger( "foo" ), false,
|
||||
deepEqual( $( "#widget" ).data( "ui-testWidget" )._trigger( "foo" ), false,
|
||||
"_trigger returns false when callback returns false" );
|
||||
});
|
||||
|
||||
|
2
ui/jquery.effects.core.js
vendored
2
ui/jquery.effects.core.js
vendored
@ -159,7 +159,7 @@ var classAnimationActions = [ "add", "remove", "toggle" ],
|
||||
padding: 1
|
||||
},
|
||||
// prefix used for storing data on .data()
|
||||
dataSpace = "ec.storage.";
|
||||
dataSpace = "ui-effects-";
|
||||
|
||||
$.each([ "borderLeftStyle", "borderRightStyle", "borderBottomStyle", "borderTopStyle" ], function( _, prop ) {
|
||||
$.fx.step[ prop ] = function( fx ) {
|
||||
|
6
ui/jquery.ui.accordion.js
vendored
6
ui/jquery.ui.accordion.js
vendored
@ -405,7 +405,7 @@ $.widget( "ui.accordion", {
|
||||
animate = this.options.animate || {},
|
||||
options = down && animate.down || animate,
|
||||
complete = function() {
|
||||
toShow.removeData( "accordionHeight" );
|
||||
toShow.removeData( "ui-accordion-height" );
|
||||
that._completed( data );
|
||||
};
|
||||
|
||||
@ -430,7 +430,7 @@ $.widget( "ui.accordion", {
|
||||
toHide.animate( hideProps, duration, easing );
|
||||
toShow
|
||||
.hide()
|
||||
.data( "accordionHeight", {
|
||||
.data( "ui-accordion-height", {
|
||||
total: total,
|
||||
toHide: toHide
|
||||
})
|
||||
@ -455,7 +455,7 @@ $.widget( "ui.accordion", {
|
||||
|
||||
$.fx.step.accordionHeight = function( fx ) {
|
||||
var elem = $( fx.elem ),
|
||||
data = elem.data( "accordionHeight" );
|
||||
data = elem.data( "ui-accordion-height" );
|
||||
elem.height( data.total - elem.outerHeight() - data.toHide.outerHeight() + elem.height() );
|
||||
};
|
||||
var hideProps = {},
|
||||
|
15
ui/jquery.ui.autocomplete.js
vendored
15
ui/jquery.ui.autocomplete.js
vendored
@ -225,7 +225,9 @@ $.widget( "ui.autocomplete", {
|
||||
// custom key handling for now
|
||||
input: $(),
|
||||
focus: function( event, ui ) {
|
||||
var item = ui.item.data( "item.autocomplete" );
|
||||
// back compat for _renderItem using item.autocomplete, via #7810
|
||||
// TODO remove the fallback, see #8156
|
||||
var item = ui.item.data( "ui-autocomplete-item" ) || ui.item.data( "item.autocomplete" );
|
||||
if ( false !== self._trigger( "focus", event, { item: item } ) ) {
|
||||
// use value to match what will end up in the input, if it was a key event
|
||||
if ( /^key/.test(event.originalEvent.type) ) {
|
||||
@ -234,7 +236,9 @@ $.widget( "ui.autocomplete", {
|
||||
}
|
||||
},
|
||||
select: function( event, ui ) {
|
||||
var item = ui.item.data( "item.autocomplete" ),
|
||||
// back compat for _renderItem using item.autocomplete, via #7810
|
||||
// TODO remove the fallback, see #8156
|
||||
var item = ui.item.data( "ui-autocomplete-item" ) || ui.item.data( "item.autocomplete" );
|
||||
previous = self.previous;
|
||||
|
||||
// only trigger when focus was lost (click on menu)
|
||||
@ -470,13 +474,16 @@ $.widget( "ui.autocomplete", {
|
||||
_renderMenu: function( ul, items ) {
|
||||
var self = this;
|
||||
$.each( items, function( index, item ) {
|
||||
self._renderItem( ul, item );
|
||||
self._renderItemData( ul, item );
|
||||
});
|
||||
},
|
||||
|
||||
_renderItemData: function( ul, item ) {
|
||||
return this._renderItem( ul, item ).data( "ui-autocomplete-item", item );
|
||||
},
|
||||
|
||||
_renderItem: function( ul, item ) {
|
||||
return $( "<li></li>" )
|
||||
.data( "item.autocomplete", item )
|
||||
.append( $( "<a></a>" ).text( item.label ) )
|
||||
.appendTo( ul );
|
||||
},
|
||||
|
6
ui/jquery.ui.slider.js
vendored
6
ui/jquery.ui.slider.js
vendored
@ -110,12 +110,12 @@ $.widget( "ui.slider", $.ui.mouse, {
|
||||
});
|
||||
|
||||
this.handles.each(function( i ) {
|
||||
$( this ).data( "index.ui-slider-handle", i );
|
||||
$( this ).data( "ui-slider-handle-index", i );
|
||||
});
|
||||
|
||||
this.handles
|
||||
.keydown(function( event ) {
|
||||
var index = $( this ).data( "index.ui-slider-handle" ),
|
||||
var index = $( this ).data( "ui-slider-handle-index" ),
|
||||
allowed,
|
||||
curVal,
|
||||
newVal,
|
||||
@ -185,7 +185,7 @@ $.widget( "ui.slider", $.ui.mouse, {
|
||||
self._slide( event, index, newVal );
|
||||
})
|
||||
.keyup(function( event ) {
|
||||
var index = $( this ).data( "index.ui-slider-handle" );
|
||||
var index = $( this ).data( "ui-slider-handle-index" );
|
||||
|
||||
if ( self._keySliding ) {
|
||||
self._keySliding = false;
|
||||
|
8
ui/jquery.ui.tabs.js
vendored
8
ui/jquery.ui.tabs.js
vendored
@ -257,7 +257,7 @@ $.widget( "ui.tabs", {
|
||||
return $( "<div></div>" )
|
||||
.attr( "id", id )
|
||||
.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" )
|
||||
.data( "destroy.tabs", true );
|
||||
.data( "ui-tabs-destroy", true );
|
||||
},
|
||||
|
||||
_setupDisabled: function( disabled ) {
|
||||
@ -457,7 +457,7 @@ $.widget( "ui.tabs", {
|
||||
.removeData( "load.tabs" );
|
||||
|
||||
this.lis.unbind( ".tabs" ).add( this.panels ).each(function() {
|
||||
if ( $.data( this, "destroy.tabs" ) ) {
|
||||
if ( $.data( this, "ui-tabs-destroy" ) ) {
|
||||
$( this ).remove();
|
||||
} else {
|
||||
$( this ).removeClass([
|
||||
@ -755,7 +755,7 @@ if ( $.uiBackCompat !== false ) {
|
||||
url.replace( "#", "" ) :
|
||||
this._tabId( li.find( "a" )[ 0 ] );
|
||||
|
||||
li.addClass( "ui-state-default ui-corner-top" ).data( "destroy.tabs", true );
|
||||
li.addClass( "ui-state-default ui-corner-top" ).data( "ui-tabs-destroy", true );
|
||||
li.find( "a" ).attr( "aria-controls", id );
|
||||
|
||||
var doInsertAfter = index >= this.lis.length;
|
||||
@ -855,7 +855,7 @@ if ( $.uiBackCompat !== false ) {
|
||||
return $( this.options.panelTemplate )
|
||||
.attr( "id", id )
|
||||
.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" )
|
||||
.data( "destroy.tabs", true );
|
||||
.data( "ui-tabs-destroy", true );
|
||||
}
|
||||
});
|
||||
|
||||
|
14
ui/jquery.ui.tooltip.js
vendored
14
ui/jquery.ui.tooltip.js
vendored
@ -72,7 +72,7 @@ $.widget( "ui.tooltip", {
|
||||
var element = $( this );
|
||||
if ( element.is( "[title]" ) ) {
|
||||
element
|
||||
.data( "tooltip-title", element.attr( "title" ) )
|
||||
.data( "ui-tooltip-title", element.attr( "title" ) )
|
||||
.attr( "title", "" );
|
||||
}
|
||||
});
|
||||
@ -82,8 +82,8 @@ $.widget( "ui.tooltip", {
|
||||
// restore title attributes
|
||||
this.element.find( this.options.items ).andSelf().each(function() {
|
||||
var element = $( this );
|
||||
if ( element.data( "tooltip-title" ) ) {
|
||||
element.attr( "title", element.data( "tooltip-title" ) );
|
||||
if ( element.data( "ui-tooltip-title" ) ) {
|
||||
element.attr( "title", element.data( "ui-tooltip-title" ) );
|
||||
}
|
||||
});
|
||||
},
|
||||
@ -99,8 +99,8 @@ $.widget( "ui.tooltip", {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !target.data( "tooltip-title" ) ) {
|
||||
target.data( "tooltip-title", target.attr( "title" ) );
|
||||
if ( !target.data( "ui-tooltip-title" ) ) {
|
||||
target.data( "ui-tooltip-title", target.attr( "title" ) );
|
||||
}
|
||||
|
||||
target.data( "tooltip-open", true );
|
||||
@ -180,8 +180,8 @@ $.widget( "ui.tooltip", {
|
||||
}
|
||||
|
||||
// only set title if we had one before (see comment in _open())
|
||||
if ( target.data( "tooltip-title" ) ) {
|
||||
target.attr( "title", target.data( "tooltip-title" ) );
|
||||
if ( target.data( "ui-tooltip-title" ) ) {
|
||||
target.attr( "title", target.data( "ui-tooltip-title" ) );
|
||||
}
|
||||
|
||||
target.removeAttr( "aria-describedby" );
|
||||
|
23
ui/jquery.ui.widget.js
vendored
23
ui/jquery.ui.widget.js
vendored
@ -36,7 +36,7 @@ $.widget = function( name, base, prototype ) {
|
||||
|
||||
// create selector for plugin
|
||||
$.expr[ ":" ][ fullName ] = function( elem ) {
|
||||
return !!$.data( elem, name );
|
||||
return !!$.data( elem, fullName );
|
||||
};
|
||||
|
||||
$[ namespace ] = $[ namespace ] || {};
|
||||
@ -105,7 +105,9 @@ $.widget = function( name, base, prototype ) {
|
||||
constructor: constructor,
|
||||
namespace: namespace,
|
||||
widgetName: name,
|
||||
widgetBaseClass: fullName
|
||||
// TODO remove widgetBaseClass, see #8155
|
||||
widgetBaseClass: fullName,
|
||||
widgetFullName: fullName
|
||||
});
|
||||
|
||||
// If this widget is being redefined then we need to find all widgets that
|
||||
@ -148,6 +150,7 @@ $.widget.extend = function( target ) {
|
||||
};
|
||||
|
||||
$.widget.bridge = function( name, object ) {
|
||||
var fullName = object.prototype.widgetFullName;
|
||||
$.fn[ name ] = function( options ) {
|
||||
var isMethodCall = typeof options === "string",
|
||||
args = slice.call( arguments, 1 ),
|
||||
@ -160,7 +163,7 @@ $.widget.bridge = function( name, object ) {
|
||||
|
||||
if ( isMethodCall ) {
|
||||
this.each(function() {
|
||||
var instance = $.data( this, name );
|
||||
var instance = $.data( this, fullName );
|
||||
if ( !instance ) {
|
||||
return $.error( "cannot call methods on " + name + " prior to initialization; " +
|
||||
"attempted to call method '" + options + "'" );
|
||||
@ -178,7 +181,7 @@ $.widget.bridge = function( name, object ) {
|
||||
});
|
||||
} else {
|
||||
this.each(function() {
|
||||
var instance = $.data( this, name );
|
||||
var instance = $.data( this, fullName );
|
||||
if ( instance ) {
|
||||
instance.option( options || {} )._init();
|
||||
} else {
|
||||
@ -217,7 +220,10 @@ $.Widget.prototype = {
|
||||
this.focusable = $();
|
||||
|
||||
if ( element !== this ) {
|
||||
// 1.9 BC for #7810
|
||||
// TODO remove dual storage
|
||||
$.data( element, this.widgetName, this );
|
||||
$.data( element, this.widgetFullName, this );
|
||||
this._bind({ remove: "destroy" });
|
||||
this.document = $( element.style ?
|
||||
// element within the document
|
||||
@ -242,12 +248,15 @@ $.Widget.prototype = {
|
||||
// all event bindings should go through this._bind()
|
||||
this.element
|
||||
.unbind( "." + this.widgetName )
|
||||
.removeData( this.widgetName );
|
||||
// 1.9 BC for #7810
|
||||
// TODO remove dual storage
|
||||
.removeData( this.widgetName )
|
||||
.removeData( this.widgetFullName );
|
||||
this.widget()
|
||||
.unbind( "." + this.widgetName )
|
||||
.removeAttr( "aria-disabled" )
|
||||
.removeClass(
|
||||
this.widgetBaseClass + "-disabled " +
|
||||
this.widgetFullName + "-disabled " +
|
||||
"ui-state-disabled" );
|
||||
|
||||
// clean up events and states
|
||||
@ -314,7 +323,7 @@ $.Widget.prototype = {
|
||||
|
||||
if ( key === "disabled" ) {
|
||||
this.widget()
|
||||
.toggleClass( this.widgetBaseClass + "-disabled ui-state-disabled", !!value )
|
||||
.toggleClass( this.widgetFullName + "-disabled ui-state-disabled", !!value )
|
||||
.attr( "aria-disabled", value );
|
||||
this.hoverable.removeClass( "ui-state-hover" );
|
||||
this.focusable.removeClass( "ui-state-focus" );
|
||||
|
Loading…
Reference in New Issue
Block a user