From 46327804350874d21c564bc72d7d3c541bef9378 Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Fri, 9 Nov 2012 17:17:32 +0100 Subject: Dialog: Fix yoda-if, remove unnecessary TODOs; add missing callbacks to commons test --- tests/unit/dialog/dialog_common.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/unit/dialog/dialog_common.js b/tests/unit/dialog/dialog_common.js index 2c0e86b46..fb29838b7 100644 --- a/tests/unit/dialog/dialog_common.js +++ b/tests/unit/dialog/dialog_common.js @@ -27,6 +27,16 @@ TestHelpers.commonWidgetTests( "dialog", { width: 300, // callbacks - create: null + beforeClose: null, + close: null, + create: null, + drag: null, + dragStart: null, + dragStop: null, + focus: null, + open: null, + resize: null, + resizeStart: null, + resizeStop: null } }); -- cgit v1.2.3 From 6edce867339c5808eda428fa2566aa40da4b0202 Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Fri, 9 Nov 2012 18:26:30 +0100 Subject: Dialog: Remove attroperty workaround for title attribute. Make the default null, as it should be. No back-compat, as the behaviour doesn't change. --- tests/unit/dialog/dialog_common.js | 2 +- tests/unit/dialog/dialog_options.js | 42 ++++++++++++++++++++++--------------- ui/jquery.ui.dialog.js | 9 ++------ 3 files changed, 28 insertions(+), 25 deletions(-) (limited to 'tests') diff --git a/tests/unit/dialog/dialog_common.js b/tests/unit/dialog/dialog_common.js index fb29838b7..47fff1013 100644 --- a/tests/unit/dialog/dialog_common.js +++ b/tests/unit/dialog/dialog_common.js @@ -23,7 +23,7 @@ TestHelpers.commonWidgetTests( "dialog", { }, resizable: true, show: null, - title: '', + title: null, width: 300, // callbacks diff --git a/tests/unit/dialog/dialog_options.js b/tests/unit/dialog/dialog_options.js index 331230318..899dc1df6 100644 --- a/tests/unit/dialog/dialog_options.js +++ b/tests/unit/dialog/dialog_options.js @@ -415,37 +415,45 @@ test("resizable", function() { el.remove(); }); -test("title", function() { - expect(9); +test( "title", function() { + expect( 11 ); function titleText() { - return el.dialog('widget').find(".ui-dialog-title").html(); + return el.dialog('widget').find( ".ui-dialog-title" ).html(); } - var el = $('
').dialog(); + var el = $( '
' ).dialog(); // some browsers return a non-breaking space and some return " " // so we generate a non-breaking space for comparison - equal(titleText(), $( " " ).html(), "[default]"); - equal(el.dialog("option", "title"), "", "option not changed"); + equal( titleText(), $( " " ).html(), "[default]" ); + equal( el.dialog( "option", "title" ), null, "option not changed" ); + el.remove(); + + el = $( '
' ).dialog(); + equal( titleText(), "foo", "title in element attribute" ); + equal( el.dialog( "option", "title"), "foo", "option updated from attribute" ); el.remove(); - el = $('
').dialog(); - equal(titleText(), "foo", "title in element attribute"); - equal(el.dialog("option", "title"), "foo", "option updated from attribute"); + el = $( '
' ).dialog({ title: 'foo' }); + equal( titleText(), "foo", "title in init options" ); + equal( el.dialog("option", "title"), "foo", "opiton set from options hash" ); el.remove(); - el = $('
').dialog({ title: 'foo' }); - equal(titleText(), "foo", "title in init options"); - equal(el.dialog("option", "title"), "foo", "opiton set from options hash"); + el = $( '
' ).dialog({ title: 'bar' }); + equal( titleText(), "bar", "title in init options should override title in element attribute" ); + equal( el.dialog("option", "title"), "bar", "opiton set from options hash" ); el.remove(); - el = $('
').dialog({ title: 'bar' }); - equal(titleText(), "bar", "title in init options should override title in element attribute"); - equal(el.dialog("option", "title"), "bar", "opiton set from options hash"); + el = $( '
' ).dialog().dialog( 'option', 'title', 'foo' ); + equal( titleText(), 'foo', 'title after init' ); el.remove(); - el = $('
').dialog().dialog('option', 'title', 'foo'); - equal(titleText(), 'foo', 'title after init'); + // make sure attroperties are properly ignored - #5742 - .attr() might return a DOMElement + el = $( '
' ).dialog(); + // some browsers return a non-breaking space and some return " " + // so we get the text to normalize to the actual non-breaking space + equal( titleText(), $( " " ).html(), "[default]" ); + equal( el.dialog( "option", "title" ), null, "option not changed" ); el.remove(); }); diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index ab32219c2..451203cae 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -67,7 +67,7 @@ $.widget("ui.dialog", { }, resizable: true, show: null, - title: "", + title: null, width: 300, // callbacks @@ -85,16 +85,11 @@ $.widget("ui.dialog", { _create: function() { this.originalTitle = this.element.attr( "title" ); - // #5742 - .attr() might return a DOMElement - // TODO WTF? - if ( typeof this.originalTitle !== "string" ) { - this.originalTitle = ""; - } + this.options.title = this.options.title || this.originalTitle; this.oldPosition = { parent: this.element.parent(), index: this.element.parent().children().index( this.element ) }; - this.options.title = this.options.title || this.originalTitle; var that = this, options = this.options, -- cgit v1.2.3 From 0848040d3ee041e443e2492c18a5a69c78ab9c12 Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Fri, 9 Nov 2012 18:44:29 +0100 Subject: Dialog: Focus tabbable only when dialog lost focus before. --- tests/unit/dialog/dialog_events.js | 45 ++++++++++++++++++++++++++++++++++++++ ui/jquery.ui.dialog.js | 23 ++++++++++++------- 2 files changed, 60 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/unit/dialog/dialog_events.js b/tests/unit/dialog/dialog_events.js index ee7a8bcb3..eeb17eb93 100644 --- a/tests/unit/dialog/dialog_events.js +++ b/tests/unit/dialog/dialog_events.js @@ -39,6 +39,51 @@ test("open", function() { el.remove(); }); + +test( "focus", function() { + expect( 5 ); + var el, other; + el = $("#dialog1").dialog({ + autoOpen: false + }); + other = $("#dialog2").dialog({ + autoOpen: false + }); + + el.one( "dialogopen", function() { + ok( true, "open, just once" ); + }); + el.one( "dialogfocus", function() { + ok( true, "focus on open" ); + }); + other.dialog( "open" ); + + el.one( "dialogfocus", function() { + ok( true, "when opening and already open and wasn't on top" ); + }); + other.dialog( "open" ); + el.dialog( "open" ); + + el.one( "dialogfocus", function() { + ok( true, "when calling moveToTop and wasn't on top" ); + }); + other.dialog( "moveToTop" ); + el.dialog( "moveToTop" ); + + el.bind( "dialogfocus", function() { + ok( true, "when mousedown anywhere on the dialog and it wasn't on top" ); + }); + other.dialog( "moveToTop" ); + el.trigger( "mousedown" ); + + // triggers just once when already on top + el.dialog( "open" ); + el.dialog( "moveToTop" ); + el.trigger( "mousedown" ); + + el.add( other ).remove(); +}); + test("dragStart", function() { expect(9); diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index 451203cae..b860a8b18 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -117,7 +117,9 @@ $.widget("ui.dialog", { } }) .mousedown(function( event ) { - that.moveToTop( event ); + if ( that._moveToTop( event ) ) { + that._focusTabbable(); + } }) .appendTo( this.document[ 0 ].body ); @@ -292,18 +294,23 @@ $.widget("ui.dialog", { return this._isOpen; }, - moveToTop: function( event, silent ) { - var moved = this.uiDialog.nextAll( ":visible" ).insertBefore( this.uiDialog ); - if ( !silent && moved.length ) { + moveToTop: function() { + this._moveToTop(); + }, + + _moveToTop: function( event, silent ) { + var moved = !!this.uiDialog.nextAll( ":visible" ).insertBefore( this.uiDialog ).length; + if ( !silent && moved ) { this._trigger( "focus", event ); } + return moved; }, open: function() { if ( this._isOpen ) { - this.moveToTop( null ); - // TODO run this only when dialog wasn't focused? - this._focusTabbable(); + if ( this._moveToTop() ) { + this._focusTabbable(); + } return; } @@ -316,7 +323,7 @@ $.widget("ui.dialog", { this._size(); this._position( options.position ); this.overlay = options.modal ? new $.ui.dialog.overlay( this ) : null; - this.moveToTop( null, true ); + this._moveToTop( null, true ); this._show( uiDialog, options.show ); this._focusTabbable(); -- cgit v1.2.3 From 83a9f219bf40ff834d660020bbfa7de550e48a0c Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Thu, 15 Nov 2012 22:29:24 +0100 Subject: Dialog: Use button widget for close button (was already listed as dependency) --- demos/dialog/animated.html | 1 + demos/dialog/default.html | 1 + demos/dialog/modal-confirmation.html | 1 + demos/dialog/modal-form.html | 7 ++++--- demos/dialog/modal-message.html | 1 + demos/dialog/modal.html | 1 + tests/unit/dialog/dialog.html | 1 + tests/unit/dialog/dialog_options.js | 8 ++++---- tests/visual/dialog/animated.html | 1 + tests/visual/dialog/complex-dialogs.html | 1 + tests/visual/dialog/form.html | 1 + tests/visual/dialog/performance.html | 1 + themes/base/jquery.ui.dialog.css | 12 ++---------- ui/jquery.ui.dialog.js | 26 ++++++++++++-------------- 14 files changed, 32 insertions(+), 31 deletions(-) (limited to 'tests') diff --git a/demos/dialog/animated.html b/demos/dialog/animated.html index 8e1daf131..061396548 100644 --- a/demos/dialog/animated.html +++ b/demos/dialog/animated.html @@ -11,6 +11,7 @@ + diff --git a/demos/dialog/default.html b/demos/dialog/default.html index 214f41d0d..777921e48 100644 --- a/demos/dialog/default.html +++ b/demos/dialog/default.html @@ -11,6 +11,7 @@ + + + @@ -86,10 +87,10 @@ if ( bValid ) { $( "#users tbody" ).append( "" + - "" + name.val() + "" + - "" + email.val() + "" + + "" + name.val() + "" + + "" + email.val() + "" + "" + password.val() + "" + - "" ); + "" ); $( this ).dialog( "close" ); } }, diff --git a/demos/dialog/modal-message.html b/demos/dialog/modal-message.html index 60b7c3e15..19fc0e829 100644 --- a/demos/dialog/modal-message.html +++ b/demos/dialog/modal-message.html @@ -12,6 +12,7 @@ + + + diff --git a/tests/visual/dialog/complex-dialogs.html b/tests/visual/dialog/complex-dialogs.html index 6399d8a4b..2b9a0d3a6 100644 --- a/tests/visual/dialog/complex-dialogs.html +++ b/tests/visual/dialog/complex-dialogs.html @@ -11,6 +11,7 @@ + diff --git a/tests/visual/dialog/form.html b/tests/visual/dialog/form.html index 867991911..ed70ec69b 100644 --- a/tests/visual/dialog/form.html +++ b/tests/visual/dialog/form.html @@ -11,6 +11,7 @@ + diff --git a/tests/visual/dialog/performance.html b/tests/visual/dialog/performance.html index 937b9464f..8f63d6a69 100644 --- a/tests/visual/dialog/performance.html +++ b/tests/visual/dialog/performance.html @@ -11,6 +11,7 @@ + @@ -91,13 +96,13 @@

WHAT: A modal dialog opening another modal dialog (including a datepicker), opening a non-modal dialog (including an autocomplete with tooltip applied). A regular link on the page, outside of the dialogs.

EXPECTED: As long as a modal dialog is open, focus stays within the dialogs. Both mouse and keyboard interactions are captured and restricted to the dialog. When the nested modal dialog is open, the first modal dialog can't be interacted with, until the nested dialog is closed. When the third dialog is open (not modal), switching between the two dialogs is possible, both can be interacted with.

-Outside link

This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.

+

@@ -110,5 +115,7 @@
+Outside link + -- cgit v1.2.3 From 299681e8f0896cd0448fa08003bb7b733adc489f Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Fri, 16 Nov 2012 19:46:01 +0100 Subject: Dialog: Cleanup in ticket tests: TODO to merge one test, fix whitespace --- tests/unit/dialog/dialog_tickets.js | 59 +++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 29 deletions(-) (limited to 'tests') diff --git a/tests/unit/dialog/dialog_tickets.js b/tests/unit/dialog/dialog_tickets.js index 3055c5fc1..655f1e445 100644 --- a/tests/unit/dialog/dialog_tickets.js +++ b/tests/unit/dialog/dialog_tickets.js @@ -71,24 +71,24 @@ test("#5184: isOpen in dialogclose event is true", function() { }); test("#5531: dialog width should be at least minWidth on creation", function () { - expect( 4 ); - var el = $('
').dialog({ - width: 200, - minWidth: 300 - }); - - equal(el.dialog('option', 'width'), 300, "width is minWidth"); - el.dialog('option', 'width', 200); - equal(el.dialog('option', 'width'), 300, "width unchanged when set to < minWidth"); - el.dialog('option', 'width', 320); - equal(el.dialog('option', 'width'), 320, "width changed if set to > minWidth"); - el.remove(); - - el = $('
').dialog({ - minWidth: 300 - }); - ok(el.dialog('option', 'width') >= 300, "width is at least 300"); - el.remove(); + expect( 4 ); + var el = $('
').dialog({ + width: 200, + minWidth: 300 + }); + + equal(el.dialog('option', 'width'), 300, "width is minWidth"); + el.dialog('option', 'width', 200); + equal(el.dialog('option', 'width'), 300, "width unchanged when set to < minWidth"); + el.dialog('option', 'width', 320); + equal(el.dialog('option', 'width'), 320, "width changed if set to > minWidth"); + el.remove(); + + el = $('
').dialog({ + minWidth: 300 + }); + ok(el.dialog('option', 'width') >= 300, "width is at least 300"); + el.remove(); }); @@ -108,20 +108,21 @@ test("#6137: dialog('open') causes form elements to reset on IE7", function() { }); test("#6645: Missing element not found check in overlay", function(){ - expect(2); - var d1 = $('
Dialog 1
').dialog({modal: true}), - d2 = $('
Dialog 2
').dialog({modal: true, close: function(){ d2.remove(); }}); - - equal($.ui.dialog.overlay.instances.length, 2, 'two overlays created'); - d2.dialog('close'); - equal($.ui.dialog.overlay.instances.length, 1, 'one overlay remains after closing the 2nd overlay'); - d1.add(d2).remove(); + expect(2); + var d1 = $('
Dialog 1
').dialog({modal: true}), + d2 = $('
Dialog 2
').dialog({modal: true, close: function(){ d2.remove(); }}); + + equal($.ui.dialog.overlay.instances.length, 2, 'two overlays created'); + d2.dialog('close'); + equal($.ui.dialog.overlay.instances.length, 1, 'one overlay remains after closing the 2nd overlay'); + d1.add(d2).remove(); }); +// TODO merge this with the main destroy test test("#4980: Destroy should place element back in original DOM position", function(){ - expect( 2 ); - var container = $('
'), - modal = container.find('#modal'); + expect( 2 ); + var container = $('
'), + modal = container.find('#modal'); modal.dialog(); ok(!$.contains(container[0], modal[0]), 'dialog should move modal element to outside container element'); modal.dialog('destroy'); -- cgit v1.2.3 From b27db7e3b9a857b8f0890e91ae9c8a2d33bf9919 Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Fri, 16 Nov 2012 20:24:57 +0100 Subject: Dialog: Extend autofocus, starting with [autofocus], then :tabbable content, then buttonpane, then close button, then dialog. Fixes #4731 - Dialog: Add option to set which element gains focus on open --- tests/unit/dialog/dialog_core.js | 42 ++++++++++++++++++++++++++++++++ tests/visual/dialog/complex-dialogs.html | 2 +- ui/jquery.ui.dialog.js | 22 +++++++++++------ 3 files changed, 58 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/unit/dialog/dialog_core.js b/tests/unit/dialog/dialog_core.js index b36f6204f..31b245a61 100644 --- a/tests/unit/dialog/dialog_core.js +++ b/tests/unit/dialog/dialog_core.js @@ -17,6 +17,8 @@ test("title id", function() { el.remove(); }); +// TODO test for aria-describedby +// add only when the attribute isn't anywhere yet test("ARIA", function() { expect(4); @@ -42,4 +44,44 @@ test("widget method", function() { deepEqual(dialog.parent()[0], dialog.dialog("widget")[0]); }); +test( "focus tabbable", function() { + expect( 5 ); + var el, + options = { + buttons: [{ + text: "Ok", + click: $.noop + }] + }; + + // 1. first element inside the dialog matching [autofocus] + el = $( "
" ).dialog( options ); + equal( document.activeElement, el.find( "input" )[ 1 ] ); + el.remove(); + + // 2. tabbable element inside the content element + el = $( "
" ).dialog( options ); + equal( document.activeElement, el.find( "input" )[ 0 ] ); + el.remove(); + + // 3. tabbable element inside the buttonpane + el = $( "
text
" ).dialog( options ); + equal( document.activeElement, el.dialog( "widget" ).find( ".ui-dialog-buttonpane button" )[ 0 ] ); + el.remove(); + + // 4. the close button + el = $( "
text
" ).dialog(); + equal( document.activeElement, el.dialog( "widget" ).find( ".ui-dialog-titlebar .ui-dialog-titlebar-close" )[ 0 ] ); + el.remove(); + + // 5. the dialog itself + el = $( "
text
" ).dialog({ + autoOpen: false + }); + el.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).hide(); + el.dialog( "open" ); + equal( document.activeElement, el.parent()[ 0 ] ); + el.remove(); +}); + })(jQuery); diff --git a/tests/visual/dialog/complex-dialogs.html b/tests/visual/dialog/complex-dialogs.html index 03bb160fb..5c2e1d8a1 100644 --- a/tests/visual/dialog/complex-dialogs.html +++ b/tests/visual/dialog/complex-dialogs.html @@ -107,7 +107,7 @@

Date:

-

+

diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index 003389823..c48d1a804 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -224,15 +224,24 @@ $.widget("ui.dialog", { return this; }, - // TODO check if dialog already has focus, merge with _keepFocus _focusTabbable: function() { - // set focus to the first tabbable element in the content area or the first button - // if there are no tabbable elements, set focus on the dialog itself - var hasFocus = this.element.find( ":tabbable" ); + // set focus to the first match: + // 1. first element inside the dialog matching [autofocus] + // 2. tabbable element inside the content element + // 3. tabbable element inside the buttonpane + // 4. the close button + // 5. the dialog itself + var hasFocus = this.element.find( "[autofocus]" ); if ( !hasFocus.length ) { - hasFocus = this.uiDialogButtonPane.find( ":tabbable" ); + hasFocus = this.element.find( ":tabbable" ); if ( !hasFocus.length ) { - hasFocus = this.uiDialog; + hasFocus = this.uiDialogButtonPane.find( ":tabbable" ); + if ( !hasFocus.length ) { + hasFocus = this.uiDialogTitlebarClose.filter( ":tabbable" ); + if ( !hasFocus.length ) { + hasFocus = this.uiDialog; + } + } } } hasFocus.eq( 0 ).focus(); @@ -316,7 +325,6 @@ $.widget("ui.dialog", { .prependTo( this.uiDialog ); this._on( this.uiDialogTitlebar, { mousedown: function() { - // TODO call _focusTabbable or _keepFocus // Dialog isn't getting focus when dragging (#8063) this.uiDialog.focus(); } -- cgit v1.2.3 From 0be97bf8c01394cd68134b104bcbf30b27859531 Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Sat, 17 Nov 2012 11:31:57 +0100 Subject: Dialog: Removed broken disabled option from dialog, defuse disable/enable methods. Disabling dialogs is not supported. --- tests/unit/dialog/dialog_methods.js | 32 ++++++-------------------------- ui/jquery.ui.dialog.js | 7 +++++++ 2 files changed, 13 insertions(+), 26 deletions(-) (limited to 'tests') diff --git a/tests/unit/dialog/dialog_methods.js b/tests/unit/dialog/dialog_methods.js index a4959bf85..e5275c7a4 100644 --- a/tests/unit/dialog/dialog_methods.js +++ b/tests/unit/dialog/dialog_methods.js @@ -47,32 +47,12 @@ test("destroy", function() { }); }); -test("enable", function() { - expect( 3 ); - - var el, - expected = $('
').dialog(), - actual = expected.dialog('enable'); - equal(actual, expected, 'enable is chainable'); - - el = $('
').dialog({ disabled: true }); - el.dialog('enable'); - equal(el.dialog('option', 'disabled'), false, 'enable method sets disabled option to false'); - ok(!el.dialog('widget').hasClass('ui-dialog-disabled'), 'enable method removes ui-dialog-disabled class from ui-dialog element'); -}); - -test("disable", function() { - expect( 3 ); - - var el, - expected = $('
').dialog(), - actual = expected.dialog('disable'); - equal(actual, expected, 'disable is chainable'); - - el = $('
').dialog({ disabled: false }); - el.dialog('disable'); - equal(el.dialog('option', 'disabled'), true, 'disable method sets disabled option to true'); - ok(el.dialog('widget').hasClass('ui-dialog-disabled'), 'disable method adds ui-dialog-disabled class to ui-dialog element'); +test( "enable/disable disabled", function() { + expect( 2 ); + var el = $( "
" ).dialog(); + el.dialog( "disable" ); + equal(el.dialog( "option", "disabled" ), false, "disable method doesn't do anything" ); + ok( !el.dialog( "widget" ).hasClass( "ui-dialog-disabled" ), "disable method doesn't add ui-dialog-disabled class" ); }); test("close", function() { diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index c48d1a804..8e5ca66c1 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -152,6 +152,9 @@ $.widget("ui.dialog", { return this.uiDialog; }, + disable: $.noop, + enable: $.noop, + close: function( event ) { var that = this; @@ -578,6 +581,10 @@ $.widget("ui.dialog", { .addClass( value ); } + if ( key === "disabled" ) { + return; + } + this._super( key, value ); if ( key === "buttons" ) { -- cgit v1.2.3 From a0310eb091f679c8ba002d57a30b53f8e7ea8ef3 Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Sat, 17 Nov 2012 12:10:26 +0100 Subject: Dialog: Move array notation support for position option to backCompat check. Fixes #8824 - Deprecate array notation for position option. --- build/tasks/testswarm.js | 1 + tests/unit/all.html | 1 + tests/unit/dialog/dialog.html | 3 ++ tests/unit/dialog/dialog_deprecated.html | 62 +++++++++++++++++++++++++ tests/unit/dialog/dialog_deprecated.js | 23 +++++++++ tests/unit/dialog/dialog_options.js | 20 -------- ui/jquery.ui.dialog.js | 80 +++++++++++++++++++++++--------- 7 files changed, 147 insertions(+), 43 deletions(-) create mode 100644 tests/unit/dialog/dialog_deprecated.html create mode 100644 tests/unit/dialog/dialog_deprecated.js (limited to 'tests') diff --git a/build/tasks/testswarm.js b/build/tasks/testswarm.js index 0685315e6..96415aa74 100644 --- a/build/tasks/testswarm.js +++ b/build/tasks/testswarm.js @@ -15,6 +15,7 @@ var versions = { "Core": "core/core.html", "Datepicker": "datepicker/datepicker.html", "Dialog": "dialog/dialog.html", + "Dialog_deprecated": "dialog/dialog_deprecated.html", "Draggable": "draggable/draggable.html", "Droppable": "droppable/droppable.html", "Effects": "effects/effects.html", diff --git a/tests/unit/all.html b/tests/unit/all.html index 7581a737b..25116846f 100644 --- a/tests/unit/all.html +++ b/tests/unit/all.html @@ -22,6 +22,7 @@ "core/core.html", "datepicker/datepicker.html", "dialog/dialog.html", + "dialog/dialog_deprecated.html", "draggable/draggable.html", "droppable/droppable.html", "effects/effects.html", diff --git a/tests/unit/dialog/dialog.html b/tests/unit/dialog/dialog.html index 0b5ca4856..5413e7cc1 100644 --- a/tests/unit/dialog/dialog.html +++ b/tests/unit/dialog/dialog.html @@ -5,6 +5,9 @@ jQuery UI Dialog Test Suite + diff --git a/tests/unit/dialog/dialog_deprecated.html b/tests/unit/dialog/dialog_deprecated.html new file mode 100644 index 000000000..2a876ac73 --- /dev/null +++ b/tests/unit/dialog/dialog_deprecated.html @@ -0,0 +1,62 @@ + + + + + jQuery UI Dialog Test Suite + + + + + + + + + + + + + + + + + + + + + +

jQuery UI Dialog Test Suite

+

+
+

+
    +
    +
    +
    +
    +
    + Please share some personal information + + +
    +
    +

    Some more (optional) information

    + +
    +
    +
    + + diff --git a/tests/unit/dialog/dialog_deprecated.js b/tests/unit/dialog/dialog_deprecated.js new file mode 100644 index 000000000..06052b6bf --- /dev/null +++ b/tests/unit/dialog/dialog_deprecated.js @@ -0,0 +1,23 @@ +module("dialog (deprecated): position opton with array"); + +if ( !$.ui.ie ) { + test("position, right bottom on window w/array", function() { + expect( 2 ); + var el = $('
    ').dialog({ position: ["right", "bottom"] }), + dialog = el.dialog('widget'), + offset = dialog.offset(); + closeEnough(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft(), 1); + closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1); + el.remove(); + }); +} + +test("position, offset from top left w/array", function() { + expect( 2 ); + var el = $('
    ').dialog({ position: [10, 10] }), + dialog = el.dialog('widget'), + offset = dialog.offset(); + closeEnough(offset.left, 10 + $(window).scrollLeft(), 1); + closeEnough(offset.top, 10 + $(window).scrollTop(), 1); + el.remove(); +}); diff --git a/tests/unit/dialog/dialog_options.js b/tests/unit/dialog/dialog_options.js index beb60a642..4e11ecf62 100644 --- a/tests/unit/dialog/dialog_options.js +++ b/tests/unit/dialog/dialog_options.js @@ -331,16 +331,6 @@ if ( !$.ui.ie ) { el.remove(); }); - test("position, right bottom on window w/array", function() { - expect( 2 ); - var el = $('
    ').dialog({ position: ["right", "bottom"] }), - dialog = el.dialog('widget'), - offset = dialog.offset(); - closeEnough(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft(), 1); - closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1); - el.remove(); - }); - test("position, right bottom at right bottom via ui.position args", function() { expect( 2 ); var el = $('
    ').dialog({ @@ -359,16 +349,6 @@ if ( !$.ui.ie ) { } -test("position, offset from top left w/array", function() { - expect( 2 ); - var el = $('
    ').dialog({ position: [10, 10] }), - dialog = el.dialog('widget'), - offset = dialog.offset(); - closeEnough(offset.left, 10 + $(window).scrollLeft(), 1); - closeEnough(offset.top, 10 + $(window).scrollTop(), 1); - el.remove(); -}); - test("position, at another element", function() { expect( 4 ); var parent = $('
    ').css({ diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index 8e5ca66c1..781fa8fa6 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -211,7 +211,7 @@ $.widget("ui.dialog", { this.opener = $( this.document[ 0 ].activeElement ); this._size(); - this._position( this.options.position ); + this._position(); if ( this.options.modal ) { this.overlay = new $.ui.dialog.overlay( this ); } @@ -500,38 +500,24 @@ $.widget("ui.dialog", { } }, - _position: function( position ) { - var myAt = [], - offset = [ 0, 0 ], + _position: function() { + var position = this.options.position, + myAt = [], isVisible; if ( position ) { - // TODO we don't support 1.3.2 anymore, clean this mess up - // deep extending converts arrays to objects in jQuery <= 1.3.2 :-( - // if (typeof position == 'string' || $.isArray(position)) { - // myAt = $.isArray(position) ? position : position.split(' '); - - if ( typeof position === "string" || (typeof position === "object" && "0" in position ) ) { - myAt = position.split ? position.split( " " ) : [ position[ 0 ], position[ 1 ] ]; + if ( typeof position === "string" ) { + myAt = position.split( " " ); if ( myAt.length === 1 ) { myAt[ 1 ] = myAt[ 0 ]; } - - $.each( [ "left", "top" ], function( i, offsetPosition ) { - if ( +myAt[ i ] === myAt[ i ] ) { - offset[ i ] = myAt[ i ]; - myAt[ i ] = offsetPosition; - } - }); - position = { - my: myAt[0] + (offset[0] < 0 ? offset[0] : "+" + offset[0]) + " " + - myAt[1] + (offset[1] < 0 ? offset[1] : "+" + offset[1]), + my: myAt[0] + " " + myAt[1], at: myAt.join( " " ) }; + position = $.extend( {}, $.ui.dialog.prototype.options.position, position ); } - position = $.extend( {}, $.ui.dialog.prototype.options.position, position ); } else { position = $.ui.dialog.prototype.options.position; } @@ -610,7 +596,7 @@ $.widget("ui.dialog", { } if ( key === "position" ) { - this._position( value ); + this._position(); } if ( key === "resizable" ) { @@ -744,4 +730,52 @@ $.extend( $.ui.dialog.overlay.prototype, { } }); +// DEPRECATED +if ( $.uiBackCompat !== false ) { + // position option with array notation + // just override with old implementation + $.ui.dialog.prototype._position = function() { + var position = this.options.position, + myAt = [], + offset = [ 0, 0 ], + isVisible; + + if ( position ) { + if ( typeof position === "string" || (typeof position === "object" && "0" in position ) ) { + myAt = position.split ? position.split( " " ) : [ position[ 0 ], position[ 1 ] ]; + if ( myAt.length === 1 ) { + myAt[ 1 ] = myAt[ 0 ]; + } + + $.each( [ "left", "top" ], function( i, offsetPosition ) { + if ( +myAt[ i ] === myAt[ i ] ) { + offset[ i ] = myAt[ i ]; + myAt[ i ] = offsetPosition; + } + }); + + position = { + my: myAt[0] + (offset[0] < 0 ? offset[0] : "+" + offset[0]) + " " + + myAt[1] + (offset[1] < 0 ? offset[1] : "+" + offset[1]), + at: myAt.join( " " ) + }; + } + + position = $.extend( {}, $.ui.dialog.prototype.options.position, position ); + } else { + position = $.ui.dialog.prototype.options.position; + } + + // need to show the dialog to get the actual offset in the position plugin + isVisible = this.uiDialog.is( ":visible" ); + if ( !isVisible ) { + this.uiDialog.show(); + } + this.uiDialog.position( position ); + if ( !isVisible ) { + this.uiDialog.hide(); + } + }; +} + }( jQuery ) ); -- cgit v1.2.3 From 5aac8f563f3ff7227fe9790c2ac8620223e3bd45 Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Sat, 17 Nov 2012 13:23:57 +0100 Subject: Dialog: Add missing unit test for aria-describedby attribute --- tests/unit/dialog/dialog_core.js | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'tests') diff --git a/tests/unit/dialog/dialog_core.js b/tests/unit/dialog/dialog_core.js index 31b245a61..b5566255c 100644 --- a/tests/unit/dialog/dialog_core.js +++ b/tests/unit/dialog/dialog_core.js @@ -17,24 +17,18 @@ test("title id", function() { el.remove(); }); -// TODO test for aria-describedby -// add only when the attribute isn't anywhere yet -test("ARIA", function() { - expect(4); - - var labelledBy, - el = $('
    ').dialog(); - - equal(el.dialog('widget').attr('role'), 'dialog', 'dialog role'); - - labelledBy = el.dialog('widget').attr('aria-labelledby'); - ok(labelledBy.length > 0, 'has aria-labelledby attribute'); - equal(el.dialog('widget').find('.ui-dialog-title').attr('id'), labelledBy, - 'proper aria-labelledby attribute'); - - equal(el.dialog('widget').find('.ui-dialog-titlebar-close').attr('role'), 'button', - 'close link role'); +test( "ARIA", function() { + expect( 4 ); + + var el = $( "
    " ).dialog(), + wrapper = el.dialog( "widget" ); + equal( wrapper.attr( "role" ), "dialog", "dialog role" ); + equal( wrapper.attr( "aria-labelledby" ), wrapper.find( ".ui-dialog-title" ).attr( "id" ) ); + equal( wrapper.attr( "aria-describedby" ), el.attr( "id" ), "aria-describedby added" ); + el.remove(); + el = $( '

    descriotion

    ' ).dialog(); + strictEqual( el.dialog( "widget" ).attr( "aria-describedby" ), undefined, "no aria-describedby added, as already present in markup" ); el.remove(); }); -- cgit v1.2.3 From f3525afe0ec8d6599e2c54571b005b4c3d754352 Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Sat, 17 Nov 2012 18:04:10 +0100 Subject: Dialog: Update focus-tabbable test with a timer workaround to get IE8 to pass. --- tests/unit/dialog/dialog_core.js | 52 +++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 25 deletions(-) (limited to 'tests') diff --git a/tests/unit/dialog/dialog_core.js b/tests/unit/dialog/dialog_core.js index b5566255c..404e81770 100644 --- a/tests/unit/dialog/dialog_core.js +++ b/tests/unit/dialog/dialog_core.js @@ -48,34 +48,36 @@ test( "focus tabbable", function() { }] }; - // 1. first element inside the dialog matching [autofocus] el = $( "
    " ).dialog( options ); - equal( document.activeElement, el.find( "input" )[ 1 ] ); + equal( document.activeElement, el.find( "input" )[ 1 ], "1. first element inside the dialog matching [autofocus]" ); el.remove(); - // 2. tabbable element inside the content element - el = $( "
    " ).dialog( options ); - equal( document.activeElement, el.find( "input" )[ 0 ] ); - el.remove(); - - // 3. tabbable element inside the buttonpane - el = $( "
    text
    " ).dialog( options ); - equal( document.activeElement, el.dialog( "widget" ).find( ".ui-dialog-buttonpane button" )[ 0 ] ); - el.remove(); - - // 4. the close button - el = $( "
    text
    " ).dialog(); - equal( document.activeElement, el.dialog( "widget" ).find( ".ui-dialog-titlebar .ui-dialog-titlebar-close" )[ 0 ] ); - el.remove(); - - // 5. the dialog itself - el = $( "
    text
    " ).dialog({ - autoOpen: false - }); - el.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).hide(); - el.dialog( "open" ); - equal( document.activeElement, el.parent()[ 0 ] ); - el.remove(); + // IE8 fails to focus the input, ends up being the activeElement + // so wait for that stupid browser + stop(); + setTimeout(function() { + el = $( "
    " ).dialog( options ); + equal( document.activeElement, el.find( "input" )[ 0 ], "2. tabbable element inside the content element" ); + el.remove(); + + el = $( "
    text
    " ).dialog( options ); + equal( document.activeElement, el.dialog( "widget" ).find( ".ui-dialog-buttonpane button" )[ 0 ], "3. tabbable element inside the buttonpane" ); + el.remove(); + + el = $( "
    text
    " ).dialog(); + equal( document.activeElement, el.dialog( "widget" ).find( ".ui-dialog-titlebar .ui-dialog-titlebar-close" )[ 0 ], "4. the close button" ); + el.remove(); + + el = $( "
    text
    " ).dialog({ + autoOpen: false + }); + el.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).hide(); + el.dialog( "open" ); + equal( document.activeElement, el.parent()[ 0 ], "5. the dialog itself" ); + el.remove(); + + start(); + }, 13); }); })(jQuery); -- cgit v1.2.3 From a09f5c07f591d0ef198f1a36fab9d4b6061ecbc6 Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Wed, 21 Nov 2012 16:33:46 +0100 Subject: Dialog: Follow-up to 9fe3a62d8 - also deprecate string notation for position option. --- tests/unit/dialog/dialog_deprecated.js | 32 ++++++++++- tests/unit/dialog/dialog_options.js | 32 ----------- ui/jquery.ui.dialog.js | 101 +++++++++++++-------------------- 3 files changed, 72 insertions(+), 93 deletions(-) (limited to 'tests') diff --git a/tests/unit/dialog/dialog_deprecated.js b/tests/unit/dialog/dialog_deprecated.js index 06052b6bf..fcbd22faa 100644 --- a/tests/unit/dialog/dialog_deprecated.js +++ b/tests/unit/dialog/dialog_deprecated.js @@ -1,4 +1,4 @@ -module("dialog (deprecated): position opton with array"); +module("dialog (deprecated): position option with string and array"); if ( !$.ui.ie ) { test("position, right bottom on window w/array", function() { @@ -10,6 +10,16 @@ if ( !$.ui.ie ) { closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1); el.remove(); }); + + test("position, right bottom on window", function() { + expect( 2 ); + var el = $('
    ').dialog({ position: "right bottom" }), + dialog = el.dialog('widget'), + offset = dialog.offset(); + closeEnough(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft(), 1); + closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1); + el.remove(); + }); } test("position, offset from top left w/array", function() { @@ -21,3 +31,23 @@ test("position, offset from top left w/array", function() { closeEnough(offset.top, 10 + $(window).scrollTop(), 1); el.remove(); }); + +test("position, top on window", function() { + expect( 2 ); + var el = $('
    ').dialog({ position: "top" }), + dialog = el.dialog('widget'), + offset = dialog.offset(); + closeEnough(offset.left, Math.round($(window).width() / 2 - dialog.outerWidth() / 2) + $(window).scrollLeft(), 1); + closeEnough(offset.top, $(window).scrollTop(), 1); + el.remove(); +}); + +test("position, left on window", function() { + expect( 2 ); + var el = $('
    ').dialog({ position: "left" }), + dialog = el.dialog('widget'), + offset = dialog.offset(); + closeEnough(offset.left, 0, 1); + closeEnough(offset.top, Math.round($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop(), 1); + el.remove(); +}); diff --git a/tests/unit/dialog/dialog_options.js b/tests/unit/dialog/dialog_options.js index 4e11ecf62..f01a1a2a8 100644 --- a/tests/unit/dialog/dialog_options.js +++ b/tests/unit/dialog/dialog_options.js @@ -298,39 +298,8 @@ test("position, default center on window", function() { el.remove(); }); -test("position, top on window", function() { - expect( 2 ); - var el = $('
    ').dialog({ position: "top" }), - dialog = el.dialog('widget'), - offset = dialog.offset(); - closeEnough(offset.left, Math.round($(window).width() / 2 - dialog.outerWidth() / 2) + $(window).scrollLeft(), 1); - closeEnough(offset.top, $(window).scrollTop(), 1); - el.remove(); -}); - -test("position, left on window", function() { - expect( 2 ); - var el = $('
    ').dialog({ position: "left" }), - dialog = el.dialog('widget'), - offset = dialog.offset(); - closeEnough(offset.left, 0, 1); - closeEnough(offset.top, Math.round($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop(), 1); - el.remove(); -}); - // todo: figure out these fails in IE7 if ( !$.ui.ie ) { - - test("position, right bottom on window", function() { - expect( 2 ); - var el = $('
    ').dialog({ position: "right bottom" }), - dialog = el.dialog('widget'), - offset = dialog.offset(); - closeEnough(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft(), 1); - closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1); - el.remove(); - }); - test("position, right bottom at right bottom via ui.position args", function() { expect( 2 ); var el = $('
    ').dialog({ @@ -346,7 +315,6 @@ if ( !$.ui.ie ) { closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1); el.remove(); }); - } test("position, at another element", function() { diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index b998c2558..b9f73e954 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -495,33 +495,12 @@ $.widget("ui.dialog", { }, _position: function() { - var position = this.options.position, - myAt = [], - isVisible; - - if ( position ) { - if ( typeof position === "string" ) { - myAt = position.split( " " ); - if ( myAt.length === 1 ) { - myAt[ 1 ] = myAt[ 0 ]; - } - position = { - my: myAt[0] + " " + myAt[1], - at: myAt.join( " " ) - }; - position = $.extend( {}, $.ui.dialog.prototype.options.position, position ); - } - - } else { - position = $.ui.dialog.prototype.options.position; - } - // need to show the dialog to get the actual offset in the position plugin - isVisible = this.uiDialog.is( ":visible" ); + var isVisible = this.uiDialog.is( ":visible" ); if ( !isVisible ) { this.uiDialog.show(); } - this.uiDialog.position( position ); + this.uiDialog.position( this.options.position ); if ( !isVisible ) { this.uiDialog.hide(); } @@ -719,48 +698,50 @@ $.ui.dialog.overlay = { if ( $.uiBackCompat !== false ) { // position option with array notation // just override with old implementation - $.ui.dialog.prototype._position = function() { - var position = this.options.position, - myAt = [], - offset = [ 0, 0 ], - isVisible; - - if ( position ) { - if ( typeof position === "string" || (typeof position === "object" && "0" in position ) ) { - myAt = position.split ? position.split( " " ) : [ position[ 0 ], position[ 1 ] ]; - if ( myAt.length === 1 ) { - myAt[ 1 ] = myAt[ 0 ]; - } - - $.each( [ "left", "top" ], function( i, offsetPosition ) { - if ( +myAt[ i ] === myAt[ i ] ) { - offset[ i ] = myAt[ i ]; - myAt[ i ] = offsetPosition; + $.widget( "ui.dialog", $.ui.dialog, { + _position: function() { + var position = this.options.position, + myAt = [], + offset = [ 0, 0 ], + isVisible; + + if ( position ) { + if ( typeof position === "string" || (typeof position === "object" && "0" in position ) ) { + myAt = position.split ? position.split( " " ) : [ position[ 0 ], position[ 1 ] ]; + if ( myAt.length === 1 ) { + myAt[ 1 ] = myAt[ 0 ]; } - }); - position = { - my: myAt[0] + (offset[0] < 0 ? offset[0] : "+" + offset[0]) + " " + - myAt[1] + (offset[1] < 0 ? offset[1] : "+" + offset[1]), - at: myAt.join( " " ) - }; - } + $.each( [ "left", "top" ], function( i, offsetPosition ) { + if ( +myAt[ i ] === myAt[ i ] ) { + offset[ i ] = myAt[ i ]; + myAt[ i ] = offsetPosition; + } + }); - position = $.extend( {}, $.ui.dialog.prototype.options.position, position ); - } else { - position = $.ui.dialog.prototype.options.position; - } + position = { + my: myAt[0] + (offset[0] < 0 ? offset[0] : "+" + offset[0]) + " " + + myAt[1] + (offset[1] < 0 ? offset[1] : "+" + offset[1]), + at: myAt.join( " " ) + }; + } - // need to show the dialog to get the actual offset in the position plugin - isVisible = this.uiDialog.is( ":visible" ); - if ( !isVisible ) { - this.uiDialog.show(); - } - this.uiDialog.position( position ); - if ( !isVisible ) { - this.uiDialog.hide(); + position = $.extend( {}, $.ui.dialog.prototype.options.position, position ); + } else { + position = $.ui.dialog.prototype.options.position; + } + + // need to show the dialog to get the actual offset in the position plugin + isVisible = this.uiDialog.is( ":visible" ); + if ( !isVisible ) { + this.uiDialog.show(); + } + this.uiDialog.position( position ); + if ( !isVisible ) { + this.uiDialog.hide(); + } } - }; + }); } }( jQuery ) ); -- cgit v1.2.3 From d179cbaf3233ace0bc542e836c5c46e4129a9e0a Mon Sep 17 00:00:00 2001 From: Kris Borchers Date: Sat, 24 Nov 2012 23:18:51 -0600 Subject: Dialog: Update position when size is changed. Fixes #8789 - Dialog does not close for first click on chrome. --- tests/visual/dialog/complex-dialogs.html | 3 +-- ui/jquery.ui.dialog.js | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/visual/dialog/complex-dialogs.html b/tests/visual/dialog/complex-dialogs.html index 5c2e1d8a1..5cd9271ae 100644 --- a/tests/visual/dialog/complex-dialogs.html +++ b/tests/visual/dialog/complex-dialogs.html @@ -24,7 +24,6 @@ $(function() { var dialog = $( "#dialog" ).dialog({ modal: true, - height: 350, width: 500, buttons: [ { @@ -45,7 +44,7 @@ showText: false } ] - }), + }).dialog("option", "height", 600), datepickerDialog = $( "#dialog-datepicker" ).dialog({ autoOpen: false, diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index ea5226ac5..bcfc6f07c 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -527,6 +527,7 @@ $.widget("ui.dialog", { if ( resize ) { this._size(); + this._position(); } if ( this.uiDialog.is( ":data(ui-resizable)" ) ) { this.uiDialog.resizable( "option", resizableOptions ); -- cgit v1.2.3 From a68d5ca31d764a737653461cfba49debdc8ad0ba Mon Sep 17 00:00:00 2001 From: Kris Borchers Date: Sat, 24 Nov 2012 23:18:51 -0600 Subject: Dialog: Add unit test to cover #8789 and #8838. --- tests/unit/dialog/dialog_events.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests') diff --git a/tests/unit/dialog/dialog_events.js b/tests/unit/dialog/dialog_events.js index eeb17eb93..cbeced0f8 100644 --- a/tests/unit/dialog/dialog_events.js +++ b/tests/unit/dialog/dialog_events.js @@ -325,4 +325,20 @@ test("beforeClose", function() { el.remove(); }); +// #8789 and #8838 +asyncTest("ensure dialog's container doesn't scroll on resize and focus", function() { + expect(2); + + var el = $('#dialog1').dialog(), + initialScroll = $(window).scrollTop(); + el.dialog('option', 'height', 600); + equal($(window).scrollTop(), initialScroll, "scroll hasn't moved after height change"); + setTimeout( function(){ + $(".ui-dialog-titlebar-close").simulate('mousedown'); + equal($(window).scrollTop(), initialScroll, "scroll hasn't moved after focus moved to dialog"); + el.dialog('destroy'); + start(); + }, 500); +}); + })(jQuery); -- cgit v1.2.3 From 0cd470b0d5f8c617e761c4a6c90aeea4e3f54128 Mon Sep 17 00:00:00 2001 From: TJ VanToll Date: Sat, 24 Nov 2012 16:23:03 -0500 Subject: Resizable: Modified the default z-index value of resizable handles. Fixed #7960 - Dialog: Modal dialogs do not disable resizables on the page. --- tests/unit/resizable/resizable.html | 2 ++ tests/unit/resizable/resizable_common.js | 2 +- tests/unit/resizable/resizable_options.js | 14 ++++++++++++++ ui/jquery.ui.resizable.js | 3 ++- 4 files changed, 19 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/unit/resizable/resizable.html b/tests/unit/resizable/resizable.html index 0a27f2a80..7a63de0bc 100644 --- a/tests/unit/resizable/resizable.html +++ b/tests/unit/resizable/resizable.html @@ -16,6 +16,8 @@ "ui/jquery.ui.core.js", "ui/jquery.ui.widget.js", "ui/jquery.ui.mouse.js", + "ui/jquery.ui.button.js", + "ui/jquery.ui.dialog.js", "ui/jquery.ui.resizable.js" ] }); diff --git a/tests/unit/resizable/resizable_common.js b/tests/unit/resizable/resizable_common.js index 119f5bd0e..2c64f3cb1 100644 --- a/tests/unit/resizable/resizable_common.js +++ b/tests/unit/resizable/resizable_common.js @@ -19,7 +19,7 @@ TestHelpers.commonWidgetTests('resizable', { maxWidth: null, minHeight: 10, minWidth: 10, - zIndex: 1000, + zIndex: 90, // callbacks create: null diff --git a/tests/unit/resizable/resizable_options.js b/tests/unit/resizable/resizable_options.js index 4b47762ab..c8627953b 100644 --- a/tests/unit/resizable/resizable_options.js +++ b/tests/unit/resizable/resizable_options.js @@ -210,4 +210,18 @@ test("zIndex, applied to all handles", function() { }); }); +test( "zIndex, less than a modal dialog's overlay by default", function() { + expect(1); + + var resizable = $( '
    ' ).resizable(); + var dialog = $( '
    ' ).dialog( { modal: true }); + + var resizableZIndex = resizable.resizable( 'option', 'zIndex' ); + var overlayZIndex = $( '.ui-widget-overlay' ).css( 'zIndex' ); + overlayZIndex = parseInt( overlayZIndex, 10 ); + + ok( resizableZIndex < overlayZIndex, "Resizables behind a modal dialog must have a smaller z-index than the overlay so that they're not resizable. See #7960." ); + dialog.dialog( 'destroy' ); +}); + })(jQuery); diff --git a/ui/jquery.ui.resizable.js b/ui/jquery.ui.resizable.js index 41f3c03c0..4a019336e 100644 --- a/ui/jquery.ui.resizable.js +++ b/ui/jquery.ui.resizable.js @@ -42,7 +42,8 @@ $.widget("ui.resizable", $.ui.mouse, { maxWidth: null, minHeight: 10, minWidth: 10, - zIndex: 1000 + // See #7960 + zIndex: 90 }, _create: function() { -- cgit v1.2.3 From ee8d20ea067f29c90a0c46ddb91584989d585b28 Mon Sep 17 00:00:00 2001 From: Scott González Date: Mon, 26 Nov 2012 16:27:18 -0500 Subject: Dialog: Moved resizable handle test from resizable. --- tests/unit/dialog/dialog_core.js | 13 +++++++++++++ tests/unit/resizable/resizable.html | 2 -- tests/unit/resizable/resizable_options.js | 14 -------------- 3 files changed, 13 insertions(+), 16 deletions(-) (limited to 'tests') diff --git a/tests/unit/dialog/dialog_core.js b/tests/unit/dialog/dialog_core.js index 404e81770..9c0e80825 100644 --- a/tests/unit/dialog/dialog_core.js +++ b/tests/unit/dialog/dialog_core.js @@ -80,4 +80,17 @@ test( "focus tabbable", function() { }, 13); }); +// #7960 +test( "resizable handles below modal overlays", function() { + expect( 1 ); + + var resizable = $( "
    " ).resizable(), + dialog = $( "
    " ).dialog({ modal: true }), + resizableZindex = parseInt( resizable.find( ".ui-resizable-handle" ).css( "zIndex" ), 10 ), + overlayZindex = parseInt( $( ".ui-widget-overlay" ).css( "zIndex" ), 10 ); + + ok( resizableZindex < overlayZindex, "Resizable handles have lower z-index than modal overlay" ); + dialog.dialog( "destroy" ); +}); + })(jQuery); diff --git a/tests/unit/resizable/resizable.html b/tests/unit/resizable/resizable.html index 7a63de0bc..0a27f2a80 100644 --- a/tests/unit/resizable/resizable.html +++ b/tests/unit/resizable/resizable.html @@ -16,8 +16,6 @@ "ui/jquery.ui.core.js", "ui/jquery.ui.widget.js", "ui/jquery.ui.mouse.js", - "ui/jquery.ui.button.js", - "ui/jquery.ui.dialog.js", "ui/jquery.ui.resizable.js" ] }); diff --git a/tests/unit/resizable/resizable_options.js b/tests/unit/resizable/resizable_options.js index c8627953b..4b47762ab 100644 --- a/tests/unit/resizable/resizable_options.js +++ b/tests/unit/resizable/resizable_options.js @@ -210,18 +210,4 @@ test("zIndex, applied to all handles", function() { }); }); -test( "zIndex, less than a modal dialog's overlay by default", function() { - expect(1); - - var resizable = $( '
    ' ).resizable(); - var dialog = $( '
    ' ).dialog( { modal: true }); - - var resizableZIndex = resizable.resizable( 'option', 'zIndex' ); - var overlayZIndex = $( '.ui-widget-overlay' ).css( 'zIndex' ); - overlayZIndex = parseInt( overlayZIndex, 10 ); - - ok( resizableZIndex < overlayZIndex, "Resizables behind a modal dialog must have a smaller z-index than the overlay so that they're not resizable. See #7960." ); - dialog.dialog( 'destroy' ); -}); - })(jQuery); -- cgit v1.2.3 From 6121683d807b2da56cf6cde3240d5926421b280b Mon Sep 17 00:00:00 2001 From: David Petersen Date: Sun, 25 Nov 2012 19:02:36 -0600 Subject: Tabs: Calculate border and padding on tabs container. Fixed #8836: Height overflows parent with heightStyle: 'fill'. --- tests/unit/tabs/tabs_options.js | 10 +++++++++- ui/jquery.ui.tabs.js | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/unit/tabs/tabs_options.js b/tests/unit/tabs/tabs_options.js index f6e89e84f..c78c42b58 100644 --- a/tests/unit/tabs/tabs_options.js +++ b/tests/unit/tabs/tabs_options.js @@ -235,10 +235,18 @@ test( "{ heightStyle: 'content' }", function() { }); test( "{ heightStyle: 'fill' }", function() { - expect( 2 ); + expect( 4 ); $( "#tabs8Wrapper" ).height( 500 ); var element = $( "#tabs8" ).tabs({ heightStyle: "fill" }); equalHeight( element, 485 ); + element.tabs( "destroy" ); + + element = $( "#tabs8" ).css({ + "border": "1px solid black", + "padding": "1px 0" + }); + element.tabs({ heightStyle: "fill" }); + equalHeight( element, 481 ); }); test( "{ heightStyle: 'fill' } with sibling", function() { diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index 0b6480123..dcb0c2768 100644 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -497,6 +497,8 @@ $.widget( "ui.tabs", { if ( heightStyle === "fill" ) { maxHeight = parent.height(); + maxHeight -= this.element.outerHeight() - this.element.height(); + this.element.siblings( ":visible" ).each(function() { var elem = $( this ), position = elem.css( "position" ); -- cgit v1.2.3 From caacf8f5041ad434b8e0dd1069936eb91e4c3394 Mon Sep 17 00:00:00 2001 From: Fabrício Matté Date: Mon, 26 Nov 2012 20:14:58 -0500 Subject: Button: Let change handler handle display and aria update. Fixed #5518 - Button: Incorrect state after double click in Firefox --- tests/unit/button/button.html | 1 + tests/unit/button/button_events.js | 11 +++++++++++ ui/jquery.ui.button.js | 2 -- 3 files changed, 12 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/unit/button/button.html b/tests/unit/button/button.html index 388209991..ebdc76470 100644 --- a/tests/unit/button/button.html +++ b/tests/unit/button/button.html @@ -68,6 +68,7 @@ +
    diff --git a/tests/unit/button/button_events.js b/tests/unit/button/button_events.js index 7b79c41ea..b808b59b7 100644 --- a/tests/unit/button/button_events.js +++ b/tests/unit/button/button_events.js @@ -23,4 +23,15 @@ test( "when button loses focus, ensure active state is removed (#8559)", functio }).focus().simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ).simulate( "keypress", { keyCode: $.ui.keyCode.ENTER } ); }); +test( "ensure checked and aria after single click on checkbox label button", function() { + expect( 3 ); + + $("#check2").button().change( function() { + var lbl = $( this ).button("widget"); + ok( this.checked, "checked ok" ); + ok( lbl.attr("aria-pressed") === "true", "aria ok" ); + ok( lbl.hasClass("ui-state-active"), "ui-state-active ok" ); + }).button("widget").simulate("click"); +}); + })(jQuery); diff --git a/ui/jquery.ui.button.js b/ui/jquery.ui.button.js index d6eed67dc..1108bd50c 100644 --- a/ui/jquery.ui.button.js +++ b/ui/jquery.ui.button.js @@ -147,8 +147,6 @@ $.widget( "ui.button", { if ( options.disabled || clickDragged ) { return false; } - $( this ).toggleClass( "ui-state-active" ); - that.buttonElement.attr( "aria-pressed", that.element[0].checked ); }); } else if ( this.type === "radio" ) { this.buttonElement.bind( "click" + this.eventNamespace, function() { -- cgit v1.2.3 From 22bd9fc7045f994c7e7ce4abd3eceff4cde88273 Mon Sep 17 00:00:00 2001 From: Mike Sherov Date: Mon, 26 Nov 2012 20:24:31 -0500 Subject: Button Tests: move aria-pressed test to correct module --- tests/unit/button/button_core.js | 11 +++++++++++ tests/unit/button/button_events.js | 11 ----------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/unit/button/button_core.js b/tests/unit/button/button_core.js index f3c50d840..fb03bb8a0 100644 --- a/tests/unit/button/button_core.js +++ b/tests/unit/button/button_core.js @@ -88,4 +88,15 @@ test("buttonset (rtl)", function() { ok( set.children("label:eq(2)").is(".ui-button.ui-corner-left:not(.ui-corner-all)") ); }); +test( "ensure checked and aria after single click on checkbox label button, see #5518", function() { + expect( 3 ); + + $("#check2").button().change( function() { + var lbl = $( this ).button("widget"); + ok( this.checked, "checked ok" ); + ok( lbl.attr("aria-pressed") === "true", "aria ok" ); + ok( lbl.hasClass("ui-state-active"), "ui-state-active ok" ); + }).button("widget").simulate("click"); +}); + })(jQuery); diff --git a/tests/unit/button/button_events.js b/tests/unit/button/button_events.js index b808b59b7..7b79c41ea 100644 --- a/tests/unit/button/button_events.js +++ b/tests/unit/button/button_events.js @@ -23,15 +23,4 @@ test( "when button loses focus, ensure active state is removed (#8559)", functio }).focus().simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ).simulate( "keypress", { keyCode: $.ui.keyCode.ENTER } ); }); -test( "ensure checked and aria after single click on checkbox label button", function() { - expect( 3 ); - - $("#check2").button().change( function() { - var lbl = $( this ).button("widget"); - ok( this.checked, "checked ok" ); - ok( lbl.attr("aria-pressed") === "true", "aria ok" ); - ok( lbl.hasClass("ui-state-active"), "ui-state-active ok" ); - }).button("widget").simulate("click"); -}); - })(jQuery); -- cgit v1.2.3 From f2854408cce7e4b7fc6bf8676761904af9c96bde Mon Sep 17 00:00:00 2001 From: Scott González Date: Tue, 27 Nov 2012 11:21:33 -0500 Subject: Tooltip: Escape the title attribute so that it's treated as text and not HTML. Fixes #8861 - Tooltip: XSS vulnerability in default content. --- demos/autocomplete/combobox.html | 2 +- tests/unit/tooltip/tooltip_options.js | 14 ++++++++++++++ ui/jquery.ui.tooltip.js | 4 +++- 3 files changed, 18 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/demos/autocomplete/combobox.html b/demos/autocomplete/combobox.html index 8c6f59fc1..6229d47b2 100644 --- a/demos/autocomplete/combobox.html +++ b/demos/autocomplete/combobox.html @@ -61,7 +61,7 @@ // remove invalid value, as it didn't match anything $( element ) .val( "" ) - .attr( "title", $( "" ).text( value ).html() + " didn't match any item" ) + .attr( "title", value + " didn't match any item" ) .tooltip( "open" ); select.val( "" ); setTimeout(function() { diff --git a/tests/unit/tooltip/tooltip_options.js b/tests/unit/tooltip/tooltip_options.js index f9da27fb7..01ac25040 100644 --- a/tests/unit/tooltip/tooltip_options.js +++ b/tests/unit/tooltip/tooltip_options.js @@ -16,6 +16,20 @@ test( "content: default", function() { deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "anchortitle" ); }); +test( "content: default; HTML escaping", function() { + expect( 2 ); + var scriptText = "", + element = $( "#tooltipped1" ); + + $.ui.tooltip.hacked = false; + element.attr( "title", scriptText ) + .tooltip() + .tooltip( "open" ); + equal( $.ui.tooltip.hacked, false, "script did not execute" ); + deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), scriptText, + "correct tooltip text" ); +}); + test( "content: return string", function() { expect( 1 ); var element = $( "#tooltipped1" ).tooltip({ diff --git a/ui/jquery.ui.tooltip.js b/ui/jquery.ui.tooltip.js index 2ccd61f46..ab8d5173c 100644 --- a/ui/jquery.ui.tooltip.js +++ b/ui/jquery.ui.tooltip.js @@ -46,7 +46,9 @@ $.widget( "ui.tooltip", { version: "@VERSION", options: { content: function() { - return $( this ).attr( "title" ); + var title = $( this ).attr( "title" ); + // Escape title, since we're going from an attribute to raw HTML + return $( "" ).text( title ).html(); }, hide: true, // Disabled elements have inconsistent behavior across browsers (#8661) -- cgit v1.2.3 From dec844570fae5edf56876b760b9358fde2ecb5e7 Mon Sep 17 00:00:00 2001 From: Scott González Date: Wed, 28 Nov 2012 10:33:44 -0500 Subject: Autocomplete: When appendTo is a jQuery object or a DOM element, don't search against the document. Fixes #8858 - Autocomplete: Fails when appendTo is detached from the DOM. --- tests/unit/autocomplete/autocomplete_options.js | 17 +++++++++++++++-- ui/jquery.ui.autocomplete.js | 10 +++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/unit/autocomplete/autocomplete_options.js b/tests/unit/autocomplete/autocomplete_options.js index 8331c53d5..d3a25d2fc 100644 --- a/tests/unit/autocomplete/autocomplete_options.js +++ b/tests/unit/autocomplete/autocomplete_options.js @@ -5,8 +5,9 @@ module( "autocomplete: options" ); var data = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl" ]; test( "appendTo", function() { - expect( 5 ); - var element = $( "#autocomplete" ).autocomplete(); + expect( 7 ); + var detached = $( "
    " ), + element = $( "#autocomplete" ).autocomplete(); equal( element.autocomplete( "widget" ).parent()[0], document.body, "defaults to body" ); element.autocomplete( "destroy" ); @@ -26,6 +27,18 @@ test( "appendTo", function() { element.autocomplete().autocomplete( "option", "appendTo", "#ac-wrap1" ); equal( element.autocomplete( "widget" ).parent()[0], $( "#ac-wrap1" )[0], "modified after init" ); element.autocomplete( "destroy" ); + + element.autocomplete({ + appendTo: detached + }); + equal( element.autocomplete( "widget" ).parent()[0], detached[0], "detached jQuery object" ); + element.autocomplete( "destroy" ); + + element.autocomplete({ + appendTo: detached[0] + }); + equal( element.autocomplete( "widget" ).parent()[0], detached[0], "detached DOM element" ); + element.autocomplete( "destroy" ); }); function autoFocusTest( afValue, focusedLength ) { diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index f2a7089c4..5edb84d44 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -181,7 +181,7 @@ $.widget( "ui.autocomplete", { this._initSource(); this.menu = $( "
      " ) .addClass( "ui-autocomplete" ) - .appendTo( this.document.find( this.options.appendTo || "body" )[ 0 ] ) + .appendTo( this._appendTo() ) .menu({ // custom key handling for now input: $(), @@ -320,6 +320,14 @@ $.widget( "ui.autocomplete", { } }, + _appendTo: function() { + var element = this.options.appendTo; + if ( element && (element.jquery || element.nodeType) ) { + return $( element ); + } + return this.document.find( element || "body" ).eq( 0 ); + }, + _isMultiLine: function() { // Textareas are always multi-line if ( this.element.is( "textarea" ) ) { -- cgit v1.2.3 From 37ea7341823e7dfe54f37596b1d054b8a2e5c3de Mon Sep 17 00:00:00 2001 From: Mike Sherov Date: Wed, 28 Nov 2012 11:21:52 -0500 Subject: Button tests: simulated clicks aren't perfect in oldIE and Opera --- tests/unit/button/button_core.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/unit/button/button_core.js b/tests/unit/button/button_core.js index fb03bb8a0..d53dedf90 100644 --- a/tests/unit/button/button_core.js +++ b/tests/unit/button/button_core.js @@ -88,15 +88,20 @@ test("buttonset (rtl)", function() { ok( set.children("label:eq(2)").is(".ui-button.ui-corner-left:not(.ui-corner-all)") ); }); -test( "ensure checked and aria after single click on checkbox label button, see #5518", function() { - expect( 3 ); - - $("#check2").button().change( function() { - var lbl = $( this ).button("widget"); - ok( this.checked, "checked ok" ); - ok( lbl.attr("aria-pressed") === "true", "aria ok" ); - ok( lbl.hasClass("ui-state-active"), "ui-state-active ok" ); - }).button("widget").simulate("click"); -}); +// TODO: simulated click events don't behave like real click events in IE +// remove this when simulate properly simulates this +// see http://yuilibrary.com/projects/yui2/ticket/2528826 fore more info +if ( !$.ui.ie || ( document.documentMode && document.documentMode > 8 ) ) { + test( "ensure checked and aria after single click on checkbox label button, see #5518", function() { + expect( 3 ); + + $("#check2").button().change( function() { + var lbl = $( this ).button("widget"); + ok( this.checked, "checked ok" ); + ok( lbl.attr("aria-pressed") === "true", "aria ok" ); + ok( lbl.hasClass("ui-state-active"), "ui-state-active ok" ); + }).button("widget").simulate("mousedown").simulate("click").simulate("mouseup"); + }); +} })(jQuery); -- cgit v1.2.3