From d22edc8d05408ffe088d1c6e3f09c0ba60936c2a Mon Sep 17 00:00:00 2001 From: "Rick Waldron waldron.rick@gmail.com" Date: Thu, 12 Apr 2012 13:32:11 -0400 Subject: [PATCH 01/34] Remove compare_size; defer to plugin. Signed-off-by: Rick Waldron waldron.rick@gmail.com --- grunt.js | 73 ++-------------------------------------------------- package.json | 3 ++- 2 files changed, 4 insertions(+), 72 deletions(-) diff --git a/grunt.js b/grunt.js index 0887cad4c..83657849e 100644 --- a/grunt.js +++ b/grunt.js @@ -70,6 +70,8 @@ cssFiles.forEach(function( file ) { // csslint and cssmin tasks grunt.loadNpmTasks( "grunt-css" ); +// file size comparison tasks +grunt.loadNpmTasks( "grunt-compare-size" ); grunt.registerHelper( "strip_all_banners", function( filepath ) { return grunt.file.read( filepath ).replace( /^\s*\/\*[\s\S]*?\*\/\s*/g, "" ); @@ -537,77 +539,6 @@ grunt.registerTask( "clean", function() { require( "rimraf" ).sync( "dist" ); }); -// TODO merge with code in jQuery Core, share as grunt plugin/npm -// this here actually uses the provided filenames in the output -// the helpers should just be regular functions, no need to share those with the world -grunt.registerMultiTask( "compare_size", "Compare size of this branch to master", function() { - var files = grunt.file.expandFiles( this.file.src ), - done = this.async(), - sizecache = __dirname + "/dist/.sizecache.json", - sources = { - min: grunt.file.read( files[1] ), - max: grunt.file.read( files[0] ) - }, - oldsizes = {}, - sizes = {}; - - try { - oldsizes = JSON.parse( grunt.file.read( sizecache ) ); - } catch( e ) { - oldsizes = {}; - } - - // Obtain the current branch and continue... - grunt.helper( "git_current_branch", function( err, branch ) { - var key, diff; - - // Derived and adapted from Corey Frang's original `sizer` - grunt.log.writeln( "sizes - compared to master" ); - - sizes[ files[0] ] = sources.max.length; - sizes[ files[1] ] = sources.min.length; - sizes[ files[1] + ".gz" ] = grunt.helper( "gzip", sources.min ).length; - - for ( key in sizes ) { - diff = oldsizes[ key ] && ( sizes[ key ] - oldsizes[ key ] ); - if ( diff > 0 ) { - diff = "+" + diff; - } - console.log( "%s %s %s", - grunt.helper("lpad", sizes[ key ], 8 ), - grunt.helper("lpad", diff ? "(" + diff + ")" : "(-)", 8 ), - key - ); - } - - if ( branch === "master" ) { - // If master, write to file - this makes it easier to compare - // the size of your current code state to the master branch, - // without returning to the master to reset the cache - grunt.file.write( sizecache, JSON.stringify(sizes) ); - } - done(); - }); -}); -grunt.registerHelper( "git_current_branch", function( done ) { - grunt.utils.spawn({ - cmd: "git", - args: [ "branch", "--no-color" ] - }, function( err, result ) { - var branch; - - result.split( "\n" ).forEach(function( branch ) { - var matches = /^\* (.*)/.exec( branch ); - if ( matches !== null && matches.length && matches[ 1 ] ) { - done( null, matches[ 1 ] ); - } - }); - }); -}); -grunt.registerHelper( "lpad", function( str, len, chr ) { - return ( Array( len + 1 ).join( chr || " " ) + str ).substr( -len ); -}); - grunt.registerTask( "default", "lint csslint qunit build compare_size" ); grunt.registerTask( "sizer", "concat:ui min:dist/jquery-ui.min.js compare_size" ); grunt.registerTask( "build", "concat min cssmin" ); diff --git a/package.json b/package.json index 30e2b4898..1d24c8ab8 100644 --- a/package.json +++ b/package.json @@ -28,8 +28,9 @@ "devDependencies": { "grunt": "0.3.7", "grunt-css": "0.1.1", + "grunt-compare-size": "0.1.1", "request": "2.9.153", "rimraf": "2.0.1" }, "keywords": [] -} \ No newline at end of file +} From 26d6952bd2b81de2ad2adb0bb77c1be6f2d717c2 Mon Sep 17 00:00:00 2001 From: kborchers Date: Sat, 14 Apr 2012 15:33:48 -0400 Subject: [PATCH 02/34] Menu: Remove most event.stopImmediatePropagation() to allow proper event bubbling --- ui/jquery.ui.menu.js | 61 ++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/ui/jquery.ui.menu.js b/ui/jquery.ui.menu.js index 6982da3c3..01b7d0992 100644 --- a/ui/jquery.ui.menu.js +++ b/ui/jquery.ui.menu.js @@ -13,7 +13,8 @@ */ (function($) { -var idIncrement = 0; +var idIncrement = 0, + currentEventTarget; $.widget( "ui.menu", { version: "@VERSION", @@ -66,16 +67,22 @@ $.widget( "ui.menu", { event.preventDefault(); }, "click .ui-menu-item:has(a)": function( event ) { - event.stopImmediatePropagation(); - // Don't select disabled menu items - if ( !$( event.target ).closest( ".ui-menu-item" ).is( ".ui-state-disabled" ) ) { - this.select( event ); - // Redirect focus to the menu with a delay for firefox - this._delay(function() { - if ( !this.element.is(":focus") ) { - this.element.focus(); - } - }, 20 ); + var target = $( event.target ); + if ( target[0] != currentEventTarget ) { + currentEventTarget = target[0]; + target.one( "click", function( event ) { + currentEventTarget = ""; + }); + // Don't select disabled menu items + if ( !target.closest( ".ui-menu-item" ).is( ".ui-state-disabled" ) ) { + this.select( event ); + // Redirect focus to the menu with a delay for firefox + this._delay(function() { + if ( !this.element.is(":focus") ) { + this.element.focus(); + } + }, 20 ); + } } }, "mouseover .ui-menu-item": function( event ) { @@ -158,65 +165,49 @@ $.widget( "ui.menu", { case $.ui.keyCode.PAGE_UP: this.previousPage( event ); event.preventDefault(); - event.stopImmediatePropagation(); break; case $.ui.keyCode.PAGE_DOWN: this.nextPage( event ); event.preventDefault(); - event.stopImmediatePropagation(); break; case $.ui.keyCode.HOME: this._move( "first", "first", event ); event.preventDefault(); - event.stopImmediatePropagation(); break; case $.ui.keyCode.END: this._move( "last", "last", event ); event.preventDefault(); - event.stopImmediatePropagation(); break; case $.ui.keyCode.UP: this.previous( event ); event.preventDefault(); - event.stopImmediatePropagation(); break; case $.ui.keyCode.DOWN: this.next( event ); event.preventDefault(); - event.stopImmediatePropagation(); break; case $.ui.keyCode.LEFT: - if (this.collapse( event )) { - event.stopImmediatePropagation(); - } + this.collapse( event ); event.preventDefault(); break; case $.ui.keyCode.RIGHT: - if (this.expand( event )) { - event.stopImmediatePropagation(); - } + this.expand( event ); event.preventDefault(); break; case $.ui.keyCode.ENTER: if ( this.active.children( "a[aria-haspopup='true']" ).length ) { - if ( this.expand( event ) ) { - event.stopImmediatePropagation(); - } + this.expand( event ); } else { this.select( event ); - event.stopImmediatePropagation(); } event.preventDefault(); break; case $.ui.keyCode.ESCAPE: - if ( this.collapse( event ) ) { - event.stopImmediatePropagation(); - } + this.collapse( event ); event.preventDefault(); break; default: - event.stopPropagation(); clearTimeout( this.filterTimer ); var match, prev = this.previousFilter || "", @@ -303,7 +294,7 @@ $.widget( "ui.menu", { focus: function( event, item ) { var nested, borderTop, paddingTop, offset, scroll, elementHeight, itemHeight; - this.blur( event ); + this.blur( event, event.type == "focus" ); if ( this._hasScroll() ) { borderTop = parseFloat( $.css( this.activeMenu[0], "borderTopWidth" ) ) || 0; @@ -342,8 +333,10 @@ $.widget( "ui.menu", { this._trigger( "focus", event, { item: item } ); }, - blur: function( event ) { - clearTimeout( this.timer ); + blur: function( event, fromFocus ) { + if ( !fromFocus ) { + clearTimeout( this.timer ); + } if ( !this.active ) { return; From e2a6cdd5256e0befe8f75590499d501141a46463 Mon Sep 17 00:00:00 2001 From: kborchers Date: Sat, 14 Apr 2012 16:00:19 -0400 Subject: [PATCH 03/34] Menu: Check that the event object is defined before checking type --- ui/jquery.ui.menu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/jquery.ui.menu.js b/ui/jquery.ui.menu.js index 01b7d0992..5e6b335ba 100644 --- a/ui/jquery.ui.menu.js +++ b/ui/jquery.ui.menu.js @@ -294,7 +294,7 @@ $.widget( "ui.menu", { focus: function( event, item ) { var nested, borderTop, paddingTop, offset, scroll, elementHeight, itemHeight; - this.blur( event, event.type == "focus" ); + this.blur( event, event && event.type == "focus" ); if ( this._hasScroll() ) { borderTop = parseFloat( $.css( this.activeMenu[0], "borderTopWidth" ) ) || 0; From 6da7278e879c0dc734c23231a71fdd92f7a57a0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?= Date: Sun, 15 Apr 2012 14:25:55 -0400 Subject: [PATCH 04/34] Position: Simplify default demo by removing drag functionality on positioned elements. Fixes #5380 - Position Demo breaks when dragging an element. --- demos/position/default.html | 37 ++++++------------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/demos/position/default.html b/demos/position/default.html index 202417348..01137be62 100644 --- a/demos/position/default.html +++ b/demos/position/default.html @@ -1,4 +1,4 @@ - + @@ -37,53 +37,28 @@ width: 120px; height: 40px; } - .ui-flipped-top { - border-top: 3px solid #000000; - } - .ui-flipped-bottom { - border-bottom: 3px solid #000000; - } - .ui-flipped-left { - border-left: 3px solid #000000; - } - .ui-flipped-right { - border-right: 3px solid #000000; - } select, input { margin-left: 15px; } + - diff --git a/tests/unit/tabs/tabs_core.js b/tests/unit/tabs/tabs_core.js index 21250fb33..b9bd81987 100644 --- a/tests/unit/tabs/tabs_core.js +++ b/tests/unit/tabs/tabs_core.js @@ -1,5 +1,7 @@ (function( $ ) { +var state = TestHelpers.tabs.state; + module( "tabs: core" ); test( "markup structure", function() { @@ -89,7 +91,7 @@ test( "#4033 - IE expands hash to full url and misinterprets tab as ajax", funct }); equal( element.find( ".ui-tabs-nav a" ).attr( "aria-controls" ), "tab", "aria-contorls attribute is correct" ); - tabs_state( element, 1 ); + state( element, 1 ); }); }( jQuery ) ); diff --git a/tests/unit/tabs/tabs_deprecated.html b/tests/unit/tabs/tabs_deprecated.html index 410aebc40..c22ec3369 100644 --- a/tests/unit/tabs/tabs_deprecated.html +++ b/tests/unit/tabs/tabs_deprecated.html @@ -23,6 +23,7 @@ + @@ -30,62 +31,6 @@ - diff --git a/tests/unit/tabs/tabs_deprecated.js b/tests/unit/tabs/tabs_deprecated.js index c8f0e2881..8386a13ac 100644 --- a/tests/unit/tabs/tabs_deprecated.js +++ b/tests/unit/tabs/tabs_deprecated.js @@ -1,5 +1,7 @@ (function( $ ) { +var state = TestHelpers.tabs.state; + module( "tabs (deprecated): core" ); test( "panel ids", function() { @@ -48,17 +50,17 @@ asyncTest( "cache", function() { cache: true }); element.one( "tabsshow", function( event, ui ) { - tabs_state( element, 0, 0, 1, 0, 0 ); + state( element, 0, 0, 1, 0, 0 ); }); element.one( "tabsload", function( event, ui ) { ok( true, "tabsload" ); setTimeout(function() { element.tabs( "option", "active", 0 ); - tabs_state( element, 1, 0, 0, 0, 0 ); + state( element, 1, 0, 0, 0, 0 ); element.one( "tabsshow", function( event, ui ) { - tabs_state( element, 0, 0, 1, 0, 0 ); + state( element, 0, 0, 1, 0, 0 ); }); element.one( "tabsload", function( event, ui ) { ok( false, "should be cached" ); @@ -68,7 +70,7 @@ asyncTest( "cache", function() { }, 1 ); }); element.tabs( "option", "active", 2 ); - tabs_state( element, 0, 0, 1, 0, 0 ); + state( element, 0, 0, 1, 0, 0 ); }); test( "idPrefix", function() { @@ -171,50 +173,50 @@ test( "selected", function() { var element = $( "#tabs1" ).tabs(); equal( element.tabs( "option", "selected" ), 0, "should be 0 by default" ); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); element.tabs( "destroy" ); location.hash = "#fragment-3"; element = $( "#tabs1" ).tabs(); equal( element.tabs( "option", "selected" ), 2, "should be 2 based on URL" ); - tabs_state( element, 0, 0, 1 ); + state( element, 0, 0, 1 ); element.tabs( "destroy" ); el = $('#tabs1').tabs({ selected: -1, collapsible: true }); - tabs_state( element, 0, 0, 0 ); + state( element, 0, 0, 0 ); equal( element.find( ".ui-tabs-nav .ui-state-active" ).size(), 0, "no tabs selected" ); strictEqual( element.tabs( "option", "selected" ), -1 ); element.tabs( "option", "collapsible", false ); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); equal( element.tabs( "option", "selected" ), 0 ); element.tabs( "destroy" ); element.tabs({ selected: -1 }); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); strictEqual( element.tabs( "option", "selected" ), 0 ); element.tabs( "destroy" ); element.tabs({ selected: 2 }); equal( element.tabs( "option", "selected" ), 2 ); - tabs_state( element, 0, 0, 1 ); + state( element, 0, 0, 1 ); element.tabs( "option", "selected", 0 ); equal( element.tabs( "option", "selected" ), 0 ); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); element.find( ".ui-tabs-nav a" ).eq( 1 ).click(); equal( element.tabs( "option", "selected" ), 1 ); - tabs_state( element, 0, 1, 0 ); + state( element, 0, 1, 0 ); element.tabs( "option", "selected", 10 ); equal( element.tabs( "option", "selected" ), 1 ); - tabs_state( element, 0, 1, 0 ); + state( element, 0, 1, 0 ); location.hash = "#"; }); @@ -237,7 +239,7 @@ asyncTest( "load", function() { strictEqual( ui.tab, tab[ 0 ], "tab" ); strictEqual( ui.panel, panel[ 0 ], "panel" ); equal( $( ui.panel ).find( "p" ).length, 1, "panel html" ); - tabs_state( element, 0, 0, 1, 0, 0 ); + state( element, 0, 0, 1, 0, 0 ); tabsload1(); }); element.tabs({ active: 2 }); @@ -253,7 +255,7 @@ asyncTest( "load", function() { strictEqual( ui.tab, tab[ 0 ], "tab" ); strictEqual( ui.panel, panel[ 0 ], "panel" ); equal( $( ui.panel ).find( "p" ).length, 1, "panel html" ); - tabs_state( element, 0, 0, 0, 1, 0 ); + state( element, 0, 0, 0, 1, 0 ); tabsload2(); }); element.tabs( "option", "active", 3 ); @@ -270,7 +272,7 @@ asyncTest( "load", function() { strictEqual( ui.tab, tab[ 0 ], "tab" ); strictEqual( ui.panel, panel[ 0 ], "panel" ); equal( $( ui.panel ).find( "p" ).length, 1, "panel html" ); - tabs_state( element, 0, 0, 0, 0, 1 ); + state( element, 0, 0, 0, 0, 1 ); start(); }); element.find( ".ui-tabs-nav a" ).eq( 4 ).click(); @@ -325,10 +327,10 @@ test( "show", function() { strictEqual( ui.tab, tabs[ 0 ], "ui.tab" ); strictEqual( ui.panel, panels[ 0 ], "ui.panel" ); equal( ui.index, 0, "ui.index" ); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); }); element.tabs( "option", "active", 0 ); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); // switching tabs element.one( "tabsshow", function( event, ui ) { @@ -336,17 +338,17 @@ test( "show", function() { strictEqual( ui.tab, tabs[ 1 ], "ui.tab" ); strictEqual( ui.panel, panels[ 1 ], "ui.panel" ); equal( ui.index, 1, "ui.index" ); - tabs_state( element, 0, 1, 0 ); + state( element, 0, 1, 0 ); }); tabs.eq( 1 ).click(); - tabs_state( element, 0, 1, 0 ); + state( element, 0, 1, 0 ); // collapsing element.one( "tabsshow", function( event, ui ) { ok( false, "collapsing" ); }); element.tabs( "option", "active", false ); - tabs_state( element, 0, 0, 0 ); + state( element, 0, 0, 0 ); }); test( "select", function() { @@ -365,10 +367,10 @@ test( "select", function() { strictEqual( ui.tab, tabs[ 0 ], "ui.tab" ); strictEqual( ui.panel, panels[ 0 ], "ui.panel" ); equal( ui.index, 0, "ui.index" ); - tabs_state( element, 0, 0, 0 ); + state( element, 0, 0, 0 ); }); element.tabs( "option", "active", 0 ); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); // switching tabs element.one( "tabsselect", function( event, ui ) { @@ -376,17 +378,17 @@ test( "select", function() { strictEqual( ui.tab, tabs[ 1 ], "ui.tab" ); strictEqual( ui.panel, panels[ 1 ], "ui.panel" ); equal( ui.index, 1, "ui.index" ); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); }); tabs.eq( 1 ).click(); - tabs_state( element, 0, 1, 0 ); + state( element, 0, 1, 0 ); // collapsing element.one( "tabsselect", function( event, ui ) { ok( false, "collapsing" ); }); element.tabs( "option", "active", false ); - tabs_state( element, 0, 0, 0 ); + state( element, 0, 0, 0 ); }); module( "tabs (deprecated): methods" ); @@ -396,7 +398,7 @@ test( "add", function() { var tab, anchor, element = $( "#tabs1" ).tabs(); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); // add without index element.one( "tabsadd", function( event, ui ) { @@ -405,7 +407,7 @@ test( "add", function() { equal( ui.panel.id, "new", "ui.panel" ); }); element.tabs( "add", "#new", "New" ); - tabs_state( element, 1, 0, 0, 0 ); + state( element, 1, 0, 0, 0 ); tab = element.find( ".ui-tabs-nav li" ).last(); anchor = tab.find( "a" ); equal( tab.text(), "New", "label" ); @@ -415,7 +417,7 @@ test( "add", function() { anchor.simulate( "mouseover" ); ok( tab.hasClass( "ui-state-hover" ), "hovered" ); anchor.simulate( "click" ); - tabs_state( element, 0, 0, 0, 1 ); + state( element, 0, 0, 0, 1 ); // add remote tab with index element.one( "tabsadd", function( event, ui ) { @@ -424,7 +426,7 @@ test( "add", function() { equal( ui.panel.id, $( ui.tab ).attr( "aria-controls" ), "ui.panel" ); }); element.tabs( "add", "data/test.html", "New Remote", 1 ); - tabs_state( element, 0, 0, 0, 0, 1 ); + state( element, 0, 0, 0, 0, 1 ); tab = element.find( ".ui-tabs-nav li" ).eq( 1 ); anchor = tab.find( "a" ); equal( tab.text(), "New Remote", "label" ); @@ -434,7 +436,7 @@ test( "add", function() { anchor.simulate( "mouseover" ); ok( tab.hasClass( "ui-state-hover" ), "hovered" ); anchor.simulate( "click" ); - tabs_state( element, 0, 1, 0, 0, 0 ); + state( element, 0, 1, 0, 0, 0 ); // add to empty tab set element = $( "
    " ).tabs(); @@ -445,7 +447,7 @@ test( "add", function() { equal( ui.panel.id, "first", "ui.panel" ); }); element.tabs( "add", "#first", "First" ); - tabs_state( element, 1 ); + state( element, 1 ); equal( element.tabs( "option", "active" ), 0, "active: 0 after add" ); }); @@ -462,7 +464,7 @@ test( "remove", function() { expect( 17 ); var element = $( "#tabs1" ).tabs({ active: 1 }); - tabs_state( element, 0, 1, 0 ); + state( element, 0, 1, 0 ); element.one( "tabsremove", function( event, ui ) { equal( ui.index, -1, "ui.index" ); @@ -470,7 +472,7 @@ test( "remove", function() { equal( ui.panel.id, "fragment-2", "ui.panel" ); }); element.tabs( "remove", 1 ); - tabs_state( element, 0, 1 ); + state( element, 0, 1 ); equal( element.tabs( "option", "active" ), 1 ); equal( element.find( ".ui-tabs-nav li a[href$='fragment-2']" ).length, 0, "remove correct list item" ); @@ -482,7 +484,7 @@ test( "remove", function() { equal( ui.panel.id, "fragment-3", "ui.panel" ); }); element.tabs( "remove", 1 ); - tabs_state( element, 1 ); + state( element, 1 ); equal( element.tabs( "option", "active"), 0 ); element.one( "tabsremove", function( event, ui ) { @@ -498,43 +500,43 @@ test( "select", function() { expect( 23 ); var element = $( "#tabs1" ).tabs(); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); element.tabs( "select", 1 ); - tabs_state( element, 0, 1, 0 ); + state( element, 0, 1, 0 ); equal( element.tabs( "option", "active" ), 1, "active" ); equal( element.tabs( "option", "selected" ), 1, "selected" ); element.tabs( "destroy" ); element.tabs({ collapsible: true }); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); element.tabs( "select", 0 ); - tabs_state( element, 0, 0, 0 ); + state( element, 0, 0, 0 ); equal( element.tabs( "option", "active" ), false, "active" ); equal( element.tabs( "option", "selected" ), -1, "selected" ); element.tabs( "destroy" ); element.tabs({ collapsible: true }); element.tabs( "select", -1 ); - tabs_state( element, 0, 0, 0 ); + state( element, 0, 0, 0 ); equal( element.tabs( "option", "active" ), false, "active" ); equal( element.tabs( "option", "selected" ), -1, "selected" ); element.tabs( "destroy" ); element.tabs(); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); equal( element.tabs( "option", "active" ), 0, "active" ); equal( element.tabs( "option", "selected" ), 0, "selected" ); element.tabs( "select", 0 ); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); equal( element.tabs( "option", "active" ), 0, "active" ); equal( element.tabs( "option", "selected" ), 0, "selected" ); element.tabs( "select", -1 ); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); equal( element.tabs( "option", "active" ), 0, "active" ); equal( element.tabs( "option", "selected" ), 0, "selected" ); element.tabs( "select", "#fragment-2" ); - tabs_state( element, 0, 1, 0 ); + state( element, 0, 1, 0 ); equal( element.tabs( "option", "active" ), 1, "active" ); equal( element.tabs( "option", "selected" ), 1, "selected" ); }); diff --git a/tests/unit/tabs/tabs_events.js b/tests/unit/tabs/tabs_events.js index 4f9269b62..3f6ec14d0 100644 --- a/tests/unit/tabs/tabs_events.js +++ b/tests/unit/tabs/tabs_events.js @@ -1,5 +1,7 @@ (function( $ ) { +var state = TestHelpers.tabs.state; + module( "tabs: events" ); test( "create", function() { @@ -60,10 +62,10 @@ test( "beforeActivate", function() { strictEqual( ui.newTab[ 0 ], tabs[ 0 ], "newTab" ); equal( ui.newPanel.size(), 1, "newPanel size" ); strictEqual( ui.newPanel[ 0 ], panels[ 0 ], "newPanel" ); - tabs_state( element, 0, 0, 0 ); + state( element, 0, 0, 0 ); }); element.tabs( "option", "active", 0 ); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); // switching tabs element.one( "tabsbeforeactivate", function( event, ui ) { @@ -76,10 +78,10 @@ test( "beforeActivate", function() { strictEqual( ui.newTab[ 0 ], tabs[ 1 ], "newTab" ); equal( ui.newPanel.size(), 1, "newPanel size" ); strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" ); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); }); tabs.eq( 1 ).click(); - tabs_state( element, 0, 1, 0 ); + state( element, 0, 1, 0 ); // collapsing element.one( "tabsbeforeactivate", function( event, ui ) { @@ -90,10 +92,10 @@ test( "beforeActivate", function() { strictEqual( ui.oldPanel[ 0 ], panels[ 1 ], "oldPanel" ); equal( ui.newTab.size(), 0, "newTab size" ); equal( ui.newPanel.size(), 0, "newPanel size" ); - tabs_state( element, 0, 1, 0 ); + state( element, 0, 1, 0 ); }); element.tabs( "option", "active", false ); - tabs_state( element, 0, 0, 0 ); + state( element, 0, 0, 0 ); // prevent activation element.one( "tabsbeforeactivate", function( event, ui ) { @@ -105,10 +107,10 @@ test( "beforeActivate", function() { equal( ui.newPanel.size(), 1, "newPanel size" ); strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" ); event.preventDefault(); - tabs_state( element, 0, 0, 0 ); + state( element, 0, 0, 0 ); }); element.tabs( "option", "active", 1 ); - tabs_state( element, 0, 0, 0 ); + state( element, 0, 0, 0 ); }); test( "activate", function() { @@ -130,10 +132,10 @@ test( "activate", function() { strictEqual( ui.newTab[ 0 ], tabs[ 0 ], "newTab" ); equal( ui.newPanel.size(), 1, "newPanel size" ); strictEqual( ui.newPanel[ 0 ], panels[ 0 ], "newPanel" ); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); }); element.tabs( "option", "active", 0 ); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); // switching tabs element.one( "tabsactivate", function( event, ui ) { @@ -146,10 +148,10 @@ test( "activate", function() { strictEqual( ui.newTab[ 0 ], tabs[ 1 ], "newTab" ); equal( ui.newPanel.size(), 1, "newPanel size" ); strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" ); - tabs_state( element, 0, 1, 0 ); + state( element, 0, 1, 0 ); }); tabs.eq( 1 ).click(); - tabs_state( element, 0, 1, 0 ); + state( element, 0, 1, 0 ); // collapsing element.one( "tabsactivate", function( event, ui ) { @@ -160,10 +162,10 @@ test( "activate", function() { strictEqual( ui.oldPanel[ 0 ], panels[ 1 ], "oldPanel" ); equal( ui.newTab.size(), 0, "newTab size" ); equal( ui.newPanel.size(), 0, "newPanel size" ); - tabs_state( element, 0, 0, 0 ); + state( element, 0, 0, 0 ); }); element.tabs( "option", "active", false ); - tabs_state( element, 0, 0, 0 ); + state( element, 0, 0, 0 ); // prevent activation element.one( "tabsbeforeactivate", function( event ) { @@ -197,10 +199,10 @@ test( "beforeLoad", function() { strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); equal( ui.panel.html(), "", "panel html" ); event.preventDefault(); - tabs_state( element, 0, 0, 1, 0, 0 ); + state( element, 0, 0, 1, 0, 0 ); }); element.tabs({ active: 2 }); - tabs_state( element, 0, 0, 1, 0, 0 ); + state( element, 0, 0, 1, 0, 0 ); equal( panel.html(), "", "panel html after" ); element.tabs( "destroy" ); @@ -219,11 +221,11 @@ test( "beforeLoad", function() { strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); equal( ui.panel.html(), "", "panel html" ); event.preventDefault(); - tabs_state( element, 1, 0, 0, 0, 0 ); + state( element, 1, 0, 0, 0, 0 ); }); element.tabs(); element.tabs( "option", "active", 2 ); - tabs_state( element, 0, 0, 1, 0, 0 ); + state( element, 0, 0, 1, 0, 0 ); equal( panel.html(), "", "panel html after" ); // click, change panel content @@ -241,10 +243,10 @@ test( "beforeLoad", function() { strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); ui.panel.html( "

    testing

    " ); event.preventDefault(); - tabs_state( element, 0, 0, 1, 0, 0 ); + state( element, 0, 0, 1, 0, 0 ); }); element.find( ".ui-tabs-nav a" ).eq( 3 ).click(); - tabs_state( element, 0, 0, 0, 1, 0 ); + state( element, 0, 0, 0, 1, 0 ); // .toLowerCase() is needed to convert

    to

    in old IEs equal( panel.html().toLowerCase(), "

    testing

    ", "panel html after" ); }); @@ -268,7 +270,7 @@ if ( $.uiBackCompat === false ) { equal( ui.panel.size(), 1, "panel size" ); strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); equal( ui.panel.find( "p" ).length, 1, "panel html" ); - tabs_state( element, 0, 0, 1, 0, 0 ); + state( element, 0, 0, 1, 0, 0 ); tabsload1(); }); element.tabs({ active: 2 }); @@ -286,7 +288,7 @@ if ( $.uiBackCompat === false ) { equal( ui.panel.size(), 1, "panel size" ); strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); equal( ui.panel.find( "p" ).length, 1, "panel html" ); - tabs_state( element, 0, 0, 0, 1, 0 ); + state( element, 0, 0, 0, 1, 0 ); tabsload2(); }); element.tabs( "option", "active", 3 ); @@ -305,7 +307,7 @@ if ( $.uiBackCompat === false ) { equal( ui.panel.size(), 1, "panel size" ); strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); equal( ui.panel.find( "p" ).length, 1, "panel html" ); - tabs_state( element, 0, 0, 0, 0, 1 ); + state( element, 0, 0, 0, 0, 1 ); start(); }); element.find( ".ui-tabs-nav a" ).eq( 4 ).click(); diff --git a/tests/unit/tabs/tabs_methods.js b/tests/unit/tabs/tabs_methods.js index 0a59ae302..61ce78189 100644 --- a/tests/unit/tabs/tabs_methods.js +++ b/tests/unit/tabs/tabs_methods.js @@ -1,5 +1,8 @@ (function( $ ) { +var disabled = TestHelpers.tabs.disabled, + state = TestHelpers.tabs.state; + module( "tabs: methods" ); test( "destroy", function() { @@ -12,95 +15,95 @@ test( "enable", function() { expect( 8 ); var element = $( "#tabs1" ).tabs({ disabled: true }); - tabs_disabled( element, true ); + disabled( element, true ); element.tabs( "enable" ); - tabs_disabled( element, false ); + disabled( element, false ); element.tabs( "destroy" ); element.tabs({ disabled: [ 0, 1 ] }); - tabs_disabled( element, [ 0, 1 ] ); + disabled( element, [ 0, 1 ] ); element.tabs( "enable" ); - tabs_disabled( element, false ); + disabled( element, false ); }); test( "enable( index )", function() { expect( 10 ); var element = $( "#tabs1" ).tabs({ disabled: true }); - tabs_disabled( element, true ); + disabled( element, true ); // fully disabled -> partially disabled element.tabs( "enable", 1 ); - tabs_disabled( element, [ 0, 2 ] ); + disabled( element, [ 0, 2 ] ); // partially disabled -> partially disabled element.tabs( "enable", 2 ); - tabs_disabled( element, [ 0 ] ); + disabled( element, [ 0 ] ); // already enabled tab, no change element.tabs( "enable", 2 ); - tabs_disabled( element, [ 0 ] ); + disabled( element, [ 0 ] ); // partially disabled -> fully enabled element.tabs( "enable", 0 ); - tabs_disabled( element, false ); + disabled( element, false ); }); test( "disable", function() { expect( 8 ); var element = $( "#tabs1" ).tabs({ disabled: false }); - tabs_disabled( element, false ); + disabled( element, false ); element.tabs( "disable" ); - tabs_disabled( element, true ); + disabled( element, true ); element.tabs( "destroy" ); element.tabs({ disabled: [ 0, 1 ] }); - tabs_disabled( element, [ 0, 1 ] ); + disabled( element, [ 0, 1 ] ); element.tabs( "disable" ); - tabs_disabled( element, true ); + disabled( element, true ); }); test( "disable( index )", function() { expect( 10 ); var element = $( "#tabs1" ).tabs({ disabled: false }); - tabs_disabled( element, false ); + disabled( element, false ); // fully enabled -> partially disabled element.tabs( "disable", 1 ); - tabs_disabled( element, [ 1 ] ); + disabled( element, [ 1 ] ); // partially disabled -> partially disabled element.tabs( "disable", 2 ); - tabs_disabled( element, [ 1, 2 ] ); + disabled( element, [ 1, 2 ] ); // already disabled tab, no change element.tabs( "disable", 2 ); - tabs_disabled( element, [ 1, 2 ] ); + disabled( element, [ 1, 2 ] ); // partially disabled -> fully disabled element.tabs( "disable", 0 ); - tabs_disabled( element, true ); + disabled( element, true ); }); test( "refresh", function() { expect( 27 ); var element = $( "#tabs1" ).tabs(); - tabs_state( element, 1, 0, 0 ); - tabs_disabled( element, false ); + state( element, 1, 0, 0 ); + disabled( element, false ); // disable tab via markup element.find( ".ui-tabs-nav li" ).eq( 1 ).addClass( "ui-state-disabled" ); element.tabs( "refresh" ); - tabs_state( element, 1, 0, 0 ); - tabs_disabled( element, [ 1 ] ); + state( element, 1, 0, 0 ); + disabled( element, [ 1 ] ); // add remote tab element.find( ".ui-tabs-nav" ).append( "
  • new
  • " ); element.tabs( "refresh" ); - tabs_state( element, 1, 0, 0, 0 ); - tabs_disabled( element, [ 1 ] ); + state( element, 1, 0, 0, 0 ); + disabled( element, [ 1 ] ); equal( element.find( "#" + $( "#newTab a" ).attr( "aria-controls" ) ).length, 1, "panel added for remote tab" ); // remove all tabs element.find( ".ui-tabs-nav li, .ui-tabs-panel" ).remove(); element.tabs( "refresh" ); - tabs_state( element ); + state( element ); equal( element.tabs( "option", "active" ), false, "no active tab" ); // add tabs @@ -115,34 +118,34 @@ test( "refresh", function() { .append( "
    new 4
    " ) .append( "
    new 5
    " ); element.tabs( "refresh" ); - tabs_state( element, 0, 0, 0, 0 ); - tabs_disabled( element, [ 0 ] ); + state( element, 0, 0, 0, 0 ); + disabled( element, [ 0 ] ); // activate third tab element.tabs( "option", "active", 2 ); - tabs_state( element, 0, 0, 1, 0 ); - tabs_disabled( element, [ 0 ] ); + state( element, 0, 0, 1, 0 ); + disabled( element, [ 0 ] ); // remove fourth tab, third tab should stay active element.find( ".ui-tabs-nav li" ).eq( 3 ).remove(); element.find( ".ui-tabs-panel" ).eq( 3 ).remove(); element.tabs( "refresh" ); - tabs_state( element, 0, 0, 1 ); - tabs_disabled( element, [ 0 ] ); + state( element, 0, 0, 1 ); + disabled( element, [ 0 ] ); // remove third (active) tab, second tab should become active element.find( ".ui-tabs-nav li" ).eq( 2 ).remove(); element.find( ".ui-tabs-panel" ).eq( 2 ).remove(); element.tabs( "refresh" ); - tabs_state( element, 0, 1 ); - tabs_disabled( element, [ 0 ] ); + state( element, 0, 1 ); + disabled( element, [ 0 ] ); // remove first tab, previously active tab (now first) should stay active element.find( ".ui-tabs-nav li" ).eq( 0 ).remove(); element.find( ".ui-tabs-panel" ).eq( 0 ).remove(); element.tabs( "refresh" ); - tabs_state( element, 1 ); - tabs_disabled( element, false ); + state( element, 1 ); + disabled( element, false ); }); asyncTest( "load", function() { @@ -162,7 +165,7 @@ asyncTest( "load", function() { strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" ); equal( ui.panel.size(), 1, "panel size" ); strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); - tabs_state( element, 1, 0, 0, 0, 0 ); + state( element, 1, 0, 0, 0, 0 ); }); element.one( "tabsload", function( event, ui ) { // TODO: remove wrapping in 2.0 @@ -178,11 +181,11 @@ asyncTest( "load", function() { equal( uiPanel.size(), 1, "panel size" ); strictEqual( uiPanel[ 0 ], panel[ 0 ], "panel" ); equal( uiPanel.find( "p" ).length, 1, "panel html" ); - tabs_state( element, 1, 0, 0, 0, 0 ); + state( element, 1, 0, 0, 0, 0 ); setTimeout( tabsload1, 100 ); }); element.tabs( "load", 3 ); - tabs_state( element, 1, 0, 0, 0, 0 ); + state( element, 1, 0, 0, 0, 0 ); function tabsload1() { // no need to test details of event (tested in events tests) @@ -194,7 +197,7 @@ asyncTest( "load", function() { setTimeout( tabsload2, 100 ); }); element.tabs( "option", "active", 3 ); - tabs_state( element, 0, 0, 0, 1, 0 ); + state( element, 0, 0, 0, 1, 0 ); } function tabsload2() { @@ -209,7 +212,7 @@ asyncTest( "load", function() { strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" ); equal( ui.panel.size(), 1, "panel size" ); strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); - tabs_state( element, 0, 0, 0, 1, 0 ); + state( element, 0, 0, 0, 1, 0 ); }); element.one( "tabsload", function( event, ui ) { // TODO: remove wrapping in 2.0 @@ -224,11 +227,11 @@ asyncTest( "load", function() { strictEqual( uiTab[ 0 ], tab[ 0 ], "tab" ); equal( uiPanel.size(), 1, "panel size" ); strictEqual( uiPanel[ 0 ], panel[ 0 ], "panel" ); - tabs_state( element, 0, 0, 0, 1, 0 ); + state( element, 0, 0, 0, 1, 0 ); start(); }); element.tabs( "load", 3 ); - tabs_state( element, 0, 0, 0, 1, 0 ); + state( element, 0, 0, 0, 1, 0 ); } }); diff --git a/tests/unit/tabs/tabs_options.js b/tests/unit/tabs/tabs_options.js index e1ebf5efa..40d4ceaa7 100644 --- a/tests/unit/tabs/tabs_options.js +++ b/tests/unit/tabs/tabs_options.js @@ -1,5 +1,8 @@ (function( $ ) { +var disabled = TestHelpers.tabs.disabled, + state = TestHelpers.tabs.state; + module( "tabs: options" ); test( "{ active: default }", function() { @@ -7,13 +10,13 @@ test( "{ active: default }", function() { var element = $( "#tabs1" ).tabs(); equal( element.tabs( "option", "active" ), 0, "should be 0 by default" ); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); element.tabs( "destroy" ); location.hash = "#fragment-3"; element = $( "#tabs1" ).tabs(); equal( element.tabs( "option", "active" ), 2, "should be 2 based on URL" ); - tabs_state( element, 0, 0, 1 ); + state( element, 0, 0, 1 ); element.tabs( "destroy" ); location.hash = "#"; }); @@ -25,19 +28,19 @@ test( "{ active: false }", function() { active: false, collapsible: true }); - tabs_state( element, 0, 0, 0 ); + state( element, 0, 0, 0 ); equal( element.find( ".ui-tabs-nav .ui-state-active" ).size(), 0, "no tabs selected" ); strictEqual( element.tabs( "option", "active" ), false ); element.tabs( "option", "collapsible", false ); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); equal( element.tabs( "option", "active" ), 0 ); element.tabs( "destroy" ); element.tabs({ active: false }); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); strictEqual( element.tabs( "option", "active" ), 0 ); }); @@ -48,19 +51,19 @@ test( "{ active: Number }", function() { active: 2 }); equal( element.tabs( "option", "active" ), 2 ); - tabs_state( element, 0, 0, 1 ); + state( element, 0, 0, 1 ); element.tabs( "option", "active", 0 ); equal( element.tabs( "option", "active" ), 0 ); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); element.find( ".ui-tabs-nav a" ).eq( 1 ).click(); equal( element.tabs( "option", "active" ), 1 ); - tabs_state( element, 0, 1, 0 ); + state( element, 0, 1, 0 ); element.tabs( "option", "active", 10 ); equal( element.tabs( "option", "active" ), 1 ); - tabs_state( element, 0, 1, 0 ); + state( element, 0, 1, 0 ); }); if ( $.uiBackCompat === false ) { @@ -69,19 +72,19 @@ if ( $.uiBackCompat === false ) { active: -1 }); equal( element.tabs( "option", "active" ), 2 ); - tabs_state( element, 0, 0, 1 ); + state( element, 0, 0, 1 ); element.tabs( "option", "active", -2 ); equal( element.tabs( "option", "active" ), 1 ); - tabs_state( element, 0, 1, 0 ); + state( element, 0, 1, 0 ); element.tabs( "option", "active", -10 ); equal( element.tabs( "option", "active" ), 1 ); - tabs_state( element, 0, 1, 0 ); + state( element, 0, 1, 0 ); element.tabs( "option", "active", -3 ); equal( element.tabs( "option", "active" ), 0 ); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); }); } @@ -91,9 +94,9 @@ test( "active - mismatched tab/panel order", function() { location.hash = "#tabs7-2"; var element = $( "#tabs7" ).tabs(); equal( element.tabs( "option", "active" ), 1, "should be 1 based on URL" ); - tabs_state( element, 0, 1 ); + state( element, 0, 1 ); element.tabs( "option", "active", 0 ); - tabs_state( element, 1, 0 ); + state( element, 1, 0 ); location.hash = "#"; }); @@ -105,11 +108,11 @@ test( "{ collapsible: false }", function() { }); element.tabs( "option", "active", false ); equal( element.tabs( "option", "active" ), 1 ); - tabs_state( element, 0, 1, 0 ); + state( element, 0, 1, 0 ); element.find( ".ui-state-active a" ).eq( 1 ).click(); equal( element.tabs( "option", "active" ), 1 ); - tabs_state( element, 0, 1, 0 ); + state( element, 0, 1, 0 ); }); test( "{ collapsible: true }", function() { @@ -122,15 +125,15 @@ test( "{ collapsible: true }", function() { element.tabs( "option", "active", false ); equal( element.tabs( "option", "active" ), false ); - tabs_state( element, 0, 0, 0 ); + state( element, 0, 0, 0 ); element.tabs( "option", "active", 1 ); equal( element.tabs( "option", "active" ), 1 ); - tabs_state( element, 0, 1, 0 ); + state( element, 0, 1, 0 ); element.find( ".ui-state-active a" ).click(); equal( element.tabs( "option", "active" ), false ); - tabs_state( element, 0, 0, 0 ); + state( element, 0, 0, 0 ); }); test( "disabled", function() { @@ -138,23 +141,23 @@ test( "disabled", function() { // fully enabled by default var element = $( "#tabs1" ).tabs(); - tabs_disabled( element, false ); + disabled( element, false ); // disable single tab element.tabs( "option", "disabled", [ 1 ] ); - tabs_disabled( element, [ 1 ] ); + disabled( element, [ 1 ] ); // disabled active tab element.tabs( "option", "disabled", [ 0, 1 ] ); - tabs_disabled( element, [ 0, 1 ] ); + disabled( element, [ 0, 1 ] ); // disable all tabs element.tabs( "option", "disabled", [ 0, 1, 2 ] ); - tabs_disabled( element, true ); + disabled( element, true ); // enable all tabs element.tabs( "option", "disabled", [] ); - tabs_disabled( element, false ); + disabled( element, false ); }); test( "{ event: null }", function() { @@ -163,16 +166,16 @@ test( "{ event: null }", function() { var element = $( "#tabs1" ).tabs({ event: null }); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); element.tabs( "option", "active", 1 ); equal( element.tabs( "option", "active" ), 1 ); - tabs_state( element, 0, 1, 0 ); + state( element, 0, 1, 0 ); // ensure default click handler isn't bound element.find( ".ui-tabs-nav a" ).eq( 2 ).click(); equal( element.tabs( "option", "active" ), 1 ); - tabs_state( element, 0, 1, 0 ); + state( element, 0, 1, 0 ); }); test( "{ event: custom }", function() { @@ -181,31 +184,31 @@ test( "{ event: custom }", function() { var element = $( "#tabs1" ).tabs({ event: "custom1 custom2" }); - tabs_state( element, 1, 0, 0 ); + state( element, 1, 0, 0 ); element.find( ".ui-tabs-nav a" ).eq( 1 ).trigger( "custom1" ); equal( element.tabs( "option", "active" ), 1 ); - tabs_state( element, 0, 1, 0 ); + state( element, 0, 1, 0 ); // ensure default click handler isn't bound element.find( ".ui-tabs-nav a" ).eq( 2 ).trigger( "click" ); equal( element.tabs( "option", "active" ), 1 ); - tabs_state( element, 0, 1, 0 ); + state( element, 0, 1, 0 ); element.find( ".ui-tabs-nav a" ).eq( 2 ).trigger( "custom2" ); equal( element.tabs( "option", "active" ), 2 ); - tabs_state( element, 0, 0, 1 ); + state( element, 0, 0, 1 ); element.tabs( "option", "event", "custom3" ); // ensure old event handlers are unbound element.find( ".ui-tabs-nav a" ).eq( 1 ).trigger( "custom1" ); equal( element.tabs( "option", "active" ), 2 ); - tabs_state( element, 0, 0, 1 ); + state( element, 0, 0, 1 ); element.find( ".ui-tabs-nav a" ).eq( 1 ).trigger( "custom3" ); equal( element.tabs( "option", "active" ), 1 ); - tabs_state( element, 0, 1, 0 ); + state( element, 0, 1, 0 ); }); // TODO: add animation tests diff --git a/tests/unit/tabs/tabs_test_helpers.js b/tests/unit/tabs/tabs_test_helpers.js new file mode 100644 index 000000000..9f592c074 --- /dev/null +++ b/tests/unit/tabs/tabs_test_helpers.js @@ -0,0 +1,61 @@ +TestHelpers.tabs = { + disabled: function( tabs, state ) { + var expected, actual, + internalState = tabs.tabs( "option", "disabled" ); + + if ( internalState === false ) { + internalState = []; + } + if ( internalState === true ) { + internalState = $.map( new Array( tabs.find( ".ui-tabs-nav li" ).length ), function( _, index ) { + return index; + }); + } + + expected = $.map( new Array( tabs.find ( ".ui-tabs-nav li" ).length ), function( _, index ) { + if ( typeof state === "boolean" ) { + return state ? 1 : 0; + } else { + return $.inArray( index, state ) !== -1 ? 1 : 0; + } + }); + + actual = tabs.find( ".ui-tabs-nav li" ).map(function( index ) { + var tab = $( this ), + tabIsDisabled = tab.hasClass( "ui-state-disabled" ); + + if ( tabIsDisabled && $.inArray( index, internalState ) !== -1 ) { + return 1; + } + if ( !tabIsDisabled && $.inArray( index, internalState ) === -1 ) { + return 0; + } + // mixed state - invalid + return -1; + }).get(); + + deepEqual( tabs.tabs( "option", "disabled" ), state ); + deepEqual( actual, expected ); + }, + + state: function( tabs ) { + var expected = $.makeArray( arguments ).slice( 1 ), + actual = tabs.find( ".ui-tabs-nav li" ).map(function() { + var tab = $( this ), + panel = $( $.ui.tabs.prototype._sanitizeSelector( + "#" + tab.find( "a" ).attr( "aria-controls" ) ) ), + tabIsActive = tab.hasClass( "ui-state-active" ), + panelIsActive = panel.css( "display" ) !== "none"; + + if ( tabIsActive && panelIsActive ) { + return 1; + } + if ( !tabIsActive && !panelIsActive ) { + return 0; + } + return -1; // mixed state - invalid + }).get(); + deepEqual( actual, expected ); + } +}; + From e9d5079b04bfc6bf4103630e936be3022d83353c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?= Date: Thu, 19 Apr 2012 13:03:21 -0400 Subject: [PATCH 28/34] Tests: Move commonWidgetTests() to TestHelpers. --- grunt.js | 1 - tests/unit/accordion/accordion_defaults.js | 2 +- .../accordion_defaults_deprecated.js | 2 +- .../autocomplete/autocomplete_defaults.js | 2 +- tests/unit/button/button_defaults.js | 2 +- tests/unit/datepicker/datepicker_defaults.js | 2 +- tests/unit/dialog/dialog_defaults.js | 2 +- tests/unit/draggable/draggable_defaults.js | 68 +++++++++---------- tests/unit/droppable/droppable_defaults.js | 2 +- tests/unit/menu/menu_defaults.js | 2 +- .../unit/progressbar/progressbar_defaults.js | 2 +- tests/unit/resizable/resizable_defaults.js | 52 +++++++------- tests/unit/selectable/selectable_defaults.js | 28 ++++---- tests/unit/slider/slider_defaults.js | 2 +- tests/unit/sortable/sortable_defaults.js | 64 ++++++++--------- tests/unit/spinner/spinner_defaults.js | 2 +- tests/unit/tabs/tabs_defaults.js | 2 +- tests/unit/tabs/tabs_defaults_deprecated.js | 2 +- tests/unit/testsuite.js | 2 +- tests/unit/tooltip/tooltip_defaults.js | 2 +- 20 files changed, 113 insertions(+), 130 deletions(-) diff --git a/grunt.js b/grunt.js index e0a085a38..82e7fe1e8 100644 --- a/grunt.js +++ b/grunt.js @@ -350,7 +350,6 @@ grunt.initConfig({ globals: { addMonths: true, asyncTest: true, - commonWidgetTests: true, container: true, deepEqual: true, d1: true, diff --git a/tests/unit/accordion/accordion_defaults.js b/tests/unit/accordion/accordion_defaults.js index 9ad85bbce..ef24cf25e 100644 --- a/tests/unit/accordion/accordion_defaults.js +++ b/tests/unit/accordion/accordion_defaults.js @@ -1,4 +1,4 @@ -commonWidgetTests( "accordion", { +TestHelpers.commonWidgetTests( "accordion", { defaults: { active: 0, animate: {}, diff --git a/tests/unit/accordion/accordion_defaults_deprecated.js b/tests/unit/accordion/accordion_defaults_deprecated.js index 99f5ac827..22d5e1289 100644 --- a/tests/unit/accordion/accordion_defaults_deprecated.js +++ b/tests/unit/accordion/accordion_defaults_deprecated.js @@ -1,4 +1,4 @@ -commonWidgetTests( "accordion", { +TestHelpers.commonWidgetTests( "accordion", { defaults: { active: 0, animate: null, diff --git a/tests/unit/autocomplete/autocomplete_defaults.js b/tests/unit/autocomplete/autocomplete_defaults.js index ac83eaea4..c090ce4df 100644 --- a/tests/unit/autocomplete/autocomplete_defaults.js +++ b/tests/unit/autocomplete/autocomplete_defaults.js @@ -1,4 +1,4 @@ -commonWidgetTests( "autocomplete", { +TestHelpers.commonWidgetTests( "autocomplete", { defaults: { appendTo: "body", autoFocus: false, diff --git a/tests/unit/button/button_defaults.js b/tests/unit/button/button_defaults.js index 96c7e5bfa..ef22d3011 100644 --- a/tests/unit/button/button_defaults.js +++ b/tests/unit/button/button_defaults.js @@ -1,4 +1,4 @@ -commonWidgetTests( "button", { +TestHelpers.commonWidgetTests( "button", { defaults: { disabled: null, icons: { diff --git a/tests/unit/datepicker/datepicker_defaults.js b/tests/unit/datepicker/datepicker_defaults.js index 4243cf187..28e150791 100644 --- a/tests/unit/datepicker/datepicker_defaults.js +++ b/tests/unit/datepicker/datepicker_defaults.js @@ -6,4 +6,4 @@ var datepicker_defaults = { disabled: false }; -//commonWidgetTests('datepicker', { defaults: datepicker_defaults }); +//TestHelpers.commonWidgetTests('datepicker', { defaults: datepicker_defaults }); diff --git a/tests/unit/dialog/dialog_defaults.js b/tests/unit/dialog/dialog_defaults.js index 9f2e4c6a8..623908da7 100644 --- a/tests/unit/dialog/dialog_defaults.js +++ b/tests/unit/dialog/dialog_defaults.js @@ -1,4 +1,4 @@ -commonWidgetTests( "dialog", { +TestHelpers.commonWidgetTests( "dialog", { defaults: { autoOpen: true, buttons: {}, diff --git a/tests/unit/draggable/draggable_defaults.js b/tests/unit/draggable/draggable_defaults.js index 4b0aaca19..b47b139cd 100644 --- a/tests/unit/draggable/draggable_defaults.js +++ b/tests/unit/draggable/draggable_defaults.js @@ -1,36 +1,32 @@ -/* - * draggable_defaults.js - */ - -var draggable_defaults = { - addClasses: true, - appendTo: "parent", - axis: false, - cancel: ":input,option", - connectToSortable: false, - containment: false, - cursor: "auto", - cursorAt: false, - delay: 0, - disabled: false, - distance: 1, - grid: false, - handle: false, - helper: "original", - iframeFix: false, - opacity: false, - refreshPositions: false, - revert: false, - revertDuration: 500, - scroll: true, - scrollSensitivity: 20, - scrollSpeed: 20, - scope: "default", - snap: false, - snapMode: "both", - snapTolerance: 20, - stack: false, - zIndex: false -}; - -commonWidgetTests('draggable', { defaults: draggable_defaults }); +TestHelpers.commonWidgetTests( "draggable", { + defaults: { + addClasses: true, + appendTo: "parent", + axis: false, + cancel: ":input,option", + connectToSortable: false, + containment: false, + cursor: "auto", + cursorAt: false, + delay: 0, + disabled: false, + distance: 1, + grid: false, + handle: false, + helper: "original", + iframeFix: false, + opacity: false, + refreshPositions: false, + revert: false, + revertDuration: 500, + scroll: true, + scrollSensitivity: 20, + scrollSpeed: 20, + scope: "default", + snap: false, + snapMode: "both", + snapTolerance: 20, + stack: false, + zIndex: false + } +}); diff --git a/tests/unit/droppable/droppable_defaults.js b/tests/unit/droppable/droppable_defaults.js index 5a1a4198c..985dba06d 100644 --- a/tests/unit/droppable/droppable_defaults.js +++ b/tests/unit/droppable/droppable_defaults.js @@ -1,4 +1,4 @@ -commonWidgetTests( "droppable", { +TestHelpers.commonWidgetTests( "droppable", { defaults: { accept: "*", activeClass: false, diff --git a/tests/unit/menu/menu_defaults.js b/tests/unit/menu/menu_defaults.js index 018ac8ccf..ddcdbebf2 100644 --- a/tests/unit/menu/menu_defaults.js +++ b/tests/unit/menu/menu_defaults.js @@ -1,4 +1,4 @@ -commonWidgetTests( "menu", { +TestHelpers.commonWidgetTests( "menu", { defaults: { disabled: false, menus: "ul", diff --git a/tests/unit/progressbar/progressbar_defaults.js b/tests/unit/progressbar/progressbar_defaults.js index 3856e31a0..2f97a78bb 100644 --- a/tests/unit/progressbar/progressbar_defaults.js +++ b/tests/unit/progressbar/progressbar_defaults.js @@ -1,4 +1,4 @@ -commonWidgetTests( "progressbar", { +TestHelpers.commonWidgetTests( "progressbar", { defaults: { disabled: false, value: 0, diff --git a/tests/unit/resizable/resizable_defaults.js b/tests/unit/resizable/resizable_defaults.js index f69e5217c..c46e10781 100644 --- a/tests/unit/resizable/resizable_defaults.js +++ b/tests/unit/resizable/resizable_defaults.js @@ -1,28 +1,24 @@ -/* - * resizable_defaults.js - */ - -var resizable_defaults = { - alsoResize: false, - animate: false, - animateDuration: 'slow', - animateEasing: 'swing', - aspectRatio: false, - autoHide: false, - cancel: ':input,option', - containment: false, - delay: 0, - disabled: false, - distance: 1, - ghost: false, - grid: false, - handles: 'e,s,se', - helper: false, - maxHeight: null, - maxWidth: null, - minHeight: 10, - minWidth: 10, - zIndex: 1000 -}; - -commonWidgetTests('resizable', { defaults: resizable_defaults }); +TestHelpers.commonWidgetTests('resizable', { + defaults: { + alsoResize: false, + animate: false, + animateDuration: 'slow', + animateEasing: 'swing', + aspectRatio: false, + autoHide: false, + cancel: ':input,option', + containment: false, + delay: 0, + disabled: false, + distance: 1, + ghost: false, + grid: false, + handles: 'e,s,se', + helper: false, + maxHeight: null, + maxWidth: null, + minHeight: 10, + minWidth: 10, + zIndex: 1000 + } +}); diff --git a/tests/unit/selectable/selectable_defaults.js b/tests/unit/selectable/selectable_defaults.js index dbf799a43..27714d0ae 100644 --- a/tests/unit/selectable/selectable_defaults.js +++ b/tests/unit/selectable/selectable_defaults.js @@ -1,16 +1,12 @@ -/* - * selectable_defaults.js - */ - -var selectable_defaults = { - appendTo: 'body', - autoRefresh: true, - cancel: ':input,option', - delay: 0, - disabled: false, - distance: 0, - filter: '*', - tolerance: 'touch' -}; - -commonWidgetTests('selectable', { defaults: selectable_defaults }); +TestHelpers.commonWidgetTests('selectable', { + defaults: { + appendTo: 'body', + autoRefresh: true, + cancel: ':input,option', + delay: 0, + disabled: false, + distance: 0, + filter: '*', + tolerance: 'touch' + } +}); diff --git a/tests/unit/slider/slider_defaults.js b/tests/unit/slider/slider_defaults.js index 8049fe969..8a0b347f3 100644 --- a/tests/unit/slider/slider_defaults.js +++ b/tests/unit/slider/slider_defaults.js @@ -1,4 +1,4 @@ -commonWidgetTests( "slider", { +TestHelpers.commonWidgetTests( "slider", { defaults: { animate: false, cancel: ':input,option', diff --git a/tests/unit/sortable/sortable_defaults.js b/tests/unit/sortable/sortable_defaults.js index 7681addad..b5fc05a5d 100644 --- a/tests/unit/sortable/sortable_defaults.js +++ b/tests/unit/sortable/sortable_defaults.js @@ -1,34 +1,30 @@ -/* - * sortable_defaults.js - */ - -var sortable_defaults = { - appendTo: "parent", - axis: false, - cancel: ":input,option", - connectWith: false, - containment: false, - cursor: 'auto', - cursorAt: false, - delay: 0, - disabled: false, - distance: 1, - dropOnEmpty: true, - forcePlaceholderSize: false, - forceHelperSize: false, - grid: false, - handle: false, - helper: "original", - items: "> *", - opacity: false, - placeholder: false, - revert: false, - scroll: true, - scrollSensitivity: 20, - scrollSpeed: 20, - scope: "default", - tolerance: "intersect", - zIndex: 1000 -}; - -commonWidgetTests('sortable', { defaults: sortable_defaults }); +TestHelpers.commonWidgetTests( "sortable", { + defaults: { + appendTo: "parent", + axis: false, + cancel: ":input,option", + connectWith: false, + containment: false, + cursor: "auto", + cursorAt: false, + delay: 0, + disabled: false, + distance: 1, + dropOnEmpty: true, + forcePlaceholderSize: false, + forceHelperSize: false, + grid: false, + handle: false, + helper: "original", + items: "> *", + opacity: false, + placeholder: false, + revert: false, + scroll: true, + scrollSensitivity: 20, + scrollSpeed: 20, + scope: "default", + tolerance: "intersect", + zIndex: 1000 + } +}); diff --git a/tests/unit/spinner/spinner_defaults.js b/tests/unit/spinner/spinner_defaults.js index 0a4e7c236..4f05b1e63 100644 --- a/tests/unit/spinner/spinner_defaults.js +++ b/tests/unit/spinner/spinner_defaults.js @@ -1,4 +1,4 @@ -commonWidgetTests( "spinner", { +TestHelpers.commonWidgetTests( "spinner", { defaults: { culture: null, disabled: false, diff --git a/tests/unit/tabs/tabs_defaults.js b/tests/unit/tabs/tabs_defaults.js index 52b6f8a71..7ffb05da4 100644 --- a/tests/unit/tabs/tabs_defaults.js +++ b/tests/unit/tabs/tabs_defaults.js @@ -1,4 +1,4 @@ -commonWidgetTests( "tabs", { +TestHelpers.commonWidgetTests( "tabs", { defaults: { active: null, collapsible: false, diff --git a/tests/unit/tabs/tabs_defaults_deprecated.js b/tests/unit/tabs/tabs_defaults_deprecated.js index 1a56297e9..fdcff21b3 100644 --- a/tests/unit/tabs/tabs_defaults_deprecated.js +++ b/tests/unit/tabs/tabs_defaults_deprecated.js @@ -1,4 +1,4 @@ -commonWidgetTests( "tabs", { +TestHelpers.commonWidgetTests( "tabs", { defaults: { active: null, ajaxOptions: null, diff --git a/tests/unit/testsuite.js b/tests/unit/testsuite.js index 648b302ee..a877e38af 100644 --- a/tests/unit/testsuite.js +++ b/tests/unit/testsuite.js @@ -56,7 +56,7 @@ function testBasicUsage( widget ) { }); } -window.commonWidgetTests = function( widget, settings ) { +TestHelpers.commonWidgetTests = function( widget, settings ) { module( widget + ": common widget" ); testWidgetDefaults( widget, settings.defaults ); diff --git a/tests/unit/tooltip/tooltip_defaults.js b/tests/unit/tooltip/tooltip_defaults.js index b8b41bf47..d12ee9519 100644 --- a/tests/unit/tooltip/tooltip_defaults.js +++ b/tests/unit/tooltip/tooltip_defaults.js @@ -1,4 +1,4 @@ -commonWidgetTests( "tooltip", { +TestHelpers.commonWidgetTests( "tooltip", { defaults: { content: function() {}, disabled: false, From d62d9d4eff764220be9696acc7ffe8bf0d24c570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?= Date: Thu, 19 Apr 2012 13:12:23 -0400 Subject: [PATCH 29/34] Spinner tests: Don't pollute the global namespace with helpers. --- grunt.js | 1 - tests/unit/spinner/spinner_core.js | 42 ++++++++--------- tests/unit/spinner/spinner_events.js | 52 +++++++++++----------- tests/unit/spinner/spinner_methods.js | 12 ++--- tests/unit/spinner/spinner_options.js | 2 + tests/unit/spinner/spinner_test_helpers.js | 11 +++-- 6 files changed, 65 insertions(+), 55 deletions(-) diff --git a/grunt.js b/grunt.js index 82e7fe1e8..d03acdca9 100644 --- a/grunt.js +++ b/grunt.js @@ -383,7 +383,6 @@ grunt.initConfig({ shouldnotmove: true, shouldnotresize: true, shouldresize: true, - spinner_simulateKeyDownUp: true, start: true, strictEqual: true, stop: true, diff --git a/tests/unit/spinner/spinner_core.js b/tests/unit/spinner/spinner_core.js index e38b467a3..a1179bb35 100644 --- a/tests/unit/spinner/spinner_core.js +++ b/tests/unit/spinner/spinner_core.js @@ -1,5 +1,7 @@ (function( $ ) { +var simulateKeyDownUp = TestHelpers.spinner.simulateKeyDownUp; + module( "spinner: core" ); test( "keydown UP on input, increases value not greater than max", function() { @@ -9,15 +11,15 @@ test( "keydown UP on input, increases value not greater than max", function() { step: 10 }); - spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + simulateKeyDownUp( element, $.ui.keyCode.UP ); equal( element.val(), 80 ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + simulateKeyDownUp( element, $.ui.keyCode.UP ); equal( element.val(), 90 ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + simulateKeyDownUp( element, $.ui.keyCode.UP ); equal( element.val(), 100 ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + simulateKeyDownUp( element, $.ui.keyCode.UP ); equal( element.val(), 100 ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + simulateKeyDownUp( element, $.ui.keyCode.UP ); equal( element.val(), 100 ); }); @@ -28,15 +30,15 @@ test( "keydown DOWN on input, decreases value not less than min", function() { step: 10 }); - spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.DOWN ); equal( element.val(), 40 ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.DOWN ); equal( element.val(), 30 ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.DOWN ); equal( element.val(), 20 ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.DOWN ); equal( element.val(), 20 ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.DOWN ); equal( element.val(), 20 ); }); @@ -47,15 +49,15 @@ test( "keydown PAGE_UP on input, increases value not greater than max", function page: 10 }); - spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); + simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); equal( element.val(), 80 ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); + simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); equal( element.val(), 90 ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); + simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); equal( element.val(), 100 ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); + simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); equal( element.val(), 100 ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); + simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); equal( element.val(), 100 ); }); @@ -66,15 +68,15 @@ test( "keydown PAGE_DOWN on input, decreases value not less than min", function( page: 10 }); - spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); equal( element.val(), 40 ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); equal( element.val(), 30 ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); equal( element.val(), 20 ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); equal( element.val(), 20 ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); equal( element.val(), 20 ); }); diff --git a/tests/unit/spinner/spinner_events.js b/tests/unit/spinner/spinner_events.js index e43ba3365..133a8d5a2 100644 --- a/tests/unit/spinner/spinner_events.js +++ b/tests/unit/spinner/spinner_events.js @@ -1,5 +1,7 @@ (function( $ ) { +var simulateKeyDownUp = TestHelpers.spinner.simulateKeyDownUp; + module( "spinner: events" ); test( "start", function() { @@ -13,14 +15,14 @@ test( "start", function() { } shouldStart( true, "key UP" ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + simulateKeyDownUp( element, $.ui.keyCode.UP ); shouldStart( true, "key DOWN" ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.DOWN ); shouldStart( true, "key PAGE_UP" ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); + simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); shouldStart( true, "key PAGE_DOWN" ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); shouldStart( true, "button up" ); element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup(); @@ -52,14 +54,14 @@ test( "spin", function() { } shouldSpin( true, "key UP" ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + simulateKeyDownUp( element, $.ui.keyCode.UP ); shouldSpin( true, "key DOWN" ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.DOWN ); shouldSpin( true, "key PAGE_UP" ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); + simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); shouldSpin( true, "key PAGE_DOWN" ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); shouldSpin( true, "button up" ); element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup(); @@ -91,14 +93,14 @@ test( "stop", function() { } shouldStop( true, "key UP" ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + simulateKeyDownUp( element, $.ui.keyCode.UP ); shouldStop( true, "key DOWN" ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.DOWN ); shouldStop( true, "key PAGE_UP" ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); + simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); shouldStop( true, "key PAGE_DOWN" ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); shouldStop( true, "button up" ); element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup(); @@ -131,42 +133,42 @@ test( "change", function() { element.focus(); shouldChange( false, "key UP, before blur" ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + simulateKeyDownUp( element, $.ui.keyCode.UP ); shouldChange( true, "blur after key UP" ); element.blur(); element.focus(); shouldChange( false, "key DOWN, before blur" ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.DOWN ); shouldChange( true, "blur after key DOWN" ); element.blur(); element.focus(); shouldChange( false, "key PAGE_UP, before blur" ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); + simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); shouldChange( true, "blur after key PAGE_UP" ); element.blur(); element.focus(); shouldChange( false, "key PAGE_DOWN, before blur" ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); shouldChange( true, "blur after key PAGE_DOWN" ); element.blur(); shouldChange( false, "many keys, before blur" ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.UP ); + simulateKeyDownUp( element, $.ui.keyCode.UP ); + simulateKeyDownUp( element, $.ui.keyCode.UP ); + simulateKeyDownUp( element, $.ui.keyCode.DOWN ); shouldChange( true, "blur after many keys" ); element.blur(); shouldChange( false, "many keys, same final value, before blur" ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.UP ); + simulateKeyDownUp( element, $.ui.keyCode.UP ); + simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.DOWN ); shouldChange( false, "blur after many keys, same final value" ); shouldChange( false, "button up, before blur" ); diff --git a/tests/unit/spinner/spinner_methods.js b/tests/unit/spinner/spinner_methods.js index 2cb3c849f..bafd949a7 100644 --- a/tests/unit/spinner/spinner_methods.js +++ b/tests/unit/spinner/spinner_methods.js @@ -1,5 +1,7 @@ (function( $ ) { +var simulateKeyDownUp = TestHelpers.spinner.simulateKeyDownUp; + module( "spinner: methods" ); test( "destroy", function() { @@ -21,16 +23,16 @@ test( "disable", function() { ok( wrapper.hasClass( "ui-spinner-disabled" ), "after: wrapper has ui-spinner-disabled class" ); ok( element.is( ":disabled"), "after: input has disabled attribute" ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + simulateKeyDownUp( element, $.ui.keyCode.UP ); equal( 2, element.val(), "keyboard - value does not change on key UP" ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.DOWN ); equal( 2, element.val(), "keyboard - value does not change on key DOWN" ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); + simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); equal( 2, element.val(), "keyboard - value does not change on key PGUP" ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); + simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); equal( 2, element.val(), "keyboard - value does not change on key PGDN" ); wrapper.find( ".ui-spinner-up" ).trigger( "mousedown" ).trigger( "mouseup" ); @@ -65,7 +67,7 @@ test( "enable", function() { ok( !wrapper.hasClass( ".ui-spinner-disabled" ), "after: wrapper does not have ui-spinner-disabled class" ); ok( !element.is( ":disabled" ), "after: input does not have disabled attribute" ); - spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + simulateKeyDownUp( element, $.ui.keyCode.UP ); equal( 2, element.val(), "keyboard - value changes on key UP" ); }); diff --git a/tests/unit/spinner/spinner_options.js b/tests/unit/spinner/spinner_options.js index 6f5090d3a..e21852630 100644 --- a/tests/unit/spinner/spinner_options.js +++ b/tests/unit/spinner/spinner_options.js @@ -1,5 +1,7 @@ (function( $ ) { +var simulateKeyDownUp = TestHelpers.spinner.simulateKeyDownUp; + module( "spinner: options" ); // culture is tested after numberFormat, since it depends on numberFormat diff --git a/tests/unit/spinner/spinner_test_helpers.js b/tests/unit/spinner/spinner_test_helpers.js index af555dbf2..2021e8f7a 100644 --- a/tests/unit/spinner/spinner_test_helpers.js +++ b/tests/unit/spinner/spinner_test_helpers.js @@ -1,5 +1,8 @@ -var spinner_simulateKeyDownUp = function( element, keyCode, shift ) { - element - .simulate( "keydown", { keyCode: keyCode, shiftKey: shift || false } ) - .simulate( "keyup", { keyCode: keyCode, shiftKey: shift || false } ); +TestHelpers.spinner = { + simulateKeyDownUp: function( element, keyCode, shift ) { + element + .simulate( "keydown", { keyCode: keyCode, shiftKey: shift || false } ) + .simulate( "keyup", { keyCode: keyCode, shiftKey: shift || false } ); + } }; + From 82735366fab531ffd54dd597f69899509ff27653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?= Date: Thu, 19 Apr 2012 20:34:53 -0400 Subject: [PATCH 30/34] Grunt: Added link to JSHint issue. --- grunt.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grunt.js b/grunt.js index d03acdca9..7827961da 100644 --- a/grunt.js +++ b/grunt.js @@ -343,7 +343,7 @@ grunt.initConfig({ options: extend({ browser: true, jquery: true, - // TODO: this is only for document.write() + // TODO: this is only for document.write() https://github.com/jshint/jshint/issues/519 evil: true }, defaults ), // TODO: don't create so many globals in tests From d783766f9053a2075c579296d819f0941796ac1c Mon Sep 17 00:00:00 2001 From: G Karunakar Date: Sun, 15 Apr 2012 01:28:40 +0530 Subject: [PATCH 31/34] Datepicker: Corrections in Hindi weekday names, text labels. Fixes #8265 - Datepicker: Incorrect translations for Hindi locale. --- ui/i18n/jquery.ui.datepicker-hi.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ui/i18n/jquery.ui.datepicker-hi.js b/ui/i18n/jquery.ui.datepicker-hi.js index d75e98ead..edc530679 100644 --- a/ui/i18n/jquery.ui.datepicker-hi.js +++ b/ui/i18n/jquery.ui.datepicker-hi.js @@ -2,19 +2,19 @@ /* Written by Michael Dawart. */ jQuery(function($){ $.datepicker.regional['hi'] = { - closeText: 'होकर', - prevText: 'अगला', - nextText: 'नेक्स्ट', + closeText: 'बंद', + prevText: 'पिछला', + nextText: 'अगला', currentText: 'आज', - monthNames: ['जनवरी ','फरवरी','मार्च','अप्रेल','मै','जून', - 'जूलाई','अगस्त ','सितम्बर','आक्टोबर','नवम्बर','दिसम्बर'], - monthNamesShort: ['जन', 'फर', 'मार्च', 'अप्रेल', 'मै', 'जून', - 'जूलाई', 'अग', 'सित', 'आक्ट', 'नव', 'िद'], - dayNames: ['रविवासर', 'सोमवासर', 'मंगलवासर', 'बुधवासर', 'गुरुवासर', 'शुक्रवासर', 'शनिवासर'], + monthNames: ['जनवरी ','फरवरी','मार्च','अप्रेल','मई','जून', + 'जूलाई','अगस्त ','सितम्बर','अक्टूबर','नवम्बर','दिसम्बर'], + monthNamesShort: ['जन', 'फर', 'मार्च', 'अप्रेल', 'मई', 'जून', + 'जूलाई', 'अग', 'सित', अक्ट', 'नव', 'दि'], + dayNames: ['रविवार', 'सोमवार', 'मंगलवार', 'बुधवार', 'गुरुवार', 'शुक्रवार', 'शनिवार'], dayNamesShort: ['रवि', 'सोम', 'मंगल', 'बुध', 'गुरु', 'शुक्र', 'शनि'], dayNamesMin: ['रवि', 'सोम', 'मंगल', 'बुध', 'गुरु', 'शुक्र', 'शनि'], weekHeader: 'हफ्ता', - dateFormat: 'mm/dd/yy', + dateFormat: 'dd/mm/yy', firstDay: 1, isRTL: false, showMonthAfterYear: false, From 6150abae49f77a3b2f67c39a3c60a06792b4de8f Mon Sep 17 00:00:00 2001 From: TJ VanToll Date: Mon, 9 Jan 2012 21:42:56 -0500 Subject: [PATCH 32/34] Resizable: Apply zIndex option to all handles. Partial Fix for #7960- Modal dialog does not disable resizables on the page. --- tests/unit/resizable/resizable_options.js | 9 +++++++++ themes/base/jquery.ui.resizable.css | 2 +- ui/jquery.ui.resizable.js | 5 ++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/unit/resizable/resizable_options.js b/tests/unit/resizable/resizable_options.js index 76cca560a..275639ca1 100644 --- a/tests/unit/resizable/resizable_options.js +++ b/tests/unit/resizable/resizable_options.js @@ -187,4 +187,13 @@ test("ui-resizable-nw { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 1 equal( target.height(), 100, "compare maxHeight" ); }); +test("zIndex, applied to all handles", function() { + expect(8); + + var target = $('
    ').resizable({ handles: 'all', zIndex: 100 }); + target.children( '.ui-resizable-handle' ).each( function( index, handle ) { + equals( $( handle ).css( 'zIndex' ), 100, 'compare zIndex' ); + }); +}); + })(jQuery); diff --git a/themes/base/jquery.ui.resizable.css b/themes/base/jquery.ui.resizable.css index 0bf680482..0bb688d5b 100644 --- a/themes/base/jquery.ui.resizable.css +++ b/themes/base/jquery.ui.resizable.css @@ -8,7 +8,7 @@ * http://docs.jquery.com/UI/Resizable#theming */ .ui-resizable { position: relative;} -.ui-resizable-handle { position: absolute;font-size: 0.1px;z-index: 99999; display: block; } +.ui-resizable-handle { position: absolute;font-size: 0.1px; display: block; } .ui-resizable-disabled .ui-resizable-handle, .ui-resizable-autohide .ui-resizable-handle { display: none; } .ui-resizable-n { cursor: n-resize; height: 7px; width: 100%; top: -5px; left: 0; } .ui-resizable-s { cursor: s-resize; height: 7px; width: 100%; bottom: -5px; left: 0; } diff --git a/ui/jquery.ui.resizable.js b/ui/jquery.ui.resizable.js index 9be33927e..c00602cc8 100644 --- a/ui/jquery.ui.resizable.js +++ b/ui/jquery.ui.resizable.js @@ -99,9 +99,8 @@ $.widget("ui.resizable", $.ui.mouse, { var handle = $.trim(n[i]), hname = 'ui-resizable-'+handle; var axis = $('
    '); - // increase zIndex of sw, se, ne, nw axis - //TODO : this modifies original option - if(/sw|se|ne|nw/.test(handle)) axis.css({ zIndex: ++o.zIndex }); + // Apply zIndex to all handles - see #7960 + axis.css({ zIndex: o.zIndex }); //TODO : What's going on here? if ('se' == handle) { From 00306d6bbdf6c12ae1499ec090ef62dfd1a59ec5 Mon Sep 17 00:00:00 2001 From: kborchers Date: Thu, 19 Apr 2012 23:49:33 -0500 Subject: [PATCH 33/34] Menu: Bind to mouseenter instead of mouseover to avoid use of stopImmediatePropagation --- ui/jquery.ui.menu.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ui/jquery.ui.menu.js b/ui/jquery.ui.menu.js index abc759f1a..bcefd5822 100644 --- a/ui/jquery.ui.menu.js +++ b/ui/jquery.ui.menu.js @@ -87,8 +87,7 @@ $.widget( "ui.menu", { } } }, - "mouseover .ui-menu-item": function( event ) { - event.stopImmediatePropagation(); + "mouseenter .ui-menu-item": function( event ) { var target = $( event.currentTarget ); // Remove ui-state-active class from siblings of the newly focused menu item // to avoid a jump caused by adjacent elements both having a class with a border From 33df9b788d3f60459c43acbfefdfeef8a07ce632 Mon Sep 17 00:00:00 2001 From: kborchers Date: Thu, 19 Apr 2012 23:50:52 -0500 Subject: [PATCH 34/34] Menu tests: Update tests to test mouseenter instead of mouseover --- tests/unit/menu/menu_events.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/unit/menu/menu_events.js b/tests/unit/menu/menu_events.js index a0051c70b..4cb083240 100644 --- a/tests/unit/menu/menu_events.js +++ b/tests/unit/menu/menu_events.js @@ -87,11 +87,12 @@ test( "handle blur on custom item menu: click", function() { asyncTest( "handle submenu auto collapse: mouseleave", function() { expect( 4 ); - var $menu = $( "#menu2" ).menu(); + var $menu = $( "#menu2" ).menu(), + event = $.Event( "mouseenter" ); function menumouseleave1() { equal( $menu.find( "ul[aria-expanded='true']" ).length, 1, "first submenu expanded" ); - $menu.find( "li:nth-child(7) li:first" ).trigger( "mouseover" ); + $menu.menu( "focus", event, $menu.find( "li:nth-child(7) li:first" ) ); setTimeout( menumouseleave2, 350 ); } function menumouseleave2() { @@ -109,17 +110,18 @@ asyncTest( "handle submenu auto collapse: mouseleave", function() { start(); } - $menu.find( "li:nth-child(7)" ).trigger( "mouseover" ); + $menu.find( "li:nth-child(7)" ).trigger( "mouseenter" ); setTimeout( menumouseleave1, 350 ); }); asyncTest( "handle submenu auto collapse: mouseleave", function() { expect( 4 ); - var $menu = $( "#menu5" ).menu( { menus: "div" } ); + var $menu = $( "#menu5" ).menu( { menus: "div" } ), + event = $.Event( "mouseenter" ); function menumouseleave1() { equal( $menu.find( "div[aria-expanded='true']" ).length, 1, "first submenu expanded" ); - $menu.find( ":nth-child(7)" ).find( "div" ).eq( 0 ).children().eq( 0 ).trigger( "mouseover" ); + $menu.menu( "focus", event, $menu.find( ":nth-child(7)" ).find( "div" ).eq( 0 ).children().eq( 0 ) ); setTimeout( menumouseleave2, 350 ); } function menumouseleave2() { @@ -137,7 +139,7 @@ asyncTest( "handle submenu auto collapse: mouseleave", function() { start(); } - $menu.find( ":nth-child(7)" ).trigger( "mouseover" ); + $menu.find( ":nth-child(7)" ).trigger( "mouseenter" ); setTimeout( menumouseleave1, 350 ); });