]> source.dussan.org Git - jquery-ui.git/commitdiff
Widgets: Updating to use instance method on bridge
authorCorey Frang <gnarf@gnarf.net>
Wed, 30 Jan 2013 14:32:48 +0000 (08:32 -0600)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Tue, 19 Mar 2013 15:08:00 +0000 (16:08 +0100)
tests/unit/widget/widget_core.js
ui/jquery.ui.autocomplete.js
ui/jquery.ui.draggable.js
ui/jquery.ui.resizable.js
ui/jquery.ui.widget.js

index 0f6692c3c71fff55ccdba72bac1b66c9711f5ca2..eaea8d8be80b3e318b1549076db87a8c8b16840d 100644 (file)
@@ -626,7 +626,7 @@ test( ".widget() - overriden", function() {
 });
 
 test( ".instance()", function() {
-       expect( 1 );
+       expect( 2 );
        var div,
                _test = function() {};
 
@@ -634,7 +634,10 @@ test( ".instance()", function() {
                _create: function() {},
                _test: _test
        });
-       div = $( "<div>" ).testWidget();
+
+       div = $( "<div>" );
+       equal( div.testWidget( "instance" ), undefined );
+       div.testWidget();
        equal( div.testWidget( "instance" ), div.data( "ui-testWidget" ) );
 });
 
index b3a05da0bac91e86f28e8c1c7fb1246b55c708c8..92ddc3a125e65edc56e2225b47eb7f1dd52d1478 100644 (file)
@@ -201,7 +201,7 @@ $.widget( "ui.autocomplete", {
                                role: null
                        })
                        .hide()
-                       .data( "ui-menu" );
+                       .menu( "instance" );
 
                this._on( this.menu.element, {
                        mousedown: function( event ) {
index 605425859c90c1e88638609e4e5b7c9304919396..a16b022d76482f7ba07e3b7ad897772f94aae1ee 100644 (file)
@@ -563,7 +563,7 @@ $.widget("ui.draggable", $.ui.mouse, {
 $.ui.plugin.add("draggable", "connectToSortable", {
        start: function(event, ui) {
 
-               var inst = $(this).data("ui-draggable"), o = inst.options,
+               var inst = $(this).draggable( "instance" ), o = inst.options,
                        uiSortable = $.extend({}, ui, { item: inst.element });
                inst.sortables = [];
                $(o.connectToSortable).each(function() {
@@ -582,7 +582,7 @@ $.ui.plugin.add("draggable", "connectToSortable", {
        stop: function(event, ui) {
 
                //If we are still over the sortable, we fake the stop event of the sortable, but also remove helper
-               var inst = $(this).data("ui-draggable"),
+               var inst = $(this).draggable( "instance" ),
                        uiSortable = $.extend({}, ui, { item: inst.element });
 
                $.each(inst.sortables, function() {
@@ -618,7 +618,7 @@ $.ui.plugin.add("draggable", "connectToSortable", {
        },
        drag: function(event, ui) {
 
-               var inst = $(this).data("ui-draggable"), that = this;
+               var inst = $(this).draggable( "instance" ), that = this;
 
                $.each(inst.sortables, function() {
 
@@ -719,14 +719,14 @@ $.ui.plugin.add("draggable", "connectToSortable", {
 
 $.ui.plugin.add("draggable", "cursor", {
        start: function() {
-               var t = $("body"), o = $(this).data("ui-draggable").options;
+               var t = $("body"), o = $(this).draggable( "instance" ).options;
                if (t.css("cursor")) {
                        o._cursor = t.css("cursor");
                }
                t.css("cursor", o.cursor);
        },
        stop: function() {
-               var o = $(this).data("ui-draggable").options;
+               var o = $(this).draggable( "instance" ).options;
                if (o._cursor) {
                        $("body").css("cursor", o._cursor);
                }
@@ -735,14 +735,14 @@ $.ui.plugin.add("draggable", "cursor", {
 
 $.ui.plugin.add("draggable", "opacity", {
        start: function(event, ui) {
-               var t = $(ui.helper), o = $(this).data("ui-draggable").options;
+               var t = $(ui.helper), o = $(this).draggable( "instance" ).options;
                if(t.css("opacity")) {
                        o._opacity = t.css("opacity");
                }
                t.css("opacity", o.opacity);
        },
        stop: function(event, ui) {
-               var o = $(this).data("ui-draggable").options;
+               var o = $(this).draggable( "instance" ).options;
                if(o._opacity) {
                        $(ui.helper).css("opacity", o._opacity);
                }
@@ -751,14 +751,14 @@ $.ui.plugin.add("draggable", "opacity", {
 
 $.ui.plugin.add("draggable", "scroll", {
        start: function() {
-               var i = $(this).data("ui-draggable");
+               var i = $(this).draggable( "instance" );
                if(i.scrollParent[0] !== document && i.scrollParent[0].tagName !== "HTML") {
                        i.overflowOffset = i.scrollParent.offset();
                }
        },
        drag: function( event ) {
 
-               var i = $(this).data("ui-draggable"), o = i.options, scrolled = false;
+               var i = $(this).draggable( "instance" ), o = i.options, scrolled = false;
 
                if(i.scrollParent[0] !== document && i.scrollParent[0].tagName !== "HTML") {
 
@@ -808,7 +808,7 @@ $.ui.plugin.add("draggable", "scroll", {
 $.ui.plugin.add("draggable", "snap", {
        start: function() {
 
-               var i = $(this).data("ui-draggable"),
+               var i = $(this).draggable( "instance" ),
                        o = i.options;
 
                i.snapElements = [];
@@ -829,7 +829,7 @@ $.ui.plugin.add("draggable", "snap", {
        drag: function(event, ui) {
 
                var ts, bs, ls, rs, l, r, t, b, i, first,
-                       inst = $(this).data("ui-draggable"),
+                       inst = $(this).draggable( "instance" ),
                        o = inst.options,
                        d = o.snapTolerance,
                        x1 = ui.offset.left, x2 = x1 + inst.helperProportions.width,
@@ -903,7 +903,7 @@ $.ui.plugin.add("draggable", "snap", {
 $.ui.plugin.add("draggable", "stack", {
        start: function() {
                var min,
-                       o = this.data("ui-draggable").options,
+                       o = $(this).draggable( "instance" ).options,
                        group = $.makeArray($(o.stack)).sort(function(a,b) {
                                return (parseInt($(a).css("zIndex"),10) || 0) - (parseInt($(b).css("zIndex"),10) || 0);
                        });
@@ -920,14 +920,14 @@ $.ui.plugin.add("draggable", "stack", {
 
 $.ui.plugin.add("draggable", "zIndex", {
        start: function(event, ui) {
-               var t = $(ui.helper), o = $(this).data("ui-draggable").options;
+               var t = $(ui.helper), o = $(this).draggable( "instance" ).options;
                if(t.css("zIndex")) {
                        o._zIndex = t.css("zIndex");
                }
                t.css("zIndex", o.zIndex);
        },
        stop: function(event, ui) {
-               var o = $(this).data("ui-draggable").options;
+               var o = $(this).draggable( "instance" ).options;
                if(o._zIndex) {
                        $(ui.helper).css("zIndex", o._zIndex);
                }
index 2468dcaa65f9f141529410c38a388f8d64b76d10..761ea058bcc7d0183f153734db8543be1d349678 100644 (file)
@@ -81,7 +81,7 @@ $.widget("ui.resizable", $.ui.mouse, {
 
                        //Overwrite the original this.element
                        this.element = this.element.parent().data(
-                               "ui-resizable", this.element.data("ui-resizable")
+                               "ui-resizable", this.element.resizable( "instance" )
                        );
 
                        this.elementIsWrapper = true;
@@ -651,7 +651,7 @@ $.widget("ui.resizable", $.ui.mouse, {
 $.ui.plugin.add("resizable", "animate", {
 
        stop: function( event ) {
-               var that = $(this).data("ui-resizable"),
+               var that = $(this).resizable( "instance" ),
                        o = that.options,
                        pr = that._proportionallyResizeElements,
                        ista = pr.length && (/textarea/i).test(pr[0].nodeName),
@@ -693,7 +693,7 @@ $.ui.plugin.add("resizable", "containment", {
 
        start: function() {
                var element, p, co, ch, cw, width, height,
-                       that = $(this).data("ui-resizable"),
+                       that = $(this).resizable( "instance" ),
                        o = that.options,
                        el = that.element,
                        oc = o.containment,
@@ -739,7 +739,7 @@ $.ui.plugin.add("resizable", "containment", {
 
        resize: function( event ) {
                var woset, hoset, isParent, isOffsetRelative,
-                       that = $(this).data("ui-resizable"),
+                       that = $(this).resizable( "instance" ),
                        o = that.options,
                        co = that.containerOffset, cp = that.position,
                        pRatio = that._aspectRatio || event.shiftKey,
@@ -794,7 +794,7 @@ $.ui.plugin.add("resizable", "containment", {
        },
 
        stop: function(){
-               var that = $(this).data("ui-resizable"),
+               var that = $(this).resizable( "instance" ),
                        o = that.options,
                        co = that.containerOffset,
                        cop = that.containerPosition,
@@ -818,7 +818,7 @@ $.ui.plugin.add("resizable", "containment", {
 $.ui.plugin.add("resizable", "alsoResize", {
 
        start: function () {
-               var that = $(this).data("ui-resizable"),
+               var that = $(this).resizable( "instance" ),
                        o = that.options,
                        _store = function (exp) {
                                $(exp).each(function() {
@@ -839,7 +839,7 @@ $.ui.plugin.add("resizable", "alsoResize", {
        },
 
        resize: function (event, ui) {
-               var that = $(this).data("ui-resizable"),
+               var that = $(this).resizable( "instance" ),
                        o = that.options,
                        os = that.originalSize,
                        op = that.originalPosition,
@@ -880,7 +880,7 @@ $.ui.plugin.add("resizable", "ghost", {
 
        start: function() {
 
-               var that = $(this).data("ui-resizable"), o = that.options, cs = that.size;
+               var that = $(this).resizable( "instance" ), o = that.options, cs = that.size;
 
                that.ghost = that.originalElement.clone();
                that.ghost
@@ -893,14 +893,14 @@ $.ui.plugin.add("resizable", "ghost", {
        },
 
        resize: function(){
-               var that = $(this).data("ui-resizable");
+               var that = $(this).resizable( "instance" );
                if (that.ghost) {
                        that.ghost.css({ position: "relative", height: that.size.height, width: that.size.width });
                }
        },
 
        stop: function() {
-               var that = $(this).data("ui-resizable");
+               var that = $(this).resizable( "instance" );
                if (that.ghost && that.helper) {
                        that.helper.get(0).removeChild(that.ghost.get(0));
                }
@@ -911,7 +911,7 @@ $.ui.plugin.add("resizable", "ghost", {
 $.ui.plugin.add("resizable", "grid", {
 
        resize: function() {
-               var that = $(this).data("ui-resizable"),
+               var that = $(this).resizable( "instance" ),
                        o = that.options,
                        cs = that.size,
                        os = that.originalSize,
index ca097e02bc6c7dc3d1db24225408eb260a6098cb..741ac74d7a8dd1873aea991703ff822d2aaf4bf6 100644 (file)
@@ -178,14 +178,14 @@ $.widget.bridge = function( name, object ) {
                        this.each(function() {
                                var methodValue,
                                        instance = $.data( this, fullName );
-                               if ( !instance ) {
-                                       return $.error( "cannot call methods on " + name + " prior to initialization; " +
-                                               "attempted to call method '" + options + "'" );
-                               }
                                if ( options === "instance" ) {
                                        returnValue = instance;
                                        return false;
                                }
+                               if ( !instance ) {
+                                       return $.error( "cannot call methods on " + name + " prior to initialization; " +
+                                               "attempted to call method '" + options + "'" );
+                               }
                                if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
                                        return $.error( "no such method '" + options + "' for " + name + " widget instance" );
                                }