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_options.js | 42 ++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 17 deletions(-) (limited to 'tests/unit/dialog/dialog_options.js') 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(); }); -- 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/unit/dialog/dialog_options.js') 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 @@ + + 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 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/unit/dialog/dialog_options.js') 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