Skip to content
Permalink
Browse files

Merge branch 'data-naming'

  • Loading branch information
jzaefferer committed Mar 1, 2012
2 parents 63215a6 + 2321ae0 commit f65d6b92cc14ee3e829d6e941fcd07a5fb37b278
@@ -32,36 +32,36 @@ 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 );

elem = $( "<div id='element-normalization-selector'></div>" )
.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" );
});

@@ -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 ) {
@@ -689,7 +689,7 @@ $.extend( baseEasings, {
Bounce: function ( p ) {
var pow2,
bounce = 4;

while ( p < ( ( pow2 = Math.pow( 2, --bounce ) ) - 1 ) / 11 ) {}
return 1 / Math.pow( 4, 3 - bounce ) - 7.5625 * Math.pow( ( pow2 * 3 - 2 ) / 22 - p, 2 );
}
@@ -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 = {},
@@ -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 );
});
},

_renderItem: function( 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 );
},
@@ -74,7 +74,7 @@ $.widget( "ui.slider", $.ui.mouse, {
.addClass( "ui-slider-range" +
// note: this isn't the most fittingly semantic framework class for this element,
// but worked best visually with a variety of themes
" ui-widget-header" +
" ui-widget-header" +
( ( o.range === "min" || o.range === "max" ) ? " ui-slider-range-" + o.range : "" ) );
}

@@ -110,21 +110,21 @@ $.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,
step;

if ( self.options.disabled ) {
return;
}

switch ( event.keyCode ) {
case $.ui.keyCode.HOME:
case $.ui.keyCode.END:
@@ -145,14 +145,14 @@ $.widget( "ui.slider", $.ui.mouse, {
}
break;
}

step = self.options.step;
if ( self.options.values && self.options.values.length ) {
curVal = newVal = self.values( index );
} else {
curVal = newVal = self.value();
}

switch ( event.keyCode ) {
case $.ui.keyCode.HOME:
newVal = self._valueMin();
@@ -181,19 +181,19 @@ $.widget( "ui.slider", $.ui.mouse, {
newVal = self._trimAlignValue( curVal - step );
break;
}

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;
self._stop( event, index );
self._change( event, index );
$( this ).removeClass( "ui-state-active" );
}

});

this._refreshValue();
@@ -275,7 +275,7 @@ $.widget( "ui.slider", $.ui.mouse, {
closestHandle
.addClass( "ui-state-active" )
.focus();

offset = closestHandle.offset();
mouseOverHandle = !$( event.target ).parents().andSelf().is( ".ui-slider-handle" );
this._clickOffset = mouseOverHandle ? { left: 0, top: 0 } : {
@@ -301,7 +301,7 @@ $.widget( "ui.slider", $.ui.mouse, {
_mouseDrag: function( event ) {
var position = { x: event.pageX, y: event.pageY },
normValue = this._normValueFromMouse( position );

this._slide( event, this._handleIndex, normValue );

return false;
@@ -320,7 +320,7 @@ $.widget( "ui.slider", $.ui.mouse, {

return false;
},

_detectOrientation: function() {
this.orientation = ( this.options.orientation === "vertical" ) ? "vertical" : "horizontal";
},
@@ -377,7 +377,7 @@ $.widget( "ui.slider", $.ui.mouse, {
if ( this.options.values && this.options.values.length ) {
otherVal = this.values( index ? 0 : 1 );

if ( ( this.options.values.length === 2 && this.options.range === true ) &&
if ( ( this.options.values.length === 2 && this.options.range === true ) &&
( ( index === 0 && newVal > otherVal) || ( index === 1 && newVal < otherVal ) )
) {
newVal = otherVal;
@@ -562,7 +562,7 @@ $.widget( "ui.slider", $.ui.mouse, {
return vals;
}
},

// returns the step-aligned value that val is closest to, between (inclusive) min and max
_trimAlignValue: function( val ) {
if ( val <= this._valueMin() ) {
@@ -591,7 +591,7 @@ $.widget( "ui.slider", $.ui.mouse, {
_valueMax: function() {
return this.options.max;
},

_refreshValue: function() {
var oRange = this.options.range,
o = this.options,

0 comments on commit f65d6b9

Please sign in to comment.
You can’t perform that action at this time.