diff --git a/ui/.jshintrc b/ui/.jshintrc index 98a79b5db..7bb17b5f9 100644 --- a/ui/.jshintrc +++ b/ui/.jshintrc @@ -6,7 +6,6 @@ "expr": true, "immed": true, "noarg": true, - "onevar": true, "quotmark": "double", "smarttabs": true, "trailing": true, diff --git a/ui/widget.js b/ui/widget.js index 183d455b6..eabeb3981 100644 --- a/ui/widget.js +++ b/ui/widget.js @@ -25,8 +25,8 @@ } }( function( $ ) { -var widgetUuid = 0, - widgetSlice = Array.prototype.slice; +var widgetUuid = 0; +var widgetSlice = Array.prototype.slice; $.cleanData = ( function( orig ) { return function( elems ) { @@ -48,15 +48,15 @@ $.cleanData = ( function( orig ) { } )( $.cleanData ); $.widget = function( name, base, prototype ) { - var fullName, existingConstructor, constructor, basePrototype, + var existingConstructor, constructor, basePrototype; - // ProxiedPrototype allows the provided prototype to remain unmodified - // so that it can be used as a mixin for multiple widgets (#8876) - proxiedPrototype = {}, - namespace = name.split( "." )[ 0 ]; + // ProxiedPrototype allows the provided prototype to remain unmodified + // so that it can be used as a mixin for multiple widgets (#8876) + var proxiedPrototype = {}; + var namespace = name.split( "." )[ 0 ]; name = name.split( "." )[ 1 ]; - fullName = namespace + "-" + name; + var fullName = namespace + "-" + name; if ( !prototype ) { prototype = base; @@ -113,16 +113,18 @@ $.widget = function( name, base, prototype ) { return; } proxiedPrototype[ prop ] = ( function() { - var _super = function() { - return base.prototype[ prop ].apply( this, arguments ); - }, - _superApply = function( args ) { - return base.prototype[ prop ].apply( this, args ); - }; + function _super() { + return base.prototype[ prop ].apply( this, arguments ); + } + + function _superApply( args ) { + return base.prototype[ prop ].apply( this, args ); + } + return function() { - var __super = this._super, - __superApply = this._superApply, - returnValue; + var __super = this._super; + var __superApply = this._superApply; + var returnValue; this._super = _super; this._superApply = _superApply; @@ -159,7 +161,8 @@ $.widget = function( name, base, prototype ) { // Redefine the child widget using the same prototype that was // originally used, but inherit from the new version of the base - $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto ); + $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, + child._proto ); } ); // Remove the list of existing child constructors from the old constructor @@ -175,11 +178,12 @@ $.widget = function( name, base, prototype ) { }; $.widget.extend = function( target ) { - var input = widgetSlice.call( arguments, 1 ), - inputIndex = 0, - inputLength = input.length, - key, - value; + var input = widgetSlice.call( arguments, 1 ); + var inputIndex = 0; + var inputLength = input.length; + var key; + var value; + for ( ; inputIndex < inputLength; inputIndex++ ) { for ( key in input[ inputIndex ] ) { value = input[ inputIndex ][ key ]; @@ -206,26 +210,31 @@ $.widget.extend = function( target ) { $.widget.bridge = function( name, object ) { var fullName = object.prototype.widgetFullName || name; $.fn[ name ] = function( options ) { - var isMethodCall = typeof options === "string", - args = widgetSlice.call( arguments, 1 ), - returnValue = this; + var isMethodCall = typeof options === "string"; + var args = widgetSlice.call( arguments, 1 ); + var returnValue = this; if ( isMethodCall ) { this.each( function() { - var methodValue, - instance = $.data( this, fullName ); + var methodValue; + var instance = $.data( this, fullName ); + 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" ); } + methodValue = instance[ options ].apply( instance, args ); + if ( methodValue !== instance && methodValue !== undefined ) { returnValue = methodValue && methodValue.jquery ? returnValue.pushStack( methodValue.get() ) : @@ -264,6 +273,7 @@ $.Widget.prototype = { widgetName: "widget", widgetEventPrefix: "", defaultElement: "