]> source.dussan.org Git - jquery-ui.git/commitdiff
Widget: Don't throw errors for invalid method calls (wait till 1.9 to add this back...
authorScott González <scott.gonzalez@gmail.com>
Thu, 21 Oct 2010 13:52:27 +0000 (09:52 -0400)
committerScott González <scott.gonzalez@gmail.com>
Thu, 21 Oct 2010 13:52:27 +0000 (09:52 -0400)
ui/jquery.ui.widget.js

index 95923edddd44a9b8aa69b3556d1d191c6d78387e..fadf81f2be427da7e9615cd8bc3326a22d6181e6 100644 (file)
@@ -96,15 +96,19 @@ $.widget.bridge = function( name, object ) {
 
                if ( isMethodCall ) {
                        this.each(function() {
-                               var instance = $.data( this, name );
-                               if ( !instance ) {
-                                       throw "cannot call methods on " + name + " prior to initialization; " +
-                                               "attempted to call method '" + options + "'";
-                               }
-                               if ( !$.isFunction( instance[options] ) ) {
-                                       throw "no such method '" + options + "' for " + name + " widget instance";
-                               }
-                               var methodValue = instance[ options ].apply( instance, args );
+                               var instance = $.data( this, name ),
+                                       methodValue = instance && $.isFunction( instance[options] ) ?
+                                               instance[ options ].apply( instance, args ) :
+                                               instance;
+                               // TODO: add this back in 1.9 and use $.error() (see #5972)
+//                             if ( !instance ) {
+//                                     throw "cannot call methods on " + name + " prior to initialization; " +
+//                                             "attempted to call method '" + options + "'";
+//                             }
+//                             if ( !$.isFunction( instance[options] ) ) {
+//                                     throw "no such method '" + options + "' for " + name + " widget instance";
+//                             }
+//                             var methodValue = instance[ options ].apply( instance, args );
                                if ( methodValue !== instance && methodValue !== undefined ) {
                                        returnValue = methodValue;
                                        return false;