Skip to content

Commit 4fce29e

Browse files
gnarfjzaefferer
authored andcommitted
Widgets: Updating to use instance method on bridge
1 parent 38c7b1c commit 4fce29e

File tree

5 files changed

+35
-32
lines changed

5 files changed

+35
-32
lines changed

tests/unit/widget/widget_core.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,15 +626,18 @@ test( ".widget() - overriden", function() {
626626
});
627627

628628
test( ".instance()", function() {
629-
expect( 1 );
629+
expect( 2 );
630630
var div,
631631
_test = function() {};
632632

633633
$.widget( "ui.testWidget", {
634634
_create: function() {},
635635
_test: _test
636636
});
637-
div = $( "<div>" ).testWidget();
637+
638+
div = $( "<div>" );
639+
equal( div.testWidget( "instance" ), undefined );
640+
div.testWidget();
638641
equal( div.testWidget( "instance" ), div.data( "ui-testWidget" ) );
639642
});
640643

ui/jquery.ui.autocomplete.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ $.widget( "ui.autocomplete", {
201201
role: null
202202
})
203203
.hide()
204-
.data( "ui-menu" );
204+
.menu( "instance" );
205205

206206
this._on( this.menu.element, {
207207
mousedown: function( event ) {

ui/jquery.ui.draggable.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ $.widget("ui.draggable", $.ui.mouse, {
563563
$.ui.plugin.add("draggable", "connectToSortable", {
564564
start: function(event, ui) {
565565

566-
var inst = $(this).data("ui-draggable"), o = inst.options,
566+
var inst = $(this).draggable( "instance" ), o = inst.options,
567567
uiSortable = $.extend({}, ui, { item: inst.element });
568568
inst.sortables = [];
569569
$(o.connectToSortable).each(function() {
@@ -582,7 +582,7 @@ $.ui.plugin.add("draggable", "connectToSortable", {
582582
stop: function(event, ui) {
583583

584584
//If we are still over the sortable, we fake the stop event of the sortable, but also remove helper
585-
var inst = $(this).data("ui-draggable"),
585+
var inst = $(this).draggable( "instance" ),
586586
uiSortable = $.extend({}, ui, { item: inst.element });
587587

588588
$.each(inst.sortables, function() {
@@ -618,7 +618,7 @@ $.ui.plugin.add("draggable", "connectToSortable", {
618618
},
619619
drag: function(event, ui) {
620620

621-
var inst = $(this).data("ui-draggable"), that = this;
621+
var inst = $(this).draggable( "instance" ), that = this;
622622

623623
$.each(inst.sortables, function() {
624624

@@ -719,14 +719,14 @@ $.ui.plugin.add("draggable", "connectToSortable", {
719719

720720
$.ui.plugin.add("draggable", "cursor", {
721721
start: function() {
722-
var t = $("body"), o = $(this).data("ui-draggable").options;
722+
var t = $("body"), o = $(this).draggable( "instance" ).options;
723723
if (t.css("cursor")) {
724724
o._cursor = t.css("cursor");
725725
}
726726
t.css("cursor", o.cursor);
727727
},
728728
stop: function() {
729-
var o = $(this).data("ui-draggable").options;
729+
var o = $(this).draggable( "instance" ).options;
730730
if (o._cursor) {
731731
$("body").css("cursor", o._cursor);
732732
}
@@ -735,14 +735,14 @@ $.ui.plugin.add("draggable", "cursor", {
735735

736736
$.ui.plugin.add("draggable", "opacity", {
737737
start: function(event, ui) {
738-
var t = $(ui.helper), o = $(this).data("ui-draggable").options;
738+
var t = $(ui.helper), o = $(this).draggable( "instance" ).options;
739739
if(t.css("opacity")) {
740740
o._opacity = t.css("opacity");
741741
}
742742
t.css("opacity", o.opacity);
743743
},
744744
stop: function(event, ui) {
745-
var o = $(this).data("ui-draggable").options;
745+
var o = $(this).draggable( "instance" ).options;
746746
if(o._opacity) {
747747
$(ui.helper).css("opacity", o._opacity);
748748
}
@@ -751,14 +751,14 @@ $.ui.plugin.add("draggable", "opacity", {
751751

752752
$.ui.plugin.add("draggable", "scroll", {
753753
start: function() {
754-
var i = $(this).data("ui-draggable");
754+
var i = $(this).draggable( "instance" );
755755
if(i.scrollParent[0] !== document && i.scrollParent[0].tagName !== "HTML") {
756756
i.overflowOffset = i.scrollParent.offset();
757757
}
758758
},
759759
drag: function( event ) {
760760

761-
var i = $(this).data("ui-draggable"), o = i.options, scrolled = false;
761+
var i = $(this).draggable( "instance" ), o = i.options, scrolled = false;
762762

763763
if(i.scrollParent[0] !== document && i.scrollParent[0].tagName !== "HTML") {
764764

@@ -808,7 +808,7 @@ $.ui.plugin.add("draggable", "scroll", {
808808
$.ui.plugin.add("draggable", "snap", {
809809
start: function() {
810810

811-
var i = $(this).data("ui-draggable"),
811+
var i = $(this).draggable( "instance" ),
812812
o = i.options;
813813

814814
i.snapElements = [];
@@ -829,7 +829,7 @@ $.ui.plugin.add("draggable", "snap", {
829829
drag: function(event, ui) {
830830

831831
var ts, bs, ls, rs, l, r, t, b, i, first,
832-
inst = $(this).data("ui-draggable"),
832+
inst = $(this).draggable( "instance" ),
833833
o = inst.options,
834834
d = o.snapTolerance,
835835
x1 = ui.offset.left, x2 = x1 + inst.helperProportions.width,
@@ -903,7 +903,7 @@ $.ui.plugin.add("draggable", "snap", {
903903
$.ui.plugin.add("draggable", "stack", {
904904
start: function() {
905905
var min,
906-
o = this.data("ui-draggable").options,
906+
o = $(this).draggable( "instance" ).options,
907907
group = $.makeArray($(o.stack)).sort(function(a,b) {
908908
return (parseInt($(a).css("zIndex"),10) || 0) - (parseInt($(b).css("zIndex"),10) || 0);
909909
});
@@ -920,14 +920,14 @@ $.ui.plugin.add("draggable", "stack", {
920920

921921
$.ui.plugin.add("draggable", "zIndex", {
922922
start: function(event, ui) {
923-
var t = $(ui.helper), o = $(this).data("ui-draggable").options;
923+
var t = $(ui.helper), o = $(this).draggable( "instance" ).options;
924924
if(t.css("zIndex")) {
925925
o._zIndex = t.css("zIndex");
926926
}
927927
t.css("zIndex", o.zIndex);
928928
},
929929
stop: function(event, ui) {
930-
var o = $(this).data("ui-draggable").options;
930+
var o = $(this).draggable( "instance" ).options;
931931
if(o._zIndex) {
932932
$(ui.helper).css("zIndex", o._zIndex);
933933
}

ui/jquery.ui.resizable.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ $.widget("ui.resizable", $.ui.mouse, {
8181

8282
//Overwrite the original this.element
8383
this.element = this.element.parent().data(
84-
"ui-resizable", this.element.data("ui-resizable")
84+
"ui-resizable", this.element.resizable( "instance" )
8585
);
8686

8787
this.elementIsWrapper = true;
@@ -651,7 +651,7 @@ $.widget("ui.resizable", $.ui.mouse, {
651651
$.ui.plugin.add("resizable", "animate", {
652652

653653
stop: function( event ) {
654-
var that = $(this).data("ui-resizable"),
654+
var that = $(this).resizable( "instance" ),
655655
o = that.options,
656656
pr = that._proportionallyResizeElements,
657657
ista = pr.length && (/textarea/i).test(pr[0].nodeName),
@@ -693,7 +693,7 @@ $.ui.plugin.add("resizable", "containment", {
693693

694694
start: function() {
695695
var element, p, co, ch, cw, width, height,
696-
that = $(this).data("ui-resizable"),
696+
that = $(this).resizable( "instance" ),
697697
o = that.options,
698698
el = that.element,
699699
oc = o.containment,
@@ -739,7 +739,7 @@ $.ui.plugin.add("resizable", "containment", {
739739

740740
resize: function( event ) {
741741
var woset, hoset, isParent, isOffsetRelative,
742-
that = $(this).data("ui-resizable"),
742+
that = $(this).resizable( "instance" ),
743743
o = that.options,
744744
co = that.containerOffset, cp = that.position,
745745
pRatio = that._aspectRatio || event.shiftKey,
@@ -794,7 +794,7 @@ $.ui.plugin.add("resizable", "containment", {
794794
},
795795

796796
stop: function(){
797-
var that = $(this).data("ui-resizable"),
797+
var that = $(this).resizable( "instance" ),
798798
o = that.options,
799799
co = that.containerOffset,
800800
cop = that.containerPosition,
@@ -818,7 +818,7 @@ $.ui.plugin.add("resizable", "containment", {
818818
$.ui.plugin.add("resizable", "alsoResize", {
819819

820820
start: function () {
821-
var that = $(this).data("ui-resizable"),
821+
var that = $(this).resizable( "instance" ),
822822
o = that.options,
823823
_store = function (exp) {
824824
$(exp).each(function() {
@@ -839,7 +839,7 @@ $.ui.plugin.add("resizable", "alsoResize", {
839839
},
840840

841841
resize: function (event, ui) {
842-
var that = $(this).data("ui-resizable"),
842+
var that = $(this).resizable( "instance" ),
843843
o = that.options,
844844
os = that.originalSize,
845845
op = that.originalPosition,
@@ -880,7 +880,7 @@ $.ui.plugin.add("resizable", "ghost", {
880880

881881
start: function() {
882882

883-
var that = $(this).data("ui-resizable"), o = that.options, cs = that.size;
883+
var that = $(this).resizable( "instance" ), o = that.options, cs = that.size;
884884

885885
that.ghost = that.originalElement.clone();
886886
that.ghost
@@ -893,14 +893,14 @@ $.ui.plugin.add("resizable", "ghost", {
893893
},
894894

895895
resize: function(){
896-
var that = $(this).data("ui-resizable");
896+
var that = $(this).resizable( "instance" );
897897
if (that.ghost) {
898898
that.ghost.css({ position: "relative", height: that.size.height, width: that.size.width });
899899
}
900900
},
901901

902902
stop: function() {
903-
var that = $(this).data("ui-resizable");
903+
var that = $(this).resizable( "instance" );
904904
if (that.ghost && that.helper) {
905905
that.helper.get(0).removeChild(that.ghost.get(0));
906906
}
@@ -911,7 +911,7 @@ $.ui.plugin.add("resizable", "ghost", {
911911
$.ui.plugin.add("resizable", "grid", {
912912

913913
resize: function() {
914-
var that = $(this).data("ui-resizable"),
914+
var that = $(this).resizable( "instance" ),
915915
o = that.options,
916916
cs = that.size,
917917
os = that.originalSize,

ui/jquery.ui.widget.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,14 @@ $.widget.bridge = function( name, object ) {
178178
this.each(function() {
179179
var methodValue,
180180
instance = $.data( this, fullName );
181-
if ( !instance ) {
182-
return $.error( "cannot call methods on " + name + " prior to initialization; " +
183-
"attempted to call method '" + options + "'" );
184-
}
185181
if ( options === "instance" ) {
186182
returnValue = instance;
187183
return false;
188184
}
185+
if ( !instance ) {
186+
return $.error( "cannot call methods on " + name + " prior to initialization; " +
187+
"attempted to call method '" + options + "'" );
188+
}
189189
if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
190190
return $.error( "no such method '" + options + "' for " + name + " widget instance" );
191191
}

0 commit comments

Comments
 (0)