From a5051924207365297ec7665df875cfefc39dc858 Mon Sep 17 00:00:00 2001 From: Scott González Date: Tue, 3 Apr 2012 19:59:08 -0400 Subject: Tabs: Coding standards. --- ui/jquery.ui.tabs.js | 70 +++++++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 36 deletions(-) (limited to 'ui/jquery.ui.tabs.js') diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index 68c182c31..95113fc57 100644 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -95,8 +95,8 @@ $.widget( "ui.tabs", { // into account and update option properly. if ( $.isArray( options.disabled ) ) { options.disabled = $.unique( options.disabled.concat( - $.map( this.lis.filter( ".ui-state-disabled" ), function( n, i ) { - return that.lis.index( n ); + $.map( this.lis.filter( ".ui-state-disabled" ), function( li ) { + return that.lis.index( li ); }) ) ).sort(); } @@ -162,13 +162,12 @@ $.widget( "ui.tabs", { }, _sanitizeSelector: function( hash ) { - // we need this because an id may contain a ":" return hash ? hash.replace( /[!"$%&'()*+,.\/:;<=>?@[\]^`{|}~]/g, "\\$&" ) : ""; }, refresh: function() { var next, - self = this, + that = this, options = this.options, lis = this.list.children( ":has(a[href])" ); @@ -216,14 +215,14 @@ $.widget( "ui.tabs", { }, _processTabs: function() { - var self = this; + var that = this; this.list = this._getList(); - this.lis = $( " > li:has(a[href])", this.list ); + this.lis = this.list.find( "> li:has(a[href])" ); this.anchors = this.lis.map(function() { return $( "a", this )[ 0 ]; }); - this.panels = $( [] ); + this.panels = $(); this.anchors.each(function( i, a ) { var selector, panel, id; @@ -231,20 +230,20 @@ $.widget( "ui.tabs", { // inline tab if ( isLocal( a ) ) { selector = a.hash; - panel = self.element.find( self._sanitizeSelector( selector ) ); + panel = that.element.find( that._sanitizeSelector( selector ) ); // remote tab } else { - id = self._tabId( a ); + id = that._tabId( a ); selector = "#" + id; - panel = self.element.find( selector ); + panel = that.element.find( selector ); if ( !panel.length ) { - panel = self._createPanel( id ); - panel.insertAfter( self.panels[ i - 1 ] || self.list ); + panel = that._createPanel( id ); + panel.insertAfter( that.panels[ i - 1 ] || that.list ); } } if ( panel.length) { - self.panels = self.panels.add( panel ); + that.panels = that.panels.add( panel ); } $( a ).attr( "aria-controls", selector.substring( 1 ) ); }); @@ -256,10 +255,10 @@ $.widget( "ui.tabs", { }, _createPanel: function( id ) { - return $( "
" ) - .attr( "id", id ) - .addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" ) - .data( "ui-tabs-destroy", true ); + return $( "
" ) + .attr( "id", id ) + .addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" ) + .data( "ui-tabs-destroy", true ); }, _setupDisabled: function( disabled ) { @@ -273,7 +272,8 @@ $.widget( "ui.tabs", { // disable tabs for ( var i = 0, li; ( li = this.lis[ i ] ); i++ ) { - $( li ).toggleClass( "ui-state-disabled", ( disabled === true || $.inArray( i, disabled ) !== -1 ) ); + $( li ).toggleClass( "ui-state-disabled", + ( disabled === true || $.inArray( i, disabled ) !== -1 ) ); } this.options.disabled = disabled; @@ -302,11 +302,13 @@ $.widget( "ui.tabs", { // attach tab event handler, unbind to avoid duplicates from former tabifying... this.anchors.unbind( ".tabs" ); + // TODO: use event delegation via _bind() if ( event ) { this.anchors.bind( event.split( " " ).join( ".tabs " ) + ".tabs", $.proxy( this, "_eventHandler" ) ); } + // TODO: use event delegation via _bind() // disable click in any case this.anchors.bind( "click.tabs", function( event ){ event.preventDefault(); @@ -353,14 +355,12 @@ $.widget( "ui.tabs", { } if ( !toHide.length && !toShow.length ) { - throw "jQuery UI Tabs: Mismatching fragment identifier."; + jQuery.error( "jQuery UI Tabs: Mismatching fragment identifier." ); } if ( toShow.length ) { - // TODO make passing in node possible that.load( that.anchors.index( clicked ), event ); - clicked[ 0 ].blur(); } that._toggle( event, eventData ); @@ -429,7 +429,7 @@ $.widget( "ui.tabs", { _findActive: function( selector ) { return typeof selector === "number" ? this.anchors.eq( selector ) : - typeof selector === "string" ? this.anchors.filter( "[href$='" + selector + "']" ) : $(); + typeof selector === "string" ? this.anchors.filter( "[href$='" + selector + "']" ) : $(); }, _getIndex: function( index ) { @@ -525,10 +525,10 @@ $.widget( "ui.tabs", { load: function( index, event ) { index = this._getIndex( index ); - var self = this, + var that = this, options = this.options, anchor = this.anchors.eq( index ), - panel = self._getPanelForTab( anchor ), + panel = that._getPanelForTab( anchor ), eventData = { tab: anchor, panel: panel @@ -542,7 +542,7 @@ $.widget( "ui.tabs", { this.xhr = $.ajax({ url: anchor.attr( "href" ), beforeSend: function( jqXHR, settings ) { - return self._trigger( "beforeLoad", event, + return that._trigger( "beforeLoad", event, $.extend( { jqXHR : jqXHR, ajaxSettings: settings }, eventData ) ); } }); @@ -556,7 +556,7 @@ $.widget( "ui.tabs", { // remove when core #10467 is fixed setTimeout(function() { panel.html( response ); - self._trigger( "load", event, eventData ); + that._trigger( "load", event, eventData ); }, 1 ); }) .complete(function( jqXHR, status ) { @@ -564,19 +564,17 @@ $.widget( "ui.tabs", { // remove when core #10467 is fixed setTimeout(function() { if ( status === "abort" ) { - self.panels.stop( false, true ); + that.panels.stop( false, true ); } - self.lis.eq( index ).removeClass( "ui-tabs-loading" ); + that.lis.eq( index ).removeClass( "ui-tabs-loading" ); - if ( jqXHR === self.xhr ) { - delete self.xhr; + if ( jqXHR === that.xhr ) { + delete that.xhr; } }, 1 ); }); } - - return this; }, _getPanelForTab: function( tab ) { @@ -614,7 +612,7 @@ if ( $.uiBackCompat !== false ) { _create: function() { this._super(); - var self = this; + var that = this; this.element.bind( "tabsbeforeload.tabs", function( event, ui ) { // tab is already cached @@ -623,21 +621,21 @@ if ( $.uiBackCompat !== false ) { return; } - $.extend( ui.ajaxSettings, self.options.ajaxOptions, { + $.extend( ui.ajaxSettings, that.options.ajaxOptions, { error: function( xhr, s, e ) { try { // Passing index avoid a race condition when this method is // called after the user has selected another tab. // Pass the anchor that initiated this request allows // loadError to manipulate the tab content panel via $(a.hash) - self.options.ajaxOptions.error( xhr, s, ui.tab.closest( "li" ).index(), ui.tab[ 0 ] ); + that.options.ajaxOptions.error( xhr, s, ui.tab.closest( "li" ).index(), ui.tab[ 0 ] ); } catch ( e ) {} } }); ui.jqXHR.success(function() { - if ( self.options.cache ) { + if ( that.options.cache ) { $.data( ui.tab[ 0 ], "cache.tabs", true ); } }); -- cgit v1.2.3 From 79f1eea6dc874accae3447891783566337e97736 Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Wed, 4 Apr 2012 10:52:41 +0200 Subject: Build: Filter filters for linting to exclude some to-be-rewritten ones. Fix lint in those remaining --- grunt.js | 7 +++++-- ui/jquery.ui.autocomplete.js | 10 +++++----- ui/jquery.ui.menu.js | 2 +- ui/jquery.ui.position.js | 2 +- ui/jquery.ui.tabs.js | 4 ++-- 5 files changed, 14 insertions(+), 11 deletions(-) (limited to 'ui/jquery.ui.tabs.js') diff --git a/grunt.js b/grunt.js index 74713be5d..3d861be85 100644 --- a/grunt.js +++ b/grunt.js @@ -261,11 +261,14 @@ grunt.initConfig({ files: grunt.file.expandFiles( "tests/unit/**/*.html" ).filter(function( file ) { // disabling everything that doesn't (quite) work with PhantomJS for now // except for all|index|test, try to include more as we go - return !( /(all|index|test|draggable|droppable|selectable|resizable|sortable|dialog|slider|datepicker|tabs|tabs_deprecated)\.html/ ).test( file ); + return !( /(all|all-active|index|test|draggable|droppable|selectable|resizable|sortable|dialog|slider|datepicker|tabs|tabs_deprecated)\.html/ ).test( file ); }) }, lint: { - ui: "ui/*", + ui: grunt.file.expandFiles( "ui/*.js" ).filter(function( file ) { + // remove items from this list once rewritten + return !( /(effects.core|mouse|datepicker|draggable|droppable|resizable|selectable|sortable)\.js$/ ).test( file ); + }), grunt: "grunt.js", tests: "tests/unit/**/*.js" }, diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index 226d40605..ab4d17584 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -107,13 +107,13 @@ $.widget( "ui.autocomplete", { // which causes forms to submit suppressKeyPress = true; event.preventDefault(); + self.menu.select( event ); } - //passthrough - ENTER and TAB both select the current element + break; case keyCode.TAB: - if ( !self.menu.active ) { - return; + if ( self.menu.active ) { + self.menu.select( event ); } - self.menu.select( event ); break; case keyCode.ESCAPE: if ( self.menu.element.is(":visible") ) { @@ -524,7 +524,7 @@ $.widget( "ui.autocomplete", { $.extend( $.ui.autocomplete, { escapeRegex: function( value ) { - return value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); + return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&"); }, filter: function(array, term) { var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" ); diff --git a/ui/jquery.ui.menu.js b/ui/jquery.ui.menu.js index af22c19b0..526789e9e 100644 --- a/ui/jquery.ui.menu.js +++ b/ui/jquery.ui.menu.js @@ -189,7 +189,7 @@ $.widget( "ui.menu", { character = prev + character; } function escape( value ) { - return value.replace( /[-[\]{}()*+?.,\\^$|#\s]/g , "\\$&" ); + return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&"); } match = this.activeMenu.children( ".ui-menu-item" ).filter( function() { return new RegExp("^" + escape(character), "i") diff --git a/ui/jquery.ui.position.js b/ui/jquery.ui.position.js index 7fe31626d..d751e9374 100644 --- a/ui/jquery.ui.position.js +++ b/ui/jquery.ui.position.js @@ -13,7 +13,7 @@ $.ui = $.ui || {}; var rhorizontal = /left|center|right/, rvertical = /top|center|bottom/, - roffset = /[+-]\d+%?/, + roffset = /[\+\-]\d+%?/, rposition = /^\w+/, rpercent = /%$/, center = "center", diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index 95113fc57..fb384e563 100644 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -162,7 +162,7 @@ $.widget( "ui.tabs", { }, _sanitizeSelector: function( hash ) { - return hash ? hash.replace( /[!"$%&'()*+,.\/:;<=>?@[\]^`{|}~]/g, "\\$&" ) : ""; + return hash ? hash.replace( /[!"$%&'()*+,.\/:;<=>?@\[\]\^`{|}~]/g, "\\$&" ) : ""; }, refresh: function() { @@ -841,7 +841,7 @@ if ( $.uiBackCompat !== false ) { _tabId: function( a ) { return $( a ).attr( "aria-controls" ) || - a.title && a.title.replace( /\s/g, "_" ).replace( /[^\w\u00c0-\uFFFF-]/g, "" ) || + a.title && a.title.replace( /\s/g, "_" ).replace( /[^\w\u00c0-\uFFFF\-]/g, "" ) || this.options.idPrefix + getNextTabId(); } }); -- cgit v1.2.3 From c0f5db539403f1b9c5a80db75d127d4465f911df Mon Sep 17 00:00:00 2001 From: Scott González Date: Fri, 6 Apr 2012 09:02:39 -0400 Subject: Tabs: Don't explicitly remove filter when animating opacity. Fixes #4621 - Tabs: Don't forcefully remove filter attribute. --- ui/jquery.ui.tabs.js | 9 --------- 1 file changed, 9 deletions(-) (limited to 'ui/jquery.ui.tabs.js') diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index fb384e563..e42bcb1a2 100644 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -291,13 +291,6 @@ $.widget( "ui.tabs", { } }, - // TODO: remove once jQuery core properly removes filters - see #4621 - _resetStyle: function ( $el, fx ) { - if ( !$.support.opacity && fx.opacity ) { - $el[ 0 ].style.removeAttribute( "filter" ); - } - }, - _setupEvents: function( event ) { // attach tab event handler, unbind to avoid duplicates from former tabifying... this.anchors.unbind( ".tabs" ); @@ -386,7 +379,6 @@ $.widget( "ui.tabs", { if ( toShow.length && that.showFx ) { toShow .animate( that.showFx, that.showFx.duration || "normal", function() { - that._resetStyle( $( this ), that.showFx ); complete(); }); } else { @@ -399,7 +391,6 @@ $.widget( "ui.tabs", { if ( toHide.length && that.hideFx ) { toHide.animate( that.hideFx, that.hideFx.duration || "normal", function() { eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" ); - that._resetStyle( $( this ), that.hideFx ); show(); }); } else { -- cgit v1.2.3 From 57d18cd6b7a3d5a6a1b3436481a2fbe1d835eb29 Mon Sep 17 00:00:00 2001 From: Scott González Date: Sat, 28 Apr 2012 17:36:38 -0400 Subject: Removed some unused variables. --- grunt.js | 4 +--- ui/jquery.effects.scale.js | 5 +---- ui/jquery.effects.slide.js | 3 +-- ui/jquery.ui.position.js | 5 +---- ui/jquery.ui.tabs.js | 5 ----- 5 files changed, 4 insertions(+), 18 deletions(-) (limited to 'ui/jquery.ui.tabs.js') diff --git a/grunt.js b/grunt.js index dda89caf0..01c0071af 100644 --- a/grunt.js +++ b/grunt.js @@ -5,8 +5,6 @@ var // modules fs = require( "fs" ), path = require( "path" ), request = require( "request" ), - util = require( "util" ), - inspect = util.inspect, // files coreFiles = [ @@ -340,7 +338,7 @@ grunt.initConfig({ grunt.registerTask( "testswarm", function( commit, authToken ) { var testswarm = require( "testswarm" ); var testBase = "http://swarm.jquery.org/git/jquery-ui/" + commit + "/"; - require( "testswarm" )( { + testswarm({ url: "http://swarm.jquery.org/api.php?", pollInterval: 2000, done: this.async() diff --git a/ui/jquery.effects.scale.js b/ui/jquery.effects.scale.js index 1eedb44eb..5352bde77 100644 --- a/ui/jquery.effects.scale.js +++ b/ui/jquery.effects.scale.js @@ -267,10 +267,7 @@ $.effects.effect.size = function( o, done ) { $.each([ "top", "left" ], function( idx, pos ) { el.css( pos, function( _, str ) { var val = parseInt( str, 10 ), - toRef = idx ? el.to.left : el.to.top, - delta = idx ? el.to.outerWidth - el.from.outerWidth: el.to.outerHeight - el.from.outerHeight, - same = origin[ idx ] === pos, - mid = origin[ idx ] === "middle" || origin[ idx ] === "center"; + toRef = idx ? el.to.left : el.to.top; // if original was "auto", recalculate the new value from wrapper if ( str === "auto" ) { diff --git a/ui/jquery.effects.slide.js b/ui/jquery.effects.slide.js index e57a21264..ae25a187e 100644 --- a/ui/jquery.effects.slide.js +++ b/ui/jquery.effects.slide.js @@ -23,8 +23,7 @@ $.effects.effect.slide = function( o, done ) { ref = (direction === "up" || direction === "down") ? "top" : "left", positiveMotion = (direction === "up" || direction === "left"), distance, - animation = {}, - size; + animation = {}; // Adjust $.effects.save( el, props ); diff --git a/ui/jquery.ui.position.js b/ui/jquery.ui.position.js index cb82cd4f1..bd7bfb015 100644 --- a/ui/jquery.ui.position.js +++ b/ui/jquery.ui.position.js @@ -286,8 +286,7 @@ $.ui.position = { collisionPosLeft = position.left - data.collisionPosition.marginLeft, overLeft = withinOffset - collisionPosLeft, overRight = collisionPosLeft + data.collisionWidth - outerWidth - withinOffset, - newOverRight, - newOverLeft; + newOverRight; // element is wider than within if ( data.collisionWidth > outerWidth ) { @@ -324,7 +323,6 @@ $.ui.position = { collisionPosTop = position.top - data.collisionPosition.marginTop, overTop = withinOffset - collisionPosTop, overBottom = collisionPosTop + data.collisionHeight - outerHeight - withinOffset, - newOverTop, newOverBottom; // element is taller than within @@ -365,7 +363,6 @@ $.ui.position = { collisionPosLeft = position.left - data.collisionPosition.marginLeft, overLeft = collisionPosLeft - offsetLeft, overRight = collisionPosLeft + data.collisionWidth - outerWidth - offsetLeft, - left = data.my[ 0 ] === "left", myOffset = data.my[ 0 ] === "left" ? -data.elemWidth : data.my[ 0 ] === "right" ? diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index e42bcb1a2..026c50993 100644 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -167,7 +167,6 @@ $.widget( "ui.tabs", { refresh: function() { var next, - that = this, options = this.options, lis = this.list.children( ":has(a[href])" ); @@ -362,7 +361,6 @@ $.widget( "ui.tabs", { // handles show/hide for selecting tabs _toggle: function( event, eventData ) { var that = this, - options = that.options, toShow = eventData.newPanel, toHide = eventData.oldPanel; @@ -434,8 +432,6 @@ $.widget( "ui.tabs", { }, _destroy: function() { - var o = this.options; - if ( this.xhr ) { this.xhr.abort(); } @@ -517,7 +513,6 @@ $.widget( "ui.tabs", { load: function( index, event ) { index = this._getIndex( index ); var that = this, - options = this.options, anchor = this.anchors.eq( index ), panel = that._getPanelForTab( anchor ), eventData = { -- cgit v1.2.3