From 24d9141597f16fdc84b1412683a7e66388f5f622 Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Thu, 29 Nov 2012 17:40:31 +0100 Subject: Dialog: Use consistent code for appending to body --- ui/jquery.ui.dialog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index 808d31d5b..46fc7adf4 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -676,7 +676,7 @@ $.widget("ui.dialog", { // reuse old instances due to IE memory leak with alpha transparency (see #5185) var $el = this.overlay = ( $.ui.dialog.overlay.oldInstances.pop() || $( "
" ).addClass( "ui-widget-overlay ui-front" ) ); - $el.appendTo( document.body ); + $el.appendTo( this.document[ 0 ].body ); this._on( $el, { mousedown: "_keepFocus" -- cgit v1.2.3 From f2ee4c51aa919c7bc3db9f93a4f79479ef062bf9 Mon Sep 17 00:00:00 2001 From: Kris Borchers Date: Thu, 29 Nov 2012 22:12:02 -0600 Subject: Progressbar: Create and destroy indeterminate overlay as needed and code cleanup. --- ui/jquery.ui.progressbar.js | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'ui') diff --git a/ui/jquery.ui.progressbar.js b/ui/jquery.ui.progressbar.js index 0b1ee8aba..0f97bc3fe 100644 --- a/ui/jquery.ui.progressbar.js +++ b/ui/jquery.ui.progressbar.js @@ -36,7 +36,7 @@ $.widget( "ui.progressbar", { "aria-valuenow": this.options.value }); - this.valueDiv = $( "
" ) + this.valueDiv = $( "
" ) .appendTo( this.element ); this.oldValue = this.options.value; @@ -114,11 +114,29 @@ $.widget( "ui.progressbar", { _refreshValue: function() { var value = this.options.value, - percentage = this._percentage(), - overlay = this.valueDiv.children().eq( 0 ); + percentage = this._percentage(); - overlay.toggleClass( "ui-progressbar-overlay", this.indeterminate ); - this.valueDiv.toggleClass( "ui-progressbar-indeterminate", this.indeterminate ); + this.valueDiv + .toggle( this.indeterminate || value > this.min ) + .toggleClass( "ui-corner-right", value === this.options.max ) + .toggleClass( "ui-progressbar-indeterminate", this.indeterminate ) + .width( percentage.toFixed(0) + "%" ); + + if ( this.indeterminate ) { + this.element.removeAttr( "aria-valuemax" ).removeAttr( "aria-valuenow" ); + if ( !this.overlayDiv ) { + this.overlayDiv = $( "
" ).appendTo( this.valueDiv ); + } + } else { + this.element.attr({ + "aria-valuemax": this.options.max, + "aria-valuenow": value + }); + if ( this.overlayDiv ) { + this.overlayDiv.remove(); + this.overlayDiv = null; + } + } if ( this.oldValue !== value ) { this.oldValue = value; @@ -127,18 +145,6 @@ $.widget( "ui.progressbar", { if ( value === this.options.max ) { this._trigger( "complete" ); } - - this.valueDiv - .toggle( this.indeterminate || value > this.min ) - .toggleClass( "ui-corner-right", value === this.options.max ) - .width( percentage.toFixed(0) + "%" ); - if ( this.indeterminate ) { - this.element.removeAttr( "aria-valuemax" ); - this.element.removeAttr( "aria-valuenow" ); - } else { - this.element.attr( "aria-valuemax", this.options.max ); - this.element.attr( "aria-valuenow", value ); - } } }); -- cgit v1.2.3 From 13505e5945e5532c3d56424d50ad109c665d205f Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Fri, 30 Nov 2012 13:08:56 +0100 Subject: Dialog: Ensure all animations finish and clean up themselve when destroying dialog. Fixes #5860 - Dialog: Destroying a dialog during animated close leaves .ui-effects-wrapper in DOM. --- tests/unit/dialog/dialog.html | 2 ++ tests/unit/dialog/dialog_options.js | 9 +++++++++ ui/jquery.ui.dialog.js | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) (limited to 'ui') diff --git a/tests/unit/dialog/dialog.html b/tests/unit/dialog/dialog.html index 5413e7cc1..cdc846478 100644 --- a/tests/unit/dialog/dialog.html +++ b/tests/unit/dialog/dialog.html @@ -23,6 +23,8 @@ "ui/jquery.ui.draggable.js", "ui/jquery.ui.resizable.js", "ui/jquery.ui.button.js", + "ui/jquery.ui.effect.js", + "ui/jquery.ui.effect-clip.js", "ui/jquery.ui.dialog.js" ] }); diff --git a/tests/unit/dialog/dialog_options.js b/tests/unit/dialog/dialog_options.js index f01a1a2a8..fd7d91827 100644 --- a/tests/unit/dialog/dialog_options.js +++ b/tests/unit/dialog/dialog_options.js @@ -212,6 +212,15 @@ test("height", function() { el.remove(); }); +asyncTest( "hide, #5860 - don't leave effects wrapper behind", function() { + expect( 1 ); + $( "#dialog1" ).dialog({ hide: "clip" }).dialog( "close" ).dialog( "destroy" ); + setTimeout(function() { + equal( $( ".ui-effects-wrapper" ).length, 0 ); + start(); + }, 500); +}); + test("maxHeight", function() { expect(3); diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index 46fc7adf4..4a8b9964f 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -131,7 +131,7 @@ $.widget("ui.dialog", { // without detaching first, the following becomes really slow .detach(); - this.uiDialog.remove(); + this.uiDialog.stop( true, true ).remove(); if ( this.originalTitle ) { this.element.attr( "title", this.originalTitle ); -- cgit v1.2.3 From 5ba267e7c78f0bc257383c822d241c5369e8e49d Mon Sep 17 00:00:00 2001 From: Scott González Date: Mon, 3 Dec 2012 10:36:55 -0500 Subject: Resizable: Respect containment for alsoResize option. Fixes #4603 - Resizable: alsoResize option doesn't work with containment. Fixes #5559 - Dialog: Content grows bigger than widget on resize at document edge. --- tests/unit/resizable/resizable.html | 26 ++++--- tests/unit/resizable/resizable_options.js | 55 ++++++++++++++ ui/jquery.ui.resizable.js | 122 +++++++++++++++--------------- 3 files changed, 132 insertions(+), 71 deletions(-) (limited to 'ui') diff --git a/tests/unit/resizable/resizable.html b/tests/unit/resizable/resizable.html index 0a27f2a80..255c98887 100644 --- a/tests/unit/resizable/resizable.html +++ b/tests/unit/resizable/resizable.html @@ -31,15 +31,19 @@ @@ -51,7 +55,9 @@
    -
    I'm a resizable.
    +
    +
    I'm a resizable.
    +
    solid gray
    diff --git a/tests/unit/resizable/resizable_options.js b/tests/unit/resizable/resizable_options.js index 4b47762ab..d79523183 100644 --- a/tests/unit/resizable/resizable_options.js +++ b/tests/unit/resizable/resizable_options.js @@ -5,6 +5,26 @@ module("resizable: options"); +test( "alsoResize", function() { + expect( 2 ); + + var other = $( "
    " ) + .css({ + width: 50, + height: 50 + }) + .appendTo( "body" ), + element = $( "#resizable1" ).resizable({ + alsoResize: other + }), + handle = ".ui-resizable-e"; + + TestHelpers.resizable.drag( handle, 80 ); + equal( element.width(), 180, "resizable width" ); + equal( other.width(), 130, "alsoResize width" ); +}); + + test("aspectRatio: 'preserve' (e)", function() { expect(4); @@ -103,6 +123,21 @@ test("aspectRatio: 'preserve' (ne)", function() { equal( target.height(), 70, "compare minHeight"); }); +test( "containment", function() { + expect( 4 ); + var element = $( "#resizable1" ).resizable({ + containment: "#container" + }); + + TestHelpers.resizable.drag( ".ui-resizable-se", 20, 30 ); + equal( element.width(), 120, "unconstrained width within container" ); + equal( element.height(), 130, "unconstrained height within container" ); + + TestHelpers.resizable.drag( ".ui-resizable-se", 400, 400 ); + equal( element.width(), 300, "constrained width at containment edge" ); + equal( element.height(), 200, "constrained height at containment edge" ); +}); + test("grid", function() { expect(4); @@ -210,4 +245,24 @@ test("zIndex, applied to all handles", function() { }); }); +test( "alsoResize + containment", function() { + expect( 4 ); + var other = $( "
    " ) + .css({ + width: 50, + height: 50 + }) + .appendTo( "body" ), + element = $( "#resizable1" ).resizable({ + alsoResize: other, + containment: "#container" + }); + + TestHelpers.resizable.drag( ".ui-resizable-se", 400, 400 ); + equal( element.width(), 300, "resizable constrained width at containment edge" ); + equal( element.height(), 200, "resizable constrained height at containment edge" ); + equal( other.width(), 250, "alsoResize constrained width at containment edge" ); + equal( other.height(), 150, "alsoResize constrained height at containment edge" ); +}); + })(jQuery); diff --git a/ui/jquery.ui.resizable.js b/ui/jquery.ui.resizable.js index 4a019336e..b417288d8 100644 --- a/ui/jquery.ui.resizable.js +++ b/ui/jquery.ui.resizable.js @@ -643,67 +643,6 @@ $.widget("ui.resizable", $.ui.mouse, { * Resizable Extensions */ -$.ui.plugin.add("resizable", "alsoResize", { - - start: function () { - var that = $(this).data("ui-resizable"), - o = that.options, - _store = function (exp) { - $(exp).each(function() { - var el = $(this); - el.data("ui-resizable-alsoresize", { - width: parseInt(el.width(), 10), height: parseInt(el.height(), 10), - left: parseInt(el.css('left'), 10), top: parseInt(el.css('top'), 10) - }); - }); - }; - - if (typeof(o.alsoResize) === 'object' && !o.alsoResize.parentNode) { - if (o.alsoResize.length) { o.alsoResize = o.alsoResize[0]; _store(o.alsoResize); } - else { $.each(o.alsoResize, function (exp) { _store(exp); }); } - }else{ - _store(o.alsoResize); - } - }, - - resize: function (event, ui) { - var that = $(this).data("ui-resizable"), - o = that.options, - os = that.originalSize, - op = that.originalPosition, - delta = { - height: (that.size.height - os.height) || 0, width: (that.size.width - os.width) || 0, - top: (that.position.top - op.top) || 0, left: (that.position.left - op.left) || 0 - }, - - _alsoResize = function (exp, c) { - $(exp).each(function() { - var el = $(this), start = $(this).data("ui-resizable-alsoresize"), style = {}, - css = c && c.length ? c : el.parents(ui.originalElement[0]).length ? ['width', 'height'] : ['width', 'height', 'top', 'left']; - - $.each(css, function (i, prop) { - var sum = (start[prop]||0) + (delta[prop]||0); - if (sum && sum >= 0) { - style[prop] = sum || null; - } - }); - - el.css(style); - }); - }; - - if (typeof(o.alsoResize) === 'object' && !o.alsoResize.nodeType) { - $.each(o.alsoResize, function (exp, c) { _alsoResize(exp, c); }); - }else{ - _alsoResize(o.alsoResize); - } - }, - - stop: function () { - $(this).removeData("resizable-alsoresize"); - } -}); - $.ui.plugin.add("resizable", "animate", { stop: function( event ) { @@ -871,6 +810,67 @@ $.ui.plugin.add("resizable", "containment", { } }); +$.ui.plugin.add("resizable", "alsoResize", { + + start: function () { + var that = $(this).data("ui-resizable"), + o = that.options, + _store = function (exp) { + $(exp).each(function() { + var el = $(this); + el.data("ui-resizable-alsoresize", { + width: parseInt(el.width(), 10), height: parseInt(el.height(), 10), + left: parseInt(el.css('left'), 10), top: parseInt(el.css('top'), 10) + }); + }); + }; + + if (typeof(o.alsoResize) === 'object' && !o.alsoResize.parentNode) { + if (o.alsoResize.length) { o.alsoResize = o.alsoResize[0]; _store(o.alsoResize); } + else { $.each(o.alsoResize, function (exp) { _store(exp); }); } + }else{ + _store(o.alsoResize); + } + }, + + resize: function (event, ui) { + var that = $(this).data("ui-resizable"), + o = that.options, + os = that.originalSize, + op = that.originalPosition, + delta = { + height: (that.size.height - os.height) || 0, width: (that.size.width - os.width) || 0, + top: (that.position.top - op.top) || 0, left: (that.position.left - op.left) || 0 + }, + + _alsoResize = function (exp, c) { + $(exp).each(function() { + var el = $(this), start = $(this).data("ui-resizable-alsoresize"), style = {}, + css = c && c.length ? c : el.parents(ui.originalElement[0]).length ? ['width', 'height'] : ['width', 'height', 'top', 'left']; + + $.each(css, function (i, prop) { + var sum = (start[prop]||0) + (delta[prop]||0); + if (sum && sum >= 0) { + style[prop] = sum || null; + } + }); + + el.css(style); + }); + }; + + if (typeof(o.alsoResize) === 'object' && !o.alsoResize.nodeType) { + $.each(o.alsoResize, function (exp, c) { _alsoResize(exp, c); }); + }else{ + _alsoResize(o.alsoResize); + } + }, + + stop: function () { + $(this).removeData("resizable-alsoresize"); + } +}); + $.ui.plugin.add("resizable", "ghost", { start: function() { -- cgit v1.2.3 From 8b15aaf4964490a2a84e8f9d32d86ac750e0d4a2 Mon Sep 17 00:00:00 2001 From: Scott González Date: Mon, 3 Dec 2012 14:18:24 -0500 Subject: Widget: Don't modify the prototype passed to $.widget(). Fixes #8876 - Calling _super calls wrong inherited widget. --- tests/unit/widget/widget_core.js | 49 +++++++++++++++++++++++++++++------ ui/jquery.ui.widget.js | 55 ++++++++++++++++++++++------------------ 2 files changed, 71 insertions(+), 33 deletions(-) (limited to 'ui') diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js index 961e2ff62..8102b1f4f 100644 --- a/tests/unit/widget/widget_core.js +++ b/tests/unit/widget/widget_core.js @@ -13,18 +13,23 @@ TestHelpers.testJshint( "widget" ); test( "widget creation", function() { expect( 5 ); - var myPrototype = { - _create: function() {}, - creationTest: function() {} - }; + var method, + myPrototype = { + _create: function() { + equal( method, "_create", "create function is copied over" ); + }, + creationTest: function() { + equal( method, "creationTest", "random function is copied over" ); + } + }; $.widget( "ui.testWidget", myPrototype ); ok( $.isFunction( $.ui.testWidget ), "constructor was created" ); equal( typeof $.ui.testWidget.prototype, "object", "prototype was created" ); - equal( $.ui.testWidget.prototype._create, myPrototype._create, - "create function is copied over" ); - equal( $.ui.testWidget.prototype.creationTest, myPrototype.creationTest, - "random function is copied over" ); + method = "_create"; + $.ui.testWidget.prototype._create(); + method = "creationTest"; + $.ui.testWidget.prototype.creationTest(); equal( $.ui.testWidget.prototype.option, $.Widget.prototype.option, "option method copied over from base widget" ); }); @@ -1324,6 +1329,34 @@ test( "redefine - widgetEventPrefix", function() { }); +test( "mixins", function() { + expect( 2 ); + + var mixin = { + method: function() { + return "mixed " + this._super(); + } + }; + + $.widget( "ui.testWidget1", { + method: function() { + return "testWidget1"; + } + }); + $.widget( "ui.testWidget2", { + method: function() { + return "testWidget2"; + } + }); + $.widget( "ui.testWidget1", $.ui.testWidget1, mixin ); + $.widget( "ui.testWidget2", $.ui.testWidget2, mixin ); + + equal( $( "
    " ).testWidget1().testWidget1( "method" ), + "mixed testWidget1", "testWidget1 mixin successful" ); + equal( $( "
    " ).testWidget2().testWidget2( "method" ), + "mixed testWidget2", "testWidget2 mixin successful" ); +}); + asyncTest( "_delay", function() { expect( 6 ); var order = 0, diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js index 06f25576a..239492992 100644 --- a/ui/jquery.ui.widget.js +++ b/ui/jquery.ui.widget.js @@ -25,6 +25,9 @@ $.cleanData = function( elems ) { $.widget = function( name, base, prototype ) { var fullName, existingConstructor, constructor, basePrototype, + // proxiedPrototype allows the provided prototype to remain unmodified + // so that it can be used as a mixin for multiple widgets (#8876) + proxiedPrototype = {}, namespace = name.split( "." )[ 0 ]; name = name.split( "." )[ 1 ]; @@ -71,38 +74,40 @@ $.widget = function( name, base, prototype ) { // inheriting from basePrototype.options = $.widget.extend( {}, basePrototype.options ); $.each( prototype, function( prop, value ) { - if ( $.isFunction( value ) ) { - prototype[ prop ] = (function() { - var _super = function() { - return base.prototype[ prop ].apply( this, arguments ); - }, - _superApply = function( args ) { - return base.prototype[ prop ].apply( this, args ); - }; - return function() { - var __super = this._super, - __superApply = this._superApply, - returnValue; - - this._super = _super; - this._superApply = _superApply; - - returnValue = value.apply( this, arguments ); - - this._super = __super; - this._superApply = __superApply; - - return returnValue; - }; - })(); + if ( !$.isFunction( value ) ) { + proxiedPrototype[ prop ] = value; + return; } + proxiedPrototype[ prop ] = (function() { + var _super = function() { + return base.prototype[ prop ].apply( this, arguments ); + }, + _superApply = function( args ) { + return base.prototype[ prop ].apply( this, args ); + }; + return function() { + var __super = this._super, + __superApply = this._superApply, + returnValue; + + this._super = _super; + this._superApply = _superApply; + + returnValue = value.apply( this, arguments ); + + this._super = __super; + this._superApply = __superApply; + + return returnValue; + }; + })(); }); constructor.prototype = $.widget.extend( basePrototype, { // TODO: remove support for widgetEventPrefix // always use the name + a colon as the prefix, e.g., draggable:start // don't prefix for widgets that aren't DOM-based widgetEventPrefix: existingConstructor ? basePrototype.widgetEventPrefix : name - }, prototype, { + }, proxiedPrototype, { constructor: constructor, namespace: namespace, widgetName: name, -- cgit v1.2.3 From d687a1b10d1e176a6a8dd4420f1ea3a890640da0 Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Tue, 4 Dec 2012 00:35:33 +0100 Subject: Dialog: Cleanup style properties on _destroy. Reenables style check in domEqual, while removing commented and unnecessary old code. Fixes #8119 - Dialog: Destroying a dialog leaves style, scrollleft, and scrolltop leftovers. --- tests/unit/dialog/dialog_methods.js | 2 ++ tests/unit/testsuite.js | 32 ++------------------------------ ui/jquery.ui.dialog.js | 5 +++++ 3 files changed, 9 insertions(+), 30 deletions(-) (limited to 'ui') diff --git a/tests/unit/dialog/dialog_methods.js b/tests/unit/dialog/dialog_methods.js index e5275c7a4..3753144f3 100644 --- a/tests/unit/dialog/dialog_methods.js +++ b/tests/unit/dialog/dialog_methods.js @@ -35,6 +35,8 @@ test("init", function() { test("destroy", function() { expect( 6 ); + // expect dialogs to be hidden before and after + $( "#dialog1, #form-dialog" ).hide(); domEqual( "#dialog1", function() { var dialog = $( "#dialog1" ).dialog().dialog( "destroy" ); equal( dialog.parent()[ 0 ], $( "#qunit-fixture" )[ 0 ] ); diff --git a/tests/unit/testsuite.js b/tests/unit/testsuite.js index 18337fe4e..808e6c6ea 100644 --- a/tests/unit/testsuite.js +++ b/tests/unit/testsuite.js @@ -210,36 +210,10 @@ window.domEqual = function( selector, modifier, message ) { "nodeName", "role", "tabIndex", - "title" + "title", + "style" ]; -/* - function getElementStyles( elem ) { - var key, len, - style = elem.ownerDocument.defaultView ? - elem.ownerDocument.defaultView.getComputedStyle( elem, null ) : - elem.currentStyle, - styles = {}; - - if ( style && style.length && style[ 0 ] && style[ style[ 0 ] ] ) { - len = style.length; - while ( len-- ) { - key = style[ len ]; - if ( typeof style[ key ] === "string" ) { - styles[ $.camelCase( key ) ] = style[ key ]; - } - } - // support: Opera, IE <9 - } else { - for ( key in style ) { - if ( typeof style[ key ] === "string" ) { - styles[ key ] = style[ key ]; - } - } - } - return styles; - } -*/ function extract( elem ) { if ( !elem || !elem.length ) { QUnit.push( false, actual, expected, @@ -257,8 +231,6 @@ window.domEqual = function( selector, modifier, message ) { var value = elem.attr( attr ); result[ attr ] = value !== undefined ? value : ""; }); - // TODO: Enable when we can figure out what's happening with accordion - //result.style = getElementStyles( elem[ 0 ] ); result.events = $._data( elem[ 0 ], "events" ); result.data = $.extend( {}, elem.data() ); delete result.data[ $.expando ]; diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index 4a8b9964f..382008e08 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -127,6 +127,11 @@ $.widget("ui.dialog", { this.element .removeUniqueId() .removeClass( "ui-dialog-content ui-widget-content" ) + .css({ + "width": "", + "min-height": "", + "height": "" + }) .hide() // without detaching first, the following becomes really slow .detach(); -- cgit v1.2.3 From 53b940fa27fc50b4663eef77249a9afce4129240 Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Tue, 4 Dec 2012 00:49:37 +0100 Subject: Menu: Remove display property on hidden submenus instead of setting display:block. Surfaced by domEqual now checking for style property (see d687a1b). --- ui/jquery.ui.menu.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/jquery.ui.menu.js b/ui/jquery.ui.menu.js index 45c1ec2e4..26789594d 100644 --- a/ui/jquery.ui.menu.js +++ b/ui/jquery.ui.menu.js @@ -148,7 +148,9 @@ $.widget( "ui.menu", { .removeAttr( "aria-hidden" ) .removeAttr( "aria-disabled" ) .removeUniqueId() - .show(); + .css({ + display: "" + }); // Destroy menu items this.element.find( ".ui-menu-item" ) -- cgit v1.2.3 From b9068c1523f39da8a04c799eebc9adc8b83c7279 Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Tue, 4 Dec 2012 00:56:14 +0100 Subject: Tabs: Remove display property on hidden panels instead of setting display:block. Surfaced by domEqual now checking for style property (see d687a1b). --- ui/jquery.ui.tabs.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index dcb0c2768..d1c7448d6 100644 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -718,7 +718,9 @@ $.widget( "ui.tabs", { } }); - this.panels.show(); + this.panels.css({ + display: "" + }); if ( this.options.heightStyle !== "content" ) { this.panels.css( "height", "" ); -- cgit v1.2.3 From 1e8baf568365f8edc833439315f76e5efe1ba9b6 Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Tue, 4 Dec 2012 01:08:34 +0100 Subject: Dialog: Remove the instance-storing for the overlay, just create one whenever it is needed. Heavily simplifies the code, while the memorly leak should be hardly an issue anymore, since fixed positioning restricts the overlay size to the window dimensions. Fixes #6058 - Dialog overlays are not properly reused when multiple instances of a Dialog exist. --- tests/unit/dialog/dialog_tickets.js | 11 ----------- ui/jquery.ui.dialog.js | 27 +++++++-------------------- 2 files changed, 7 insertions(+), 31 deletions(-) (limited to 'ui') diff --git a/tests/unit/dialog/dialog_tickets.js b/tests/unit/dialog/dialog_tickets.js index 655f1e445..389a243b3 100644 --- a/tests/unit/dialog/dialog_tickets.js +++ b/tests/unit/dialog/dialog_tickets.js @@ -107,17 +107,6 @@ test("#6137: dialog('open') causes form elements to reset on IE7", function() { d1.remove(); }); -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(); -}); - // TODO merge this with the main destroy test test("#4980: Destroy should place element back in original DOM position", function(){ expect( 2 ); diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index 382008e08..77392cb19 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -661,13 +661,13 @@ $.widget("ui.dialog", { if ( !this.options.modal ) { return; } - if ( $.ui.dialog.overlay.instances.length === 0 ) { + if ( $.ui.dialog.overlayInstances === 0 ) { // prevent use of anchors and inputs // we use a setTimeout in case the overlay is created from an // event that we're going to be cancelling (see #2804) setTimeout(function() { // handle $(el).dialog().dialog('close') (see #4065) - if ( $.ui.dialog.overlay.instances.length ) { + if ( $.ui.dialog.overlayInstances ) { $( document ).bind( "focusin.dialog-overlay", function( event ) { if ( !$( event.target ).closest( ".ui-dialog").length ) { event.preventDefault(); @@ -678,40 +678,27 @@ $.widget("ui.dialog", { }, 1 ); } - // reuse old instances due to IE memory leak with alpha transparency (see #5185) - var $el = this.overlay = ( $.ui.dialog.overlay.oldInstances.pop() || $( "
    " ).addClass( "ui-widget-overlay ui-front" ) ); - + var $el = this.overlay = $( "
    " ).addClass( "ui-widget-overlay ui-front" ); $el.appendTo( this.document[ 0 ].body ); - this._on( $el, { mousedown: "_keepFocus" }); - - $.ui.dialog.overlay.instances.push( $el ); + $.ui.dialog.overlayInstances += 1; }, _destroyOverlay: function() { if ( !this.options.modal ) { return; } - var indexOf = $.inArray( this.overlay, $.ui.dialog.overlay.instances ); - - if ( indexOf !== -1 ) { - $.ui.dialog.overlay.oldInstances.push( $.ui.dialog.overlay.instances.splice( indexOf, 1 )[ 0 ] ); - } - - if ( $.ui.dialog.overlay.instances.length === 0 ) { + $.ui.dialog.overlayInstances -= 1; + if ( $.ui.dialog.overlayInstances === 0 ) { $( [ document, window ] ).unbind( ".dialog-overlay" ); } - this.overlay.remove(); } }); -$.ui.dialog.overlay = { - instances: [], - oldInstances: [] -}; +$.ui.dialog.overlayInstances = 0; // DEPRECATED if ( $.uiBackCompat !== false ) { -- cgit v1.2.3 From 9bd44301d36103a951cd9026682b93b7ff0bdd2f Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Tue, 4 Dec 2012 01:17:00 +0100 Subject: Dialog: Refactor _createOverlay and _destroyOverlay to use widget methods and properties. --- ui/jquery.ui.dialog.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'ui') diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index 77392cb19..472d686a2 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -665,17 +665,19 @@ $.widget("ui.dialog", { // prevent use of anchors and inputs // we use a setTimeout in case the overlay is created from an // event that we're going to be cancelling (see #2804) - setTimeout(function() { + this._delay(function() { // handle $(el).dialog().dialog('close') (see #4065) if ( $.ui.dialog.overlayInstances ) { - $( document ).bind( "focusin.dialog-overlay", function( event ) { - if ( !$( event.target ).closest( ".ui-dialog").length ) { - event.preventDefault(); - $( ".ui-dialog:visible:last .ui-dialog-content" ).data( "ui-dialog" )._focusTabbable(); + this._on( this.document, { + focusin: function( event ) { + if ( !$( event.target ).closest( ".ui-dialog").length ) { + event.preventDefault(); + $( ".ui-dialog:visible:last .ui-dialog-content" ).data( "ui-dialog" )._focusTabbable(); + } } }); } - }, 1 ); + }); } var $el = this.overlay = $( "
    " ).addClass( "ui-widget-overlay ui-front" ); @@ -692,7 +694,7 @@ $.widget("ui.dialog", { } $.ui.dialog.overlayInstances -= 1; if ( $.ui.dialog.overlayInstances === 0 ) { - $( [ document, window ] ).unbind( ".dialog-overlay" ); + this._off( this.document, "focusin" ); } this.overlay.remove(); } -- cgit v1.2.3 From 86f1087931dbae7ed82d8110c095093b5444270f Mon Sep 17 00:00:00 2001 From: Scott González Date: Tue, 4 Dec 2012 09:20:56 -0500 Subject: Revert "Tabs: Remove display property on hidden panels instead of setting display:block. Surfaced by domEqual now checking for style property (see d687a1b)." This reverts commit b9068c1523f39da8a04c799eebc9adc8b83c7279. --- ui/jquery.ui.tabs.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'ui') diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index d1c7448d6..dcb0c2768 100644 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -718,9 +718,7 @@ $.widget( "ui.tabs", { } }); - this.panels.css({ - display: "" - }); + this.panels.show(); if ( this.options.heightStyle !== "content" ) { this.panels.css( "height", "" ); -- cgit v1.2.3 From 8072099a3ac78340b4b861d76aac082968cd1df7 Mon Sep 17 00:00:00 2001 From: Scott González Date: Tue, 4 Dec 2012 09:21:16 -0500 Subject: Revert "Menu: Remove display property on hidden submenus instead of setting display:block. Surfaced by domEqual now checking for style property (see d687a1b)." This reverts commit 53b940fa27fc50b4663eef77249a9afce4129240. --- ui/jquery.ui.menu.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'ui') diff --git a/ui/jquery.ui.menu.js b/ui/jquery.ui.menu.js index 26789594d..45c1ec2e4 100644 --- a/ui/jquery.ui.menu.js +++ b/ui/jquery.ui.menu.js @@ -148,9 +148,7 @@ $.widget( "ui.menu", { .removeAttr( "aria-hidden" ) .removeAttr( "aria-disabled" ) .removeUniqueId() - .css({ - display: "" - }); + .show(); // Destroy menu items this.element.find( ".ui-menu-item" ) -- cgit v1.2.3 From 050e71bdd88708ce6e8462a89af4399cffa72cf3 Mon Sep 17 00:00:00 2001 From: Scott González Date: Tue, 4 Dec 2012 09:21:33 -0500 Subject: Revert "Dialog: Cleanup style properties on _destroy. Reenables style check in domEqual, while removing commented and unnecessary old code. Fixes #8119 - Dialog: Destroying a dialog leaves style, scrollleft, and scrolltop leftovers." This reverts commit d687a1b10d1e176a6a8dd4420f1ea3a890640da0. --- tests/unit/dialog/dialog_methods.js | 2 -- tests/unit/testsuite.js | 32 ++++++++++++++++++++++++++++++-- ui/jquery.ui.dialog.js | 5 ----- 3 files changed, 30 insertions(+), 9 deletions(-) (limited to 'ui') diff --git a/tests/unit/dialog/dialog_methods.js b/tests/unit/dialog/dialog_methods.js index 3753144f3..e5275c7a4 100644 --- a/tests/unit/dialog/dialog_methods.js +++ b/tests/unit/dialog/dialog_methods.js @@ -35,8 +35,6 @@ test("init", function() { test("destroy", function() { expect( 6 ); - // expect dialogs to be hidden before and after - $( "#dialog1, #form-dialog" ).hide(); domEqual( "#dialog1", function() { var dialog = $( "#dialog1" ).dialog().dialog( "destroy" ); equal( dialog.parent()[ 0 ], $( "#qunit-fixture" )[ 0 ] ); diff --git a/tests/unit/testsuite.js b/tests/unit/testsuite.js index 808e6c6ea..18337fe4e 100644 --- a/tests/unit/testsuite.js +++ b/tests/unit/testsuite.js @@ -210,10 +210,36 @@ window.domEqual = function( selector, modifier, message ) { "nodeName", "role", "tabIndex", - "title", - "style" + "title" ]; +/* + function getElementStyles( elem ) { + var key, len, + style = elem.ownerDocument.defaultView ? + elem.ownerDocument.defaultView.getComputedStyle( elem, null ) : + elem.currentStyle, + styles = {}; + + if ( style && style.length && style[ 0 ] && style[ style[ 0 ] ] ) { + len = style.length; + while ( len-- ) { + key = style[ len ]; + if ( typeof style[ key ] === "string" ) { + styles[ $.camelCase( key ) ] = style[ key ]; + } + } + // support: Opera, IE <9 + } else { + for ( key in style ) { + if ( typeof style[ key ] === "string" ) { + styles[ key ] = style[ key ]; + } + } + } + return styles; + } +*/ function extract( elem ) { if ( !elem || !elem.length ) { QUnit.push( false, actual, expected, @@ -231,6 +257,8 @@ window.domEqual = function( selector, modifier, message ) { var value = elem.attr( attr ); result[ attr ] = value !== undefined ? value : ""; }); + // TODO: Enable when we can figure out what's happening with accordion + //result.style = getElementStyles( elem[ 0 ] ); result.events = $._data( elem[ 0 ], "events" ); result.data = $.extend( {}, elem.data() ); delete result.data[ $.expando ]; diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index 472d686a2..361beeb4c 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -127,11 +127,6 @@ $.widget("ui.dialog", { this.element .removeUniqueId() .removeClass( "ui-dialog-content ui-widget-content" ) - .css({ - "width": "", - "min-height": "", - "height": "" - }) .hide() // without detaching first, the following becomes really slow .detach(); -- cgit v1.2.3 From 3c2acc322782cc08e575405f8123029342e33542 Mon Sep 17 00:00:00 2001 From: Scott González Date: Tue, 4 Dec 2012 10:03:05 -0500 Subject: Dialog: Remove width, min-height, height styles on destroy. Fixes #8119 - Dialog: Destroying a dialog leaves some styles changed. --- tests/unit/dialog/dialog_methods.js | 5 +++++ tests/unit/testsuite.js | 7 +++---- ui/jquery.ui.dialog.js | 5 +++++ 3 files changed, 13 insertions(+), 4 deletions(-) (limited to 'ui') diff --git a/tests/unit/dialog/dialog_methods.js b/tests/unit/dialog/dialog_methods.js index e5275c7a4..6eeb50273 100644 --- a/tests/unit/dialog/dialog_methods.js +++ b/tests/unit/dialog/dialog_methods.js @@ -35,6 +35,11 @@ test("init", function() { test("destroy", function() { expect( 6 ); + + // Dialogs are expected to be hidden on destroy, so make sure they're hidden + // before the test + $( "#dialog1, #form-dialog" ).hide(); + domEqual( "#dialog1", function() { var dialog = $( "#dialog1" ).dialog().dialog( "destroy" ); equal( dialog.parent()[ 0 ], $( "#qunit-fixture" )[ 0 ] ); diff --git a/tests/unit/testsuite.js b/tests/unit/testsuite.js index 18337fe4e..42fdf4f9e 100644 --- a/tests/unit/testsuite.js +++ b/tests/unit/testsuite.js @@ -212,7 +212,7 @@ window.domEqual = function( selector, modifier, message ) { "tabIndex", "title" ]; -/* + function getElementStyles( elem ) { var key, len, style = elem.ownerDocument.defaultView ? @@ -239,7 +239,7 @@ window.domEqual = function( selector, modifier, message ) { return styles; } -*/ + function extract( elem ) { if ( !elem || !elem.length ) { QUnit.push( false, actual, expected, @@ -257,8 +257,7 @@ window.domEqual = function( selector, modifier, message ) { var value = elem.attr( attr ); result[ attr ] = value !== undefined ? value : ""; }); - // TODO: Enable when we can figure out what's happening with accordion - //result.style = getElementStyles( elem[ 0 ] ); + result.style = getElementStyles( elem[ 0 ] ); result.events = $._data( elem[ 0 ], "events" ); result.data = $.extend( {}, elem.data() ); delete result.data[ $.expando ]; diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index 361beeb4c..96c998656 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -127,6 +127,11 @@ $.widget("ui.dialog", { this.element .removeUniqueId() .removeClass( "ui-dialog-content ui-widget-content" ) + .css({ + width: "", + minHeight: "", + height: "" + }) .hide() // without detaching first, the following becomes really slow .detach(); -- cgit v1.2.3 From 598cdae199fed9b3aa1700142e8e00a61fc6e61a Mon Sep 17 00:00:00 2001 From: Scott González Date: Wed, 5 Dec 2012 10:38:31 -0500 Subject: Datepicker: Handle changes to the disabled option. Fixes #8883 - Datepicker: Changing disabled option doesn't work. --- tests/unit/datepicker/datepicker_options.js | 17 +++++++++++++++++ ui/jquery.ui.datepicker.js | 7 +++++++ 2 files changed, 24 insertions(+) (limited to 'ui') diff --git a/tests/unit/datepicker/datepicker_options.js b/tests/unit/datepicker/datepicker_options.js index 8b8888780..4b09face5 100644 --- a/tests/unit/datepicker/datepicker_options.js +++ b/tests/unit/datepicker/datepicker_options.js @@ -48,6 +48,23 @@ test('option', function() { 'Get default settings'); }); +test( "disabled", function() { + expect(8); + var inp = TestHelpers.datepicker.init('#inp'); + ok(!inp.datepicker('isDisabled'), 'Initially marked as enabled'); + ok(!inp[0].disabled, 'Field initially enabled'); + inp.datepicker('option', 'disabled', true); + ok(inp.datepicker('isDisabled'), 'Marked as disabled'); + ok(inp[0].disabled, 'Field now disabled'); + inp.datepicker('option', 'disabled', false); + ok(!inp.datepicker('isDisabled'), 'Marked as enabled'); + ok(!inp[0].disabled, 'Field now enabled'); + inp.datepicker('destroy'); + + inp = TestHelpers.datepicker.init('#inp', { disabled: true }); + ok(inp.datepicker('isDisabled'), 'Initially marked as disabled'); + ok(inp[0].disabled, 'Field initially disabled'); +}) test('change', function() { expect( 12 ); var inp = TestHelpers.datepicker.init('#inp'), diff --git a/ui/jquery.ui.datepicker.js b/ui/jquery.ui.datepicker.js index 9f480bf38..4ab1fa201 100644 --- a/ui/jquery.ui.datepicker.js +++ b/ui/jquery.ui.datepicker.js @@ -497,6 +497,13 @@ $.extend(Datepicker.prototype, { if (maxDate !== null && settings.dateFormat !== undefined && settings.maxDate === undefined) { inst.settings.maxDate = this._formatDate(inst, maxDate); } + if ( "disabled" in settings ) { + if ( settings.disabled ) { + this._disableDatepicker(target); + } else { + this._enableDatepicker(target); + } + } this._attachments($(target), inst); this._autoSize(inst); this._setDate(inst, date); -- cgit v1.2.3 From cff4c3c4f3395d3f9837bd1affb8107d7ae65841 Mon Sep 17 00:00:00 2001 From: Pavel Selitskas Date: Sun, 2 Dec 2012 17:02:39 +0300 Subject: Datepicker: Added Belarusian locale. Fixes #8885 - Datepicker: Add Belarusian locale. --- demos/datepicker/localization.html | 2 ++ ui/i18n/jquery.ui.datepicker-be.js | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 ui/i18n/jquery.ui.datepicker-be.js (limited to 'ui') diff --git a/demos/datepicker/localization.html b/demos/datepicker/localization.html index f39677f09..c7c415622 100644 --- a/demos/datepicker/localization.html +++ b/demos/datepicker/localization.html @@ -12,6 +12,7 @@ + @@ -100,6 +101,7 @@ + diff --git a/ui/i18n/jquery.ui.datepicker-be.js b/ui/i18n/jquery.ui.datepicker-be.js new file mode 100644 index 000000000..be605dab4 --- /dev/null +++ b/ui/i18n/jquery.ui.datepicker-be.js @@ -0,0 +1,23 @@ +/* Belarusian initialisation for the jQuery UI date picker plugin. */ +/* Written by Pavel Selitskas */ +jQuery(function($){ + $.datepicker.regional['be'] = { + closeText: 'Зачыніць', + prevText: '←Папяр.', + nextText: 'Наст.→', + currentText: 'Сёньня', + monthNames: ['Студзень','Люты','Сакавік','Красавік','Травень','Чэрвень', + 'Ліпень','Жнівень','Верасень','Кастрычнік','Лістапад','Сьнежань'], + monthNamesShort: ['Сту','Лют','Сак','Кра','Тра','Чэр', + 'Ліп','Жні','Вер','Кас','Ліс','Сьн'], + dayNames: ['нядзеля','панядзелак','аўторак','серада','чацьвер','пятніца','субота'], + dayNamesShort: ['ндз','пнд','аўт','срд','чцв','птн','сбт'], + dayNamesMin: ['Нд','Пн','Аў','Ср','Чц','Пт','Сб'], + weekHeader: 'Тд', + dateFormat: 'dd.mm.yy', + firstDay: 1, + isRTL: false, + showMonthAfterYear: false, + yearSuffix: ''}; + $.datepicker.setDefaults($.datepicker.regional['be']); +}); -- cgit v1.2.3 From 70f5d18c715ba1c759393856f0f70acfddbee07a Mon Sep 17 00:00:00 2001 From: Bjørn Johansen Date: Mon, 3 Dec 2012 08:05:06 +0100 Subject: Datepicker: Added Norwegian Bokmål and Norwegian Nynorsk locales. Fixes #8886 - Datepicker: Add Norwegian Bokmål (nb) and Norwegian Nynorsk (nn) locales. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bjørn Johansen --- demos/datepicker/localization.html | 4 ++++ ui/i18n/jquery.ui.datepicker-nb.js | 22 ++++++++++++++++++++++ ui/i18n/jquery.ui.datepicker-nn.js | 22 ++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 ui/i18n/jquery.ui.datepicker-nb.js create mode 100644 ui/i18n/jquery.ui.datepicker-nn.js (limited to 'ui') diff --git a/demos/datepicker/localization.html b/demos/datepicker/localization.html index c7c415622..968196295 100644 --- a/demos/datepicker/localization.html +++ b/demos/datepicker/localization.html @@ -54,8 +54,10 @@ + + @@ -144,7 +146,9 @@ + + diff --git a/ui/i18n/jquery.ui.datepicker-nb.js b/ui/i18n/jquery.ui.datepicker-nb.js new file mode 100644 index 000000000..845a5052d --- /dev/null +++ b/ui/i18n/jquery.ui.datepicker-nb.js @@ -0,0 +1,22 @@ +/* Norwegian Bokmål initialisation for the jQuery UI date picker plugin. */ +/* Written by Bjørn Johansen (post@bjornjohansen.no). */ +jQuery(function($){ + $.datepicker.regional['nb'] = { + closeText: 'Lukk', + prevText: '«Forrige', + nextText: 'Neste»', + currentText: 'I dag', + monthNames: ['januar','februar','mars','april','mai','juni','juli','august','september','oktober','november','desember'], + monthNamesShort: ['jan','feb','mar','apr','mai','jun','jul','aug','sep','okt','nov','des'], + dayNamesShort: ['søn','man','tir','ons','tor','fre','lør'], + dayNames: ['søndag','mandag','tirsdag','onsdag','torsdag','fredag','lørdag'], + dayNamesMin: ['sø','ma','ti','on','to','fr','lø'], + weekHeader: 'Uke', + dateFormat: 'dd.mm.yy', + firstDay: 1, + isRTL: false, + showMonthAfterYear: false, + yearSuffix: '' + }; + $.datepicker.setDefaults($.datepicker.regional['nb']); +}); diff --git a/ui/i18n/jquery.ui.datepicker-nn.js b/ui/i18n/jquery.ui.datepicker-nn.js new file mode 100644 index 000000000..b55245ee6 --- /dev/null +++ b/ui/i18n/jquery.ui.datepicker-nn.js @@ -0,0 +1,22 @@ +/* Norwegian Nynorsk initialisation for the jQuery UI date picker plugin. */ +/* Written by Bjørn Johansen (post@bjornjohansen.no). */ +jQuery(function($){ + $.datepicker.regional['nn'] = { + closeText: 'Lukk', + prevText: '«Førre', + nextText: 'Neste»', + currentText: 'I dag', + monthNames: ['januar','februar','mars','april','mai','juni','juli','august','september','oktober','november','desember'], + monthNamesShort: ['jan','feb','mar','apr','mai','jun','jul','aug','sep','okt','nov','des'], + dayNamesShort: ['sun','mån','tys','ons','tor','fre','lau'], + dayNames: ['sundag','måndag','tysdag','onsdag','torsdag','fredag','laurdag'], + dayNamesMin: ['su','må','ty','on','to','fr','la'], + weekHeader: 'Veke', + dateFormat: 'dd.mm.yy', + firstDay: 1, + isRTL: false, + showMonthAfterYear: false, + yearSuffix: '' + }; + $.datepicker.setDefaults($.datepicker.regional['nn']); +}); -- cgit v1.2.3 From f59f5a8b12d50c87ba6e2fe47a1804a23535b3cf Mon Sep 17 00:00:00 2001 From: Scott González Date: Wed, 5 Dec 2012 11:53:34 -0500 Subject: Dialog: Restore inline styles for dimensions/display. Fixes #8119 - Dialog: Destroying a dialog leaves some styles changed. --- tests/unit/dialog/dialog_methods.js | 15 +++++++++++---- ui/jquery.ui.dialog.js | 13 +++++++------ 2 files changed, 18 insertions(+), 10 deletions(-) (limited to 'ui') diff --git a/tests/unit/dialog/dialog_methods.js b/tests/unit/dialog/dialog_methods.js index 6eeb50273..92fe3d60f 100644 --- a/tests/unit/dialog/dialog_methods.js +++ b/tests/unit/dialog/dialog_methods.js @@ -34,12 +34,9 @@ test("init", function() { }); test("destroy", function() { - expect( 6 ); + expect( 7 ); - // Dialogs are expected to be hidden on destroy, so make sure they're hidden - // before the test $( "#dialog1, #form-dialog" ).hide(); - domEqual( "#dialog1", function() { var dialog = $( "#dialog1" ).dialog().dialog( "destroy" ); equal( dialog.parent()[ 0 ], $( "#qunit-fixture" )[ 0 ] ); @@ -50,6 +47,16 @@ test("destroy", function() { equal( dialog.parent()[ 0 ], $( "#qunit-fixture" )[ 0 ] ); equal( dialog.index(), 2 ); }); + + // Ensure dimensions are restored (#8119) + $( "#dialog1" ).show().css({ + width: "400px", + minHeight: "100px", + height: "200px" + }); + domEqual( "#dialog1", function() { + $( "#dialog1" ).dialog().dialog( "destroy" ); + }); }); test( "enable/disable disabled", function() { diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index 96c998656..eac818fe0 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -84,6 +84,12 @@ $.widget("ui.dialog", { }, _create: function() { + this.originalCss = { + display: this.element[0].style.display, + width: this.element[0].style.width, + minHeight: this.element[0].style.minHeight, + height: this.element[0].style.height + }; this.originalTitle = this.element.attr( "title" ); this.options.title = this.options.title || this.originalTitle; this.oldPosition = { @@ -127,12 +133,7 @@ $.widget("ui.dialog", { this.element .removeUniqueId() .removeClass( "ui-dialog-content ui-widget-content" ) - .css({ - width: "", - minHeight: "", - height: "" - }) - .hide() + .css( this.originalCss ) // without detaching first, the following becomes really slow .detach(); -- cgit v1.2.3 From 1e5662ebe5a27d5ef0b8d60730b21771a2526547 Mon Sep 17 00:00:00 2001 From: Scott González Date: Wed, 5 Dec 2012 17:19:14 -0500 Subject: Tabs: Decode URIs before comparing. Fixes #8877 - Tabs: isLocal function issue in Safari 5.1.7. --- ui/jquery.ui.tabs.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'ui') diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index dcb0c2768..bce0585a0 100644 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -23,12 +23,8 @@ function getNextTabId() { function isLocal( anchor ) { return anchor.hash.length > 1 && - anchor.href.replace( rhash, "" ) === - location.href.replace( rhash, "" ) - // support: Safari 5.1 - // Safari 5.1 doesn't encode spaces in window.location - // but it does encode spaces from anchors (#8777) - .replace( /\s/g, "%20" ); + decodeURIComponent( anchor.href.replace( rhash, "" ) ) === + decodeURIComponent( location.href.replace( rhash, "" ) ); } $.widget( "ui.tabs", { -- cgit v1.2.3 From 8c763cdf9836e9e97432167e92d0a5808e033ba2 Mon Sep 17 00:00:00 2001 From: Scott González Date: Thu, 6 Dec 2012 09:21:25 -0500 Subject: Progressbar: Define defaults for callbacks. --- tests/unit/progressbar/progressbar_common.js | 2 ++ ui/jquery.ui.progressbar.js | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'ui') diff --git a/tests/unit/progressbar/progressbar_common.js b/tests/unit/progressbar/progressbar_common.js index 2f97a78bb..ceee3fbec 100644 --- a/tests/unit/progressbar/progressbar_common.js +++ b/tests/unit/progressbar/progressbar_common.js @@ -5,6 +5,8 @@ TestHelpers.commonWidgetTests( "progressbar", { max: 100, //callbacks + change: null, + complete: null, create: null } }); diff --git a/ui/jquery.ui.progressbar.js b/ui/jquery.ui.progressbar.js index 0f97bc3fe..53c9508ed 100644 --- a/ui/jquery.ui.progressbar.js +++ b/ui/jquery.ui.progressbar.js @@ -17,8 +17,11 @@ $.widget( "ui.progressbar", { version: "@VERSION", options: { + max: 100, value: 0, - max: 100 + + change: null, + complete: null }, min: 0, -- cgit v1.2.3 From f1be88e7956fe9114ae20d19242cd8190a6ff399 Mon Sep 17 00:00:00 2001 From: Scott González Date: Thu, 6 Dec 2012 09:35:41 -0500 Subject: Progressbar: Only remove aria-valuenow for indeterminate progressbars. Added more accessibility tests. --- tests/unit/progressbar/progressbar_common.js | 2 +- tests/unit/progressbar/progressbar_core.js | 10 +++++++++- ui/jquery.ui.progressbar.js | 8 ++++---- 3 files changed, 14 insertions(+), 6 deletions(-) (limited to 'ui') diff --git a/tests/unit/progressbar/progressbar_common.js b/tests/unit/progressbar/progressbar_common.js index ceee3fbec..0768576f5 100644 --- a/tests/unit/progressbar/progressbar_common.js +++ b/tests/unit/progressbar/progressbar_common.js @@ -1,8 +1,8 @@ TestHelpers.commonWidgetTests( "progressbar", { defaults: { disabled: false, - value: 0, max: 100, + value: 0, //callbacks change: null, diff --git a/tests/unit/progressbar/progressbar_core.js b/tests/unit/progressbar/progressbar_core.js index 0a2ef895b..54a33cc9d 100644 --- a/tests/unit/progressbar/progressbar_core.js +++ b/tests/unit/progressbar/progressbar_core.js @@ -1,7 +1,7 @@ module( "progressbar: core" ); test( "accessibility", function() { - expect( 7 ); + expect( 11 ); var element = $( "#progressbar" ).progressbar(); equal( element.attr( "role" ), "progressbar", "aria role" ); @@ -12,9 +12,17 @@ test( "accessibility", function() { element.progressbar( "value", 77 ); equal( element.attr( "aria-valuenow" ), 77, "aria-valuenow" ); + element.progressbar( "option", "max", 150 ); + equal( element.attr( "aria-valuemax" ), 150, "aria-valuemax" ); + element.progressbar( "disable" ); equal( element.attr( "aria-disabled" ), "true", "aria-disabled on" ); element.progressbar( "enable" ); equal( element.attr( "aria-disabled" ), "false", "aria-disabled off" ); + + element.progressbar( "option", "value", false ); + equal( element.attr( "aria-valuemin" ), 0, "aria-valuemin" ); + equal( element.attr( "aria-valuemax" ), 150, "aria-valuemax" ); + strictEqual( element.attr( "aria-valuenow" ), undefined, "aria-valuenow initially" ); }); diff --git a/ui/jquery.ui.progressbar.js b/ui/jquery.ui.progressbar.js index 53c9508ed..348f1d061 100644 --- a/ui/jquery.ui.progressbar.js +++ b/ui/jquery.ui.progressbar.js @@ -33,10 +33,10 @@ $.widget( "ui.progressbar", { this.element .addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" ) .attr({ + // Only set static values, aria-valuenow and aria-valuemax are + // set inside _refreshValue() role: "progressbar", - "aria-valuemin": this.min, - "aria-valuemax": this.options.max, - "aria-valuenow": this.options.value + "aria-valuemin": this.min }); this.valueDiv = $( "
    " ) @@ -126,7 +126,7 @@ $.widget( "ui.progressbar", { .width( percentage.toFixed(0) + "%" ); if ( this.indeterminate ) { - this.element.removeAttr( "aria-valuemax" ).removeAttr( "aria-valuenow" ); + this.element.removeAttr( "aria-valuenow" ); if ( !this.overlayDiv ) { this.overlayDiv = $( "
    " ).appendTo( this.valueDiv ); } -- cgit v1.2.3 From f7614706abfdbc653de53fbc31361f9aacab8821 Mon Sep 17 00:00:00 2001 From: Scott González Date: Thu, 6 Dec 2012 10:10:07 -0500 Subject: Progressbar: Cleanup, byte shaving. --- tests/unit/progressbar/progressbar_core.js | 2 +- ui/jquery.ui.progressbar.js | 42 ++++++++++++------------------ 2 files changed, 17 insertions(+), 27 deletions(-) (limited to 'ui') diff --git a/tests/unit/progressbar/progressbar_core.js b/tests/unit/progressbar/progressbar_core.js index 54a33cc9d..cffd84d21 100644 --- a/tests/unit/progressbar/progressbar_core.js +++ b/tests/unit/progressbar/progressbar_core.js @@ -24,5 +24,5 @@ test( "accessibility", function() { element.progressbar( "option", "value", false ); equal( element.attr( "aria-valuemin" ), 0, "aria-valuemin" ); equal( element.attr( "aria-valuemax" ), 150, "aria-valuemax" ); - strictEqual( element.attr( "aria-valuenow" ), undefined, "aria-valuenow initially" ); + strictEqual( element.attr( "aria-valuenow" ), undefined, "aria-valuenow" ); }); diff --git a/ui/jquery.ui.progressbar.js b/ui/jquery.ui.progressbar.js index 348f1d061..46051d2c9 100644 --- a/ui/jquery.ui.progressbar.js +++ b/ui/jquery.ui.progressbar.js @@ -28,7 +28,7 @@ $.widget( "ui.progressbar", { _create: function() { // Constrain initial value - this.options.value = this._constrainedValue(); + this.oldValue = this.options.value = this._constrainedValue(); this.element .addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" ) @@ -42,7 +42,6 @@ $.widget( "ui.progressbar", { this.valueDiv = $( "
    " ) .appendTo( this.element ); - this.oldValue = this.options.value; this._refreshValue(); }, @@ -62,53 +61,44 @@ $.widget( "ui.progressbar", { return this.options.value; } - this._setOption( "value", this._constrainedValue( newValue ) ); - return this; + this.options.value = this._constrainedValue( newValue ); + this._refreshValue(); }, _constrainedValue: function( newValue ) { - var val; if ( newValue === undefined ) { - val = this.options.value; - } else { - val = newValue; + newValue = this.options.value; } - this.indeterminate = val === false; + this.indeterminate = newValue === false; // sanitize value - if ( typeof val !== "number" ) { - val = 0; + if ( typeof newValue !== "number" ) { + newValue = 0; } - return this.indeterminate ? false : Math.min( this.options.max, Math.max( this.min, val ) ); + + return this.indeterminate ? false : + Math.min( this.options.max, Math.max( this.min, newValue ) ); }, _setOptions: function( options ) { - var val = options.value; - // Ensure "value" option is set after other values (like max) + var value = options.value; delete options.value; + this._super( options ); - if ( val !== undefined ) { - this._setOption( "value", val ); - } + this.options.value = this._constrainedValue( value ); + this._refreshValue(); }, _setOption: function( key, value ) { if ( key === "max" ) { // Don't allow a max less than min - this.options.max = Math.max( this.min, value ); - this.options.value = this._constrainedValue(); - } - if ( key === "value" ) { - this.options.value = this._constrainedValue( value ); - } - else { - this._super( key, value ); + value = Math.max( this.min, value ); } - this._refreshValue(); + this._super( key, value ); }, _percentage: function() { -- cgit v1.2.3 From b44375aef19f54e1b4ef5caee6c748b6d9058814 Mon Sep 17 00:00:00 2001 From: Kris Borchers Date: Thu, 6 Dec 2012 11:07:07 -0600 Subject: Progressbar: Take min into account when calculating percentage. --- ui/jquery.ui.progressbar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/jquery.ui.progressbar.js b/ui/jquery.ui.progressbar.js index 46051d2c9..163bb06cd 100644 --- a/ui/jquery.ui.progressbar.js +++ b/ui/jquery.ui.progressbar.js @@ -102,7 +102,7 @@ $.widget( "ui.progressbar", { }, _percentage: function() { - return this.indeterminate ? 100 : 100 * this.options.value / this.options.max; + return this.indeterminate ? 100 : 100 * ( this.options.value - this.min ) / ( this.options.max - this.min ); }, _refreshValue: function() { -- cgit v1.2.3 From ebf8a601871c70ed4a7fdf28505fee6781d21504 Mon Sep 17 00:00:00 2001 From: Scott González Date: Thu, 6 Dec 2012 14:18:20 -0500 Subject: Tabs: Reduce cyclomatic complexity. --- ui/jquery.ui.tabs.js | 65 +++++++++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 29 deletions(-) (limited to 'ui') diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index bce0585a0..fb66ec6a5 100644 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -47,9 +47,7 @@ $.widget( "ui.tabs", { _create: function() { var that = this, - options = this.options, - active = options.active, - locationHash = location.hash.substring( 1 ); + options = this.options; this.running = false; @@ -75,6 +73,36 @@ $.widget( "ui.tabs", { }); this._processTabs(); + options.active = this._initialActive(); + + // Take disabling tabs via class attribute from HTML + // into account and update option properly. + if ( $.isArray( options.disabled ) ) { + options.disabled = $.unique( options.disabled.concat( + $.map( this.tabs.filter( ".ui-state-disabled" ), function( li ) { + return that.tabs.index( li ); + }) + ) ).sort(); + } + + // check for length avoids error when initializing empty list + if ( this.options.active !== false && this.anchors.length ) { + this.active = this._findActive( options.active ); + } else { + this.active = $(); + } + + this._refresh(); + + if ( this.active.length ) { + this.load( options.active ); + } + }, + + _initialActive: function() { + var active = this.options.active, + collapsible = this.options.collapsible, + locationHash = location.hash.substring( 1 ); if ( active === null ) { // check the fragment identifier in the URL @@ -102,38 +130,16 @@ $.widget( "ui.tabs", { if ( active !== false ) { active = this.tabs.index( this.tabs.eq( active ) ); if ( active === -1 ) { - active = options.collapsible ? false : 0; + active = collapsible ? false : 0; } } - options.active = active; // don't allow collapsible: false and active: false - if ( !options.collapsible && options.active === false && this.anchors.length ) { - options.active = 0; - } - - // Take disabling tabs via class attribute from HTML - // into account and update option properly. - if ( $.isArray( options.disabled ) ) { - options.disabled = $.unique( options.disabled.concat( - $.map( this.tabs.filter( ".ui-state-disabled" ), function( li ) { - return that.tabs.index( li ); - }) - ) ).sort(); + if ( !collapsible && active === false && this.anchors.length ) { + active = 0; } - // check for length avoids error when initializing empty list - if ( this.options.active !== false && this.anchors.length ) { - this.active = this._findActive( this.options.active ); - } else { - this.active = $(); - } - - this._refresh(); - - if ( this.active.length ) { - this.load( options.active ); - } + return active; }, _getCreateEventData: function() { @@ -144,6 +150,7 @@ $.widget( "ui.tabs", { }, _tabKeydown: function( event ) { + /*jshint maxcomplexity:15*/ var focusedTab = $( this.document[0].activeElement ).closest( "li" ), selectedIndex = this.tabs.index( focusedTab ), goingForward = true; -- cgit v1.2.3 From b239298946b466a0c87a0c1ead4ccd75141ed740 Mon Sep 17 00:00:00 2001 From: Scott González Date: Thu, 6 Dec 2012 14:25:48 -0500 Subject: Allow higher cyclomatic complexity in functions that sanely use switch statements. --- ui/jquery.ui.accordion.js | 1 + ui/jquery.ui.autocomplete.js | 1 + ui/jquery.ui.dialog.js | 1 + ui/jquery.ui.menu.js | 1 + ui/jquery.ui.slider.js | 1 + 5 files changed, 5 insertions(+) (limited to 'ui') diff --git a/ui/jquery.ui.accordion.js b/ui/jquery.ui.accordion.js index 7914f7c5f..60475b8ba 100644 --- a/ui/jquery.ui.accordion.js +++ b/ui/jquery.ui.accordion.js @@ -166,6 +166,7 @@ $.widget( "ui.accordion", { }, _keydown: function( event ) { + /*jshint maxcomplexity:15*/ if ( event.altKey || event.ctrlKey ) { return; } diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index 5edb84d44..c049b8569 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -66,6 +66,7 @@ $.widget( "ui.autocomplete", { this._on( this.element, { keydown: function( event ) { + /*jshint maxcomplexity:15*/ if ( this.element.prop( "readOnly" ) ) { suppressKeyPress = true; suppressInput = true; diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index eac818fe0..b2b8be8c0 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -553,6 +553,7 @@ $.widget("ui.dialog", { }, _setOption: function( key, value ) { + /*jshint maxcomplexity:15*/ var isDraggable, isResizable, uiDialog = this.uiDialog; diff --git a/ui/jquery.ui.menu.js b/ui/jquery.ui.menu.js index 45c1ec2e4..41a69c472 100644 --- a/ui/jquery.ui.menu.js +++ b/ui/jquery.ui.menu.js @@ -173,6 +173,7 @@ $.widget( "ui.menu", { }, _keydown: function( event ) { + /*jshint maxcomplexity:20*/ var match, prev, character, skip, regex, preventDefault = true; diff --git a/ui/jquery.ui.slider.js b/ui/jquery.ui.slider.js index d9fc1b132..02fee8364 100644 --- a/ui/jquery.ui.slider.js +++ b/ui/jquery.ui.slider.js @@ -119,6 +119,7 @@ $.widget( "ui.slider", $.ui.mouse, { this._on( this.handles, { keydown: function( event ) { + /*jshint maxcomplexity:25*/ var allowed, curVal, newVal, step, index = $( event.target ).data( "ui-slider-handle-index" ); -- cgit v1.2.3 From 3ec0c2e5728da9b9b9955dfe18073d3985e61a52 Mon Sep 17 00:00:00 2001 From: Scott González Date: Thu, 6 Dec 2012 14:42:10 -0500 Subject: Core: Removed $.ui.isOver() and $.ui.isOverAxis(). Fixes #8891 - Remove $.ui.isOver() and $.ui.isOverAxis(). --- ui/jquery.ui.core.js | 10 ---------- ui/jquery.ui.droppable.js | 6 +++++- ui/jquery.ui.sortable.js | 12 ++++++++---- 3 files changed, 13 insertions(+), 15 deletions(-) (limited to 'ui') diff --git a/ui/jquery.ui.core.js b/ui/jquery.ui.core.js index 288634376..17fad86b4 100644 --- a/ui/jquery.ui.core.js +++ b/ui/jquery.ui.core.js @@ -313,16 +313,6 @@ $.extend( $.ui, { has = ( el[ scroll ] > 0 ); el[ scroll ] = 0; return has; - }, - - // these are odd functions, fix the API or move into individual plugins - isOverAxis: function( x, reference, size ) { - //Determines when x coordinate is over "b" element axis - return ( x > reference ) && ( x < ( reference + size ) ); - }, - isOver: function( y, x, top, left, height, width ) { - //Determines when x, y coordinates is over "b" element - return $.ui.isOverAxis( y, top, height ) && $.ui.isOverAxis( x, left, width ); } }); diff --git a/ui/jquery.ui.droppable.js b/ui/jquery.ui.droppable.js index 9d904992d..aebca8fae 100644 --- a/ui/jquery.ui.droppable.js +++ b/ui/jquery.ui.droppable.js @@ -16,6 +16,10 @@ */ (function( $, undefined ) { +function isOverAxis( x, reference, size ) { + return ( x > reference ) && ( x < ( reference + size ) ); +} + $.widget("ui.droppable", { version: "@VERSION", widgetEventPrefix: "drop", @@ -203,7 +207,7 @@ $.ui.intersect = function(draggable, droppable, toleranceMode) { case 'pointer': draggableLeft = ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left); draggableTop = ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top); - return $.ui.isOver(draggableTop, draggableLeft, t, l, droppable.proportions.height, droppable.proportions.width); + return isOverAxis( draggableTop, t, droppable.proportions.height ) && isOverAxis( draggableLeft, l, droppable.proportions.width ) case 'touch': return ( (y1 >= t && y1 <= b) || // Top edge touching diff --git a/ui/jquery.ui.sortable.js b/ui/jquery.ui.sortable.js index b1fb642fe..e142a0ede 100644 --- a/ui/jquery.ui.sortable.js +++ b/ui/jquery.ui.sortable.js @@ -17,6 +17,10 @@ /*jshint loopfunc: true */ +function isOverAxis( x, reference, size ) { + return ( x > reference ) && ( x < ( reference + size ) ); +} + $.widget("ui.sortable", $.ui.mouse, { version: "@VERSION", widgetEventPrefix: "sort", @@ -536,8 +540,8 @@ $.widget("ui.sortable", $.ui.mouse, { _intersectsWithPointer: function(item) { - var isOverElementHeight = (this.options.axis === 'x') || $.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height), - isOverElementWidth = (this.options.axis === 'y') || $.ui.isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width), + var isOverElementHeight = (this.options.axis === 'x') || isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height), + isOverElementWidth = (this.options.axis === 'y') || isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width), isOverElement = isOverElementHeight && isOverElementWidth, verticalDirection = this._getDragVerticalDirection(), horizontalDirection = this._getDragHorizontalDirection(); @@ -554,8 +558,8 @@ $.widget("ui.sortable", $.ui.mouse, { _intersectsWithSides: function(item) { - var isOverBottomHalf = $.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height/2), item.height), - isOverRightHalf = $.ui.isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width), + var isOverBottomHalf = isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height/2), item.height), + isOverRightHalf = isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width), verticalDirection = this._getDragVerticalDirection(), horizontalDirection = this._getDragHorizontalDirection(); -- cgit v1.2.3 From fb38c20763c637e4d05ca2a48e25db4b380754be Mon Sep 17 00:00:00 2001 From: Scott González Date: Thu, 6 Dec 2012 14:43:35 -0500 Subject: Droppable: Added missing semicolon. --- ui/jquery.ui.droppable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/jquery.ui.droppable.js b/ui/jquery.ui.droppable.js index aebca8fae..e2da0b9f6 100644 --- a/ui/jquery.ui.droppable.js +++ b/ui/jquery.ui.droppable.js @@ -207,7 +207,7 @@ $.ui.intersect = function(draggable, droppable, toleranceMode) { case 'pointer': draggableLeft = ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left); draggableTop = ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top); - return isOverAxis( draggableTop, t, droppable.proportions.height ) && isOverAxis( draggableLeft, l, droppable.proportions.width ) + return isOverAxis( draggableTop, t, droppable.proportions.height ) && isOverAxis( draggableLeft, l, droppable.proportions.width ); case 'touch': return ( (y1 >= t && y1 <= b) || // Top edge touching -- cgit v1.2.3 From a1eb9ca4befdabace88fc78aa59947dbf7c36e20 Mon Sep 17 00:00:00 2001 From: Scott González Date: Thu, 6 Dec 2012 15:00:42 -0500 Subject: Position: Split out dimension parsing. --- ui/jquery.ui.position.js | 54 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 17 deletions(-) (limited to 'ui') diff --git a/ui/jquery.ui.position.js b/ui/jquery.ui.position.js index a5dc31834..dbfadedd1 100644 --- a/ui/jquery.ui.position.js +++ b/ui/jquery.ui.position.js @@ -29,10 +29,41 @@ function getOffsets( offsets, width, height ) { parseInt( offsets[ 1 ], 10 ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 ) ]; } + function parseCss( element, property ) { return parseInt( $.css( element, property ), 10 ) || 0; } +function getDimensions( elem ) { + var raw = elem[0]; + if ( raw.nodeType === 9 ) { + return { + width: elem.width(), + height: elem.height(), + offset: { top: 0, left: 0 } + }; + } + if ( $.isWindow( raw ) ) { + return { + width: elem.width(), + height: elem.height(), + offset: { top: elem.scrollTop(), left: elem.scrollLeft() } + }; + } + if ( raw.preventDefault ) { + return { + width: 0, + height: 0, + offset: { top: raw.pageY, left: raw.pageX } + }; + } + return { + width: elem.outerWidth(), + height: elem.outerHeight(), + offset: elem.offset() + }; +} + $.position = { scrollbarWidth: function() { if ( cachedScrollbarWidth !== undefined ) { @@ -91,32 +122,21 @@ $.fn.position = function( options ) { // make a copy, we don't want to modify arguments options = $.extend( {}, options ); - var atOffset, targetWidth, targetHeight, targetOffset, basePosition, + var atOffset, targetWidth, targetHeight, targetOffset, basePosition, dimensions, target = $( options.of ), within = $.position.getWithinInfo( options.within ), scrollInfo = $.position.getScrollInfo( within ), - targetElem = target[0], collision = ( options.collision || "flip" ).split( " " ), offsets = {}; - if ( targetElem.nodeType === 9 ) { - targetWidth = target.width(); - targetHeight = target.height(); - targetOffset = { top: 0, left: 0 }; - } else if ( $.isWindow( targetElem ) ) { - targetWidth = target.width(); - targetHeight = target.height(); - targetOffset = { top: target.scrollTop(), left: target.scrollLeft() }; - } else if ( targetElem.preventDefault ) { + dimensions = getDimensions( target ); + if ( target[0].preventDefault ) { // force left top to allow flipping options.at = "left top"; - targetWidth = targetHeight = 0; - targetOffset = { top: targetElem.pageY, left: targetElem.pageX }; - } else { - targetWidth = target.outerWidth(); - targetHeight = target.outerHeight(); - targetOffset = target.offset(); } + targetWidth = dimensions.width; + targetHeight = dimensions.height; + targetOffset = dimensions.offset; // clone to reuse original targetOffset later basePosition = $.extend( {}, targetOffset ); -- cgit v1.2.3 From da17a232ca554254eabd3583805b381f6b525ec5 Mon Sep 17 00:00:00 2001 From: Scott González Date: Fri, 7 Dec 2012 11:58:58 -0500 Subject: Autocomplete: Handle detached elements for appendTo after create. --- tests/unit/autocomplete/autocomplete_options.js | 6 +++++- ui/jquery.ui.autocomplete.js | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'ui') diff --git a/tests/unit/autocomplete/autocomplete_options.js b/tests/unit/autocomplete/autocomplete_options.js index d3a25d2fc..913f5bc28 100644 --- a/tests/unit/autocomplete/autocomplete_options.js +++ b/tests/unit/autocomplete/autocomplete_options.js @@ -5,7 +5,7 @@ module( "autocomplete: options" ); var data = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl" ]; test( "appendTo", function() { - expect( 7 ); + expect( 8 ); var detached = $( "
    " ), element = $( "#autocomplete" ).autocomplete(); equal( element.autocomplete( "widget" ).parent()[0], document.body, "defaults to body" ); @@ -39,6 +39,10 @@ test( "appendTo", function() { }); equal( element.autocomplete( "widget" ).parent()[0], detached[0], "detached DOM element" ); element.autocomplete( "destroy" ); + + element.autocomplete().autocomplete( "option", "appendTo", detached ); + equal( element.autocomplete( "widget" ).parent()[0], detached[0], "detached DOM element via option()" ); + element.autocomplete( "destroy" ); }); function autoFocusTest( afValue, focusedLength ) { diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index c049b8569..a858b3382 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -314,7 +314,7 @@ $.widget( "ui.autocomplete", { this._initSource(); } if ( key === "appendTo" ) { - this.menu.element.appendTo( this.document.find( value || "body" )[0] ); + this.menu.element.appendTo( this._appendTo() ); } if ( key === "disabled" && value && this.xhr ) { this.xhr.abort(); -- cgit v1.2.3 From 70b16ef445d8f9947fd414894d97673706ee8c6f Mon Sep 17 00:00:00 2001 From: Scott González Date: Fri, 7 Dec 2012 14:54:21 -0500 Subject: Dialog: Added appendTo option. Fixes #7948 - Dialog: Allow dialog to be attached to a element other than body. --- tests/unit/dialog/dialog.html | 2 ++ tests/unit/dialog/dialog_common.js | 1 + tests/unit/dialog/dialog_options.js | 41 +++++++++++++++++++++++++++++++++++++ ui/jquery.ui.dialog.js | 15 +++++++++++++- 4 files changed, 58 insertions(+), 1 deletion(-) (limited to 'ui') diff --git a/tests/unit/dialog/dialog.html b/tests/unit/dialog/dialog.html index cdc846478..8f2583ce1 100644 --- a/tests/unit/dialog/dialog.html +++ b/tests/unit/dialog/dialog.html @@ -61,6 +61,8 @@
    +
    +
    diff --git a/tests/unit/dialog/dialog_common.js b/tests/unit/dialog/dialog_common.js index 47fff1013..9657a9887 100644 --- a/tests/unit/dialog/dialog_common.js +++ b/tests/unit/dialog/dialog_common.js @@ -1,5 +1,6 @@ TestHelpers.commonWidgetTests( "dialog", { defaults: { + appendTo: "body", autoOpen: true, buttons: {}, closeOnEscape: true, diff --git a/tests/unit/dialog/dialog_options.js b/tests/unit/dialog/dialog_options.js index fd7d91827..19e69b29a 100644 --- a/tests/unit/dialog/dialog_options.js +++ b/tests/unit/dialog/dialog_options.js @@ -5,6 +5,47 @@ module("dialog: options"); +test( "appendTo", function() { + expect( 8 ); + var detached = $( "
    " ), + element = $( "#dialog1" ).dialog(); + equal( element.dialog( "widget" ).parent()[0], document.body, "defaults to body" ); + element.dialog( "destroy" ); + + element.dialog({ + appendTo: ".wrap" + }); + equal( element.dialog( "widget" ).parent()[0], $( "#wrap1" )[0], "first found element" ); + equal( $( "#wrap2 .ui-dialog" ).length, 0, "only appends to one element" ); + element.dialog( "destroy" ); + + element.dialog({ + appendTo: null + }); + equal( element.dialog( "widget" ).parent()[0], document.body, "null" ); + element.dialog( "destroy" ); + + element.dialog({ autoOpen: false }).dialog( "option", "appendTo", "#wrap1" ).dialog( "open" ); + equal( element.dialog( "widget" ).parent()[0], $( "#wrap1" )[0], "modified after init" ); + element.dialog( "destroy" ); + + element.dialog({ + appendTo: detached + }); + equal( element.dialog( "widget" ).parent()[0], detached[0], "detached jQuery object" ); + element.dialog( "destroy" ); + + element.dialog({ + appendTo: detached[0] + }); + equal( element.dialog( "widget" ).parent()[0], detached[0], "detached DOM element" ); + element.dialog( "destroy" ); + + element.dialog({ autoOpen: false }).dialog( "option", "appendTo", detached ); + equal( element.dialog( "widget" ).parent()[0], detached[0], "detached DOM element via option()" ); + element.dialog( "destroy" ); +}); + test("autoOpen", function() { expect(2); diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index b2b8be8c0..939571a68 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -39,6 +39,7 @@ var uiDialogClasses = "ui-dialog ui-widget ui-widget-content ui-corner-all ui-fr $.widget("ui.dialog", { version: "@VERSION", options: { + appendTo: "body", autoOpen: true, buttons: {}, closeOnEscape: true, @@ -124,6 +125,14 @@ $.widget("ui.dialog", { } }, + _appendTo: function() { + var element = this.options.appendTo; + if ( element && (element.jquery || element.nodeType) ) { + return $( element ); + } + return this.document.find( element || "body" ).eq( 0 ); + }, + _destroy: function() { var next, oldPosition = this.oldPosition; @@ -276,7 +285,7 @@ $.widget("ui.dialog", { tabIndex: -1, role: "dialog" }) - .appendTo( this.document[ 0 ].body ); + .appendTo( this._appendTo() ); this._on( this.uiDialog, { keydown: function( event ) { @@ -569,6 +578,10 @@ $.widget("ui.dialog", { this._super( key, value ); + if ( key === "appendTo" ) { + this.uiDialog.appendTo( this._appendTo() ); + } + if ( key === "buttons" ) { this._createButtons(); } -- cgit v1.2.3 From d4551bc3b8dfbfd925700dcb9f71e7729b125889 Mon Sep 17 00:00:00 2001 From: Scott González Date: Fri, 7 Dec 2012 16:57:03 -0500 Subject: Dialog: Respect maxHeight when determining size on open. Fixes #4820 - Dialog: Auto height does not respect the maxHeight option. --- tests/unit/dialog/dialog_common.js | 4 ++-- ui/jquery.ui.dialog.js | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'ui') diff --git a/tests/unit/dialog/dialog_common.js b/tests/unit/dialog/dialog_common.js index 9657a9887..1a9b4e109 100644 --- a/tests/unit/dialog/dialog_common.js +++ b/tests/unit/dialog/dialog_common.js @@ -10,8 +10,8 @@ TestHelpers.commonWidgetTests( "dialog", { draggable: true, height: 'auto', hide: null, - maxHeight: false, - maxWidth: false, + maxHeight: null, + maxWidth: null, minHeight: 150, minWidth: 150, modal: false, diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index 939571a68..2553109ba 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -48,8 +48,8 @@ $.widget("ui.dialog", { draggable: true, hide: null, height: "auto", - maxHeight: false, - maxWidth: false, + maxHeight: null, + maxWidth: null, minHeight: 150, minWidth: 150, modal: false, @@ -89,6 +89,7 @@ $.widget("ui.dialog", { display: this.element[0].style.display, width: this.element[0].style.width, minHeight: this.element[0].style.minHeight, + maxHeight: this.element[0].style.maxHeight, height: this.element[0].style.height }; this.originalTitle = this.element.attr( "title" ); @@ -632,16 +633,16 @@ $.widget("ui.dialog", { }, _size: function() { - // If the user has resized the dialog, the .ui-dialog and .ui-dialog-content // divs will both have width and height set, so we need to reset them - var nonContentHeight, minContentHeight, + var nonContentHeight, minContentHeight, maxContentHeight, options = this.options; // reset content sizing this.element.show().css({ width: "auto", minHeight: 0, + maxHeight: "none", height: 0 }); @@ -657,14 +658,18 @@ $.widget("ui.dialog", { }) .outerHeight(); minContentHeight = Math.max( 0, options.minHeight - nonContentHeight ); + maxContentHeight = typeof options.maxHeight === "number" ? + Math.max( 0, options.maxHeight - nonContentHeight ) : + "none"; if ( options.height === "auto" ) { this.element.css({ minHeight: minContentHeight, + maxHeight: maxContentHeight, height: "auto" }); } else { - this.element.height( Math.max( options.height - nonContentHeight, 0 ) ); + this.element.height( Math.max( 0, options.height - nonContentHeight ) ); } if (this.uiDialog.is( ":data(ui-resizable)" ) ) { -- cgit v1.2.3 From b9f206dbcf7f8b9c190e86f0974ad2003911b668 Mon Sep 17 00:00:00 2001 From: Scott González Date: Tue, 11 Dec 2012 16:23:18 -0500 Subject: Dialog: Cleanup. --- tests/unit/dialog/dialog_common.js | 2 +- ui/jquery.ui.dialog.js | 190 ++++++++++++++++++------------------- 2 files changed, 92 insertions(+), 100 deletions(-) (limited to 'ui') diff --git a/tests/unit/dialog/dialog_common.js b/tests/unit/dialog/dialog_common.js index 1a9b4e109..57d7aa0aa 100644 --- a/tests/unit/dialog/dialog_common.js +++ b/tests/unit/dialog/dialog_common.js @@ -2,7 +2,7 @@ TestHelpers.commonWidgetTests( "dialog", { defaults: { appendTo: "body", autoOpen: true, - buttons: {}, + buttons: [], closeOnEscape: true, closeText: 'close', disabled: false, diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index 2553109ba..2c7c6b57a 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -19,8 +19,7 @@ */ (function( $, undefined ) { -var uiDialogClasses = "ui-dialog ui-widget ui-widget-content ui-corner-all ui-front ", - sizeRelatedOptions = { +var sizeRelatedOptions = { buttons: true, height: true, maxHeight: true, @@ -36,12 +35,12 @@ var uiDialogClasses = "ui-dialog ui-widget ui-widget-content ui-corner-all ui-fr minWidth: true }; -$.widget("ui.dialog", { +$.widget( "ui.dialog", { version: "@VERSION", options: { appendTo: "body", autoOpen: true, - buttons: {}, + buttons: [], closeOnEscape: true, closeText: "close", dialogClass: "", @@ -58,7 +57,7 @@ $.widget("ui.dialog", { at: "center", of: window, collision: "fit", - // ensure that the titlebar is never outside the document + // Ensure the titlebar is always visible using: function( pos ) { var topOffset = $( this ).css( pos ).offset().top; if ( topOffset < 0 ) { @@ -92,12 +91,12 @@ $.widget("ui.dialog", { maxHeight: this.element[0].style.maxHeight, height: this.element[0].style.height }; - this.originalTitle = this.element.attr( "title" ); - this.options.title = this.options.title || this.originalTitle; - this.oldPosition = { + this.originalPosition = { parent: this.element.parent(), index: this.element.parent().children().index( this.element ) }; + this.originalTitle = this.element.attr( "title" ); + this.options.title = this.options.title || this.originalTitle; this._createWrapper(); @@ -136,7 +135,7 @@ $.widget("ui.dialog", { _destroy: function() { var next, - oldPosition = this.oldPosition; + originalPosition = this.originalPosition; this._destroyOverlay(); @@ -144,7 +143,7 @@ $.widget("ui.dialog", { .removeUniqueId() .removeClass( "ui-dialog-content ui-widget-content" ) .css( this.originalCss ) - // without detaching first, the following becomes really slow + // Without detaching first, the following becomes really slow .detach(); this.uiDialog.stop( true, true ).remove(); @@ -153,12 +152,12 @@ $.widget("ui.dialog", { this.element.attr( "title", this.originalTitle ); } - next = oldPosition.parent.children().eq( oldPosition.index ); + next = originalPosition.parent.children().eq( originalPosition.index ); // Don't try to place the dialog next to itself (#8613) if ( next.length && next[ 0 ] !== this.element[ 0 ] ) { next.before( this.element ); } else { - oldPosition.parent.append( this.element ); + originalPosition.parent.append( this.element ); } }, @@ -172,16 +171,11 @@ $.widget("ui.dialog", { close: function( event ) { var that = this; - if ( !this._isOpen ) { - return; - } - - if ( this._trigger( "beforeClose", event ) === false ) { + if ( !this._isOpen || this._trigger( "beforeClose", event ) === false ) { return; } this._isOpen = false; - this._destroyOverlay(); if ( !this.opener.filter( ":focusable" ).focus().length ) { @@ -206,7 +200,7 @@ $.widget("ui.dialog", { _moveToTop: function( event, silent ) { var moved = !!this.uiDialog.nextAll( ":visible" ).insertBefore( this.uiDialog ).length; - if ( !silent && moved ) { + if ( moved && !silent ) { this._trigger( "focus", event ); } return moved; @@ -233,29 +227,27 @@ $.widget("ui.dialog", { this._isOpen = true; this._trigger( "open" ); this._trigger( "focus" ); - - return this; }, _focusTabbable: function() { - // 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 + // 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.element.find( ":tabbable" ); - if ( !hasFocus.length ) { - hasFocus = this.uiDialogButtonPane.find( ":tabbable" ); - if ( !hasFocus.length ) { - hasFocus = this.uiDialogTitlebarClose.filter( ":tabbable" ); - if ( !hasFocus.length ) { - hasFocus = this.uiDialog; - } - } - } + } + if ( !hasFocus.length ) { + hasFocus = this.uiDialogButtonPane.find( ":tabbable" ); + } + if ( !hasFocus.length ) { + hasFocus = this.uiDialogTitlebarClose.filter( ":tabbable" ); + } + if ( !hasFocus.length ) { + hasFocus = this.uiDialog; } hasFocus.eq( 0 ).focus(); }, @@ -279,10 +271,11 @@ $.widget("ui.dialog", { _createWrapper: function() { this.uiDialog = $( "
    " ) - .addClass( uiDialogClasses + this.options.dialogClass ) + .addClass( "ui-dialog ui-widget ui-widget-content ui-corner-all ui-front " + + this.options.dialogClass ) .hide() .attr({ - // setting tabIndex makes the div focusable + // Setting tabIndex makes the div focusable tabIndex: -1, role: "dialog" }) @@ -307,10 +300,10 @@ $.widget("ui.dialog", { if ( ( event.target === last[ 0 ] || event.target === this.uiDialog[ 0 ] ) && !event.shiftKey ) { first.focus( 1 ); - return false; + event.preventDefault(); } else if ( ( event.target === first[ 0 ] || event.target === this.uiDialog[ 0 ] ) && event.shiftKey ) { last.focus( 1 ); - return false; + event.preventDefault(); } }, mousedown: function( event ) { @@ -334,7 +327,7 @@ $.widget("ui.dialog", { var uiDialogTitle; this.uiDialogTitlebar = $( "
    " ) - .addClass( "ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix" ) + .addClass( "ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix" ) .prependTo( this.uiDialog ); this._on( this.uiDialogTitlebar, { mousedown: function( event ) { @@ -359,7 +352,7 @@ $.widget("ui.dialog", { .addClass( "ui-dialog-titlebar-close" ) .appendTo( this.uiDialogTitlebar ); this._on( this.uiDialogTitlebarClose, { - "click": function( event ) { + click: function( event ) { event.preventDefault(); this.close( event ); } @@ -384,12 +377,12 @@ $.widget("ui.dialog", { }, _createButtonPane: function() { - var uiDialogButtonPane = ( this.uiDialogButtonPane = $( "
    " ) ) + this.uiDialogButtonPane = $( "
    " ) .addClass( "ui-dialog-buttonpane ui-widget-content ui-helper-clearfix" ); this.uiButtonSet = $( "
    " ) .addClass( "ui-dialog-buttonset" ) - .appendTo( uiDialogButtonPane ); + .appendTo( this.uiDialogButtonPane ); this._createButtons(); }, @@ -402,34 +395,35 @@ $.widget("ui.dialog", { this.uiDialogButtonPane.remove(); this.uiButtonSet.empty(); - if ( !$.isEmptyObject( buttons ) ) { - $.each( buttons, function( name, props ) { - var click, buttonOptions; - props = $.isFunction( props ) ? - { click: props, text: name } : - props; - // Default to a non-submitting button - props = $.extend( { type: "button" }, props ); - // Change the context for the click callback to be the main element - click = props.click; - props.click = function() { - click.apply( that.element[0], arguments ); - }; - buttonOptions = { - icons: props.icons, - text: props.showText - }; - delete props.icons; - delete props.showText; - $( "", props ) - .button( buttonOptions ) - .appendTo( that.uiButtonSet ); - }); - this.uiDialog.addClass( "ui-dialog-buttons" ); - this.uiDialogButtonPane.appendTo( this.uiDialog ); - } else { + if ( $.isEmptyObject( buttons ) ) { this.uiDialog.removeClass( "ui-dialog-buttons" ); + return; } + + $.each( buttons, function( name, props ) { + var click, buttonOptions; + props = $.isFunction( props ) ? + { click: props, text: name } : + props; + // Default to a non-submitting button + props = $.extend( { type: "button" }, props ); + // Change the context for the click callback to be the main element + click = props.click; + props.click = function() { + click.apply( that.element[0], arguments ); + }; + buttonOptions = { + icons: props.icons, + text: props.showText + }; + delete props.icons; + delete props.showText; + $( "", props ) + .button( buttonOptions ) + .appendTo( that.uiButtonSet ); + }); + this.uiDialog.addClass( "ui-dialog-buttons" ); + this.uiDialogButtonPane.appendTo( this.uiDialog ); }, _makeDraggable: function() { @@ -448,8 +442,7 @@ $.widget("ui.dialog", { handle: ".ui-dialog-titlebar", containment: "document", start: function( event, ui ) { - $( this ) - .addClass( "ui-dialog-dragging" ); + $( this ).addClass( "ui-dialog-dragging" ); that._trigger( "dragStart", event, filteredUi( ui ) ); }, drag: function( event, ui ) { @@ -460,8 +453,7 @@ $.widget("ui.dialog", { ui.position.left - that.document.scrollLeft(), ui.position.top - that.document.scrollTop() ]; - $( this ) - .removeClass( "ui-dialog-dragging" ); + $( this ).removeClass( "ui-dialog-dragging" ); that._trigger( "dragStop", event, filteredUi( ui ) ); } }); @@ -510,23 +502,19 @@ $.widget("ui.dialog", { that._trigger( "resizeStop", event, filteredUi( ui ) ); } }) - .css( "position", position ) - .find( ".ui-resizable-se" ) - .addClass( "ui-icon ui-icon-grip-diagonal-se" ); + .css( "position", position ); }, _minHeight: function() { var options = this.options; - if ( options.height === "auto" ) { - return options.minHeight; - } else { - return Math.min( options.minHeight, options.height ); - } + return options.height === "auto" ? + options.minHeight : + Math.min( options.minHeight, options.height ); }, _position: function() { - // need to show the dialog to get the actual offset in the position plugin + // Need to show the dialog to get the actual offset in the position plugin var isVisible = this.uiDialog.is( ":visible" ); if ( !isVisible ) { this.uiDialog.show(); @@ -539,8 +527,8 @@ $.widget("ui.dialog", { _setOptions: function( options ) { var that = this, - resizableOptions = {}, - resize = false; + resize = false, + resizableOptions = {}; $.each( options, function( key, value ) { that._setOption( key, value ); @@ -589,7 +577,7 @@ $.widget("ui.dialog", { if ( key === "closeText" ) { this.uiDialogTitlebarClose.button({ - // ensure that we always pass a string + // Ensure that we always pass a string label: "" + value }); } @@ -638,7 +626,7 @@ $.widget("ui.dialog", { var nonContentHeight, minContentHeight, maxContentHeight, options = this.options; - // reset content sizing + // Reset content sizing this.element.show().css({ width: "auto", minHeight: 0, @@ -681,18 +669,20 @@ $.widget("ui.dialog", { if ( !this.options.modal ) { return; } - if ( $.ui.dialog.overlayInstances === 0 ) { - // prevent use of anchors and inputs - // we use a setTimeout in case the overlay is created from an - // event that we're going to be cancelling (see #2804) + + if ( !$.ui.dialog.overlayInstances ) { + // Prevent use of anchors and inputs. + // We use a delay in case the overlay is created from an + // event that we're going to be cancelling. (#2804) this._delay(function() { - // handle $(el).dialog().dialog('close') (see #4065) + // Handle .dialog().dialog("close") (#4065) if ( $.ui.dialog.overlayInstances ) { this._on( this.document, { focusin: function( event ) { if ( !$( event.target ).closest( ".ui-dialog").length ) { event.preventDefault(); - $( ".ui-dialog:visible:last .ui-dialog-content" ).data( "ui-dialog" )._focusTabbable(); + $( ".ui-dialog:visible:last .ui-dialog-content" ) + .data( "ui-dialog" )._focusTabbable(); } } }); @@ -700,20 +690,22 @@ $.widget("ui.dialog", { }); } - var $el = this.overlay = $( "
    " ).addClass( "ui-widget-overlay ui-front" ); - $el.appendTo( this.document[ 0 ].body ); - this._on( $el, { + this.overlay = $( "
    " ) + .addClass( "ui-widget-overlay ui-front" ) + .appendTo( this.document[ 0 ].body ); + this._on( this.overlay, { mousedown: "_keepFocus" }); - $.ui.dialog.overlayInstances += 1; + $.ui.dialog.overlayInstances++; }, _destroyOverlay: function() { if ( !this.options.modal ) { return; } - $.ui.dialog.overlayInstances -= 1; - if ( $.ui.dialog.overlayInstances === 0 ) { + + $.ui.dialog.overlayInstances--; + if ( !$.ui.dialog.overlayInstances ) { this._off( this.document, "focusin" ); } this.overlay.remove(); -- cgit v1.2.3 From 0f111a2ac41d5851f14fa4c4bbf2f884ba268074 Mon Sep 17 00:00:00 2001 From: Scott González Date: Wed, 12 Dec 2012 08:47:05 -0500 Subject: Dialog: Spacing. --- ui/jquery.ui.dialog.js | 128 ++++++++++++++++++++++++------------------------- 1 file changed, 64 insertions(+), 64 deletions(-) (limited to 'ui') diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index 2c7c6b57a..26989959e 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -95,15 +95,15 @@ $.widget( "ui.dialog", { parent: this.element.parent(), index: this.element.parent().children().index( this.element ) }; - this.originalTitle = this.element.attr( "title" ); + this.originalTitle = this.element.attr("title"); this.options.title = this.options.title || this.originalTitle; this._createWrapper(); this.element .show() - .removeAttr( "title" ) - .addClass( "ui-dialog-content ui-widget-content" ) + .removeAttr("title") + .addClass("ui-dialog-content ui-widget-content") .appendTo( this.uiDialog ); this._createTitlebar(); @@ -141,7 +141,7 @@ $.widget( "ui.dialog", { this.element .removeUniqueId() - .removeClass( "ui-dialog-content ui-widget-content" ) + .removeClass("ui-dialog-content ui-widget-content") .css( this.originalCss ) // Without detaching first, the following becomes really slow .detach(); @@ -154,7 +154,7 @@ $.widget( "ui.dialog", { next = originalPosition.parent.children().eq( originalPosition.index ); // Don't try to place the dialog next to itself (#8613) - if ( next.length && next[ 0 ] !== this.element[ 0 ] ) { + if ( next.length && next[0] !== this.element[0] ) { next.before( this.element ); } else { originalPosition.parent.append( this.element ); @@ -178,11 +178,11 @@ $.widget( "ui.dialog", { this._isOpen = false; this._destroyOverlay(); - if ( !this.opener.filter( ":focusable" ).focus().length ) { + if ( !this.opener.filter(":focusable").focus().length ) { // Hiding a focused element doesn't trigger blur in WebKit // so in case we have nothing to focus on, explicitly blur the active element // https://bugs.webkit.org/show_bug.cgi?id=47182 - $( this.document[ 0 ].activeElement ).blur(); + $( this.document[0].activeElement ).blur(); } this._hide( this.uiDialog, this.options.hide, function() { @@ -199,7 +199,7 @@ $.widget( "ui.dialog", { }, _moveToTop: function( event, silent ) { - var moved = !!this.uiDialog.nextAll( ":visible" ).insertBefore( this.uiDialog ).length; + var moved = !!this.uiDialog.nextAll(":visible").insertBefore( this.uiDialog ).length; if ( moved && !silent ) { this._trigger( "focus", event ); } @@ -214,7 +214,7 @@ $.widget( "ui.dialog", { return; } - this.opener = $( this.document[ 0 ].activeElement ); + this.opener = $( this.document[0].activeElement ); this._size(); this._position(); @@ -225,8 +225,8 @@ $.widget( "ui.dialog", { this._focusTabbable(); this._isOpen = true; - this._trigger( "open" ); - this._trigger( "focus" ); + this._trigger("open"); + this._trigger("focus"); }, _focusTabbable: function() { @@ -236,15 +236,15 @@ $.widget( "ui.dialog", { // 3. Tabbable element inside the buttonpane // 4. The close button // 5. The dialog itself - var hasFocus = this.element.find( "[autofocus]" ); + var hasFocus = this.element.find("[autofocus]"); if ( !hasFocus.length ) { - hasFocus = this.element.find( ":tabbable" ); + hasFocus = this.element.find(":tabbable"); } if ( !hasFocus.length ) { - hasFocus = this.uiDialogButtonPane.find( ":tabbable" ); + hasFocus = this.uiDialogButtonPane.find(":tabbable"); } if ( !hasFocus.length ) { - hasFocus = this.uiDialogTitlebarClose.filter( ":tabbable" ); + hasFocus = this.uiDialogTitlebarClose.filter(":tabbable"); } if ( !hasFocus.length ) { hasFocus = this.uiDialog; @@ -254,9 +254,9 @@ $.widget( "ui.dialog", { _keepFocus: function( event ) { function checkFocus() { - var activeElement = this.document[ 0 ].activeElement, - isActive = this.uiDialog[ 0 ] === activeElement || - $.contains( this.uiDialog[ 0 ], activeElement ); + var activeElement = this.document[0].activeElement, + isActive = this.uiDialog[0] === activeElement || + $.contains( this.uiDialog[0], activeElement ); if ( !isActive ) { this._focusTabbable(); } @@ -270,7 +270,7 @@ $.widget( "ui.dialog", { }, _createWrapper: function() { - this.uiDialog = $( "
    " ) + this.uiDialog = $("
    ") .addClass( "ui-dialog ui-widget ui-widget-content ui-corner-all ui-front " + this.options.dialogClass ) .hide() @@ -294,14 +294,14 @@ $.widget( "ui.dialog", { if ( event.keyCode !== $.ui.keyCode.TAB ) { return; } - var tabbables = this.uiDialog.find( ":tabbable" ), - first = tabbables.filter( ":first" ), - last = tabbables.filter( ":last" ); + var tabbables = this.uiDialog.find(":tabbable"), + first = tabbables.filter(":first"), + last = tabbables.filter(":last"); - if ( ( event.target === last[ 0 ] || event.target === this.uiDialog[ 0 ] ) && !event.shiftKey ) { + if ( ( event.target === last[0] || event.target === this.uiDialog[0] ) && !event.shiftKey ) { first.focus( 1 ); event.preventDefault(); - } else if ( ( event.target === first[ 0 ] || event.target === this.uiDialog[ 0 ] ) && event.shiftKey ) { + } else if ( ( event.target === first[0] || event.target === this.uiDialog[0] ) && event.shiftKey ) { last.focus( 1 ); event.preventDefault(); } @@ -316,9 +316,9 @@ $.widget( "ui.dialog", { // We assume that any existing aria-describedby attribute means // that the dialog content is marked up properly // otherwise we brute force the content as the description - if ( !this.element.find( "[aria-describedby]" ).length ) { + if ( !this.element.find("[aria-describedby]").length ) { this.uiDialog.attr({ - "aria-describedby": this.element.uniqueId().attr( "id" ) + "aria-describedby": this.element.uniqueId().attr("id") }); } }, @@ -326,22 +326,22 @@ $.widget( "ui.dialog", { _createTitlebar: function() { var uiDialogTitle; - this.uiDialogTitlebar = $( "
    " ) - .addClass( "ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix" ) + this.uiDialogTitlebar = $("
    ") + .addClass("ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix") .prependTo( this.uiDialog ); this._on( this.uiDialogTitlebar, { mousedown: function( event ) { // Don't prevent click on close button (#8838) // Focusing a dialog that is partially scrolled out of view // causes the browser to scroll it into view, preventing the click event - if ( !$( event.target ).closest( ".ui-dialog-titlebar-close" ) ) { + if ( !$( event.target ).closest(".ui-dialog-titlebar-close") ) { // Dialog isn't getting focus when dragging (#8063) this.uiDialog.focus(); } } }); - this.uiDialogTitlebarClose = $( "" ) + this.uiDialogTitlebarClose = $("") .button({ label: this.options.closeText, icons: { @@ -349,7 +349,7 @@ $.widget( "ui.dialog", { }, text: false }) - .addClass( "ui-dialog-titlebar-close" ) + .addClass("ui-dialog-titlebar-close") .appendTo( this.uiDialogTitlebar ); this._on( this.uiDialogTitlebarClose, { click: function( event ) { @@ -358,30 +358,30 @@ $.widget( "ui.dialog", { } }); - uiDialogTitle = $( "" ) + uiDialogTitle = $("") .uniqueId() - .addClass( "ui-dialog-title" ) + .addClass("ui-dialog-title") .prependTo( this.uiDialogTitlebar ); this._title( uiDialogTitle ); this.uiDialog.attr({ - "aria-labelledby": uiDialogTitle.attr( "id" ) + "aria-labelledby": uiDialogTitle.attr("id") }); }, _title: function( title ) { if ( !this.options.title ) { - title.html( " " ); + title.html(" "); } title.text( this.options.title ); }, _createButtonPane: function() { - this.uiDialogButtonPane = $( "
    " ) - .addClass( "ui-dialog-buttonpane ui-widget-content ui-helper-clearfix" ); + this.uiDialogButtonPane = $("
    ") + .addClass("ui-dialog-buttonpane ui-widget-content ui-helper-clearfix"); - this.uiButtonSet = $( "
    " ) - .addClass( "ui-dialog-buttonset" ) + this.uiButtonSet = $("
    ") + .addClass("ui-dialog-buttonset") .appendTo( this.uiDialogButtonPane ); this._createButtons(); @@ -396,7 +396,7 @@ $.widget( "ui.dialog", { this.uiButtonSet.empty(); if ( $.isEmptyObject( buttons ) ) { - this.uiDialog.removeClass( "ui-dialog-buttons" ); + this.uiDialog.removeClass("ui-dialog-buttons"); return; } @@ -422,7 +422,7 @@ $.widget( "ui.dialog", { .button( buttonOptions ) .appendTo( that.uiButtonSet ); }); - this.uiDialog.addClass( "ui-dialog-buttons" ); + this.uiDialog.addClass("ui-dialog-buttons"); this.uiDialogButtonPane.appendTo( this.uiDialog ); }, @@ -442,7 +442,7 @@ $.widget( "ui.dialog", { handle: ".ui-dialog-titlebar", containment: "document", start: function( event, ui ) { - $( this ).addClass( "ui-dialog-dragging" ); + $( this ).addClass("ui-dialog-dragging"); that._trigger( "dragStart", event, filteredUi( ui ) ); }, drag: function( event, ui ) { @@ -453,7 +453,7 @@ $.widget( "ui.dialog", { ui.position.left - that.document.scrollLeft(), ui.position.top - that.document.scrollTop() ]; - $( this ).removeClass( "ui-dialog-dragging" ); + $( this ).removeClass("ui-dialog-dragging"); that._trigger( "dragStop", event, filteredUi( ui ) ); } }); @@ -465,7 +465,7 @@ $.widget( "ui.dialog", { handles = options.resizable, // .ui-resizable has position: relative defined in the stylesheet // but dialogs have to use absolute or fixed positioning - position = this.uiDialog.css( "position" ), + position = this.uiDialog.css("position"), resizeHandles = typeof handles === 'string' ? handles : "n,e,s,w,se,sw,ne,nw"; @@ -489,16 +489,16 @@ $.widget( "ui.dialog", { minHeight: this._minHeight(), handles: resizeHandles, start: function( event, ui ) { - $( this ).addClass( "ui-dialog-resizing" ); + $( this ).addClass("ui-dialog-resizing"); that._trigger( "resizeStart", event, filteredUi( ui ) ); }, resize: function( event, ui ) { that._trigger( "resize", event, filteredUi( ui ) ); }, stop: function( event, ui ) { - $( this ).removeClass( "ui-dialog-resizing" ); options.height = $( this ).height(); options.width = $( this ).width(); + $( this ).removeClass("ui-dialog-resizing"); that._trigger( "resizeStop", event, filteredUi( ui ) ); } }) @@ -515,7 +515,7 @@ $.widget( "ui.dialog", { _position: function() { // Need to show the dialog to get the actual offset in the position plugin - var isVisible = this.uiDialog.is( ":visible" ); + var isVisible = this.uiDialog.is(":visible"); if ( !isVisible ) { this.uiDialog.show(); } @@ -545,7 +545,7 @@ $.widget( "ui.dialog", { this._size(); this._position(); } - if ( this.uiDialog.is( ":data(ui-resizable)" ) ) { + if ( this.uiDialog.is(":data(ui-resizable)") ) { this.uiDialog.resizable( "option", resizableOptions ); } }, @@ -583,9 +583,9 @@ $.widget( "ui.dialog", { } if ( key === "draggable" ) { - isDraggable = uiDialog.is( ":data(ui-draggable)" ); + isDraggable = uiDialog.is(":data(ui-draggable)"); if ( isDraggable && !value ) { - uiDialog.draggable( "destroy" ); + uiDialog.draggable("destroy"); } if ( !isDraggable && value ) { @@ -599,9 +599,9 @@ $.widget( "ui.dialog", { if ( key === "resizable" ) { // currently resizable, becoming non-resizable - isResizable = uiDialog.is( ":data(ui-resizable)" ); + isResizable = uiDialog.is(":data(ui-resizable)"); if ( isResizable && !value ) { - uiDialog.resizable( "destroy" ); + uiDialog.resizable("destroy"); } // currently resizable, changing handles @@ -616,7 +616,7 @@ $.widget( "ui.dialog", { } if ( key === "title" ) { - this._title( this.uiDialogTitlebar.find( ".ui-dialog-title" ) ); + this._title( this.uiDialogTitlebar.find(".ui-dialog-title") ); } }, @@ -660,7 +660,7 @@ $.widget( "ui.dialog", { this.element.height( Math.max( 0, options.height - nonContentHeight ) ); } - if (this.uiDialog.is( ":data(ui-resizable)" ) ) { + if (this.uiDialog.is(":data(ui-resizable)") ) { this.uiDialog.resizable( "option", "minHeight", this._minHeight() ); } }, @@ -679,10 +679,10 @@ $.widget( "ui.dialog", { if ( $.ui.dialog.overlayInstances ) { this._on( this.document, { focusin: function( event ) { - if ( !$( event.target ).closest( ".ui-dialog").length ) { + if ( !$( event.target ).closest(".ui-dialog").length ) { event.preventDefault(); - $( ".ui-dialog:visible:last .ui-dialog-content" ) - .data( "ui-dialog" )._focusTabbable(); + $(".ui-dialog:visible:last .ui-dialog-content") + .data("ui-dialog")._focusTabbable(); } } }); @@ -690,9 +690,9 @@ $.widget( "ui.dialog", { }); } - this.overlay = $( "
    " ) - .addClass( "ui-widget-overlay ui-front" ) - .appendTo( this.document[ 0 ].body ); + this.overlay = $("
    ") + .addClass("ui-widget-overlay ui-front") + .appendTo( this.document[0].body ); this._on( this.overlay, { mousedown: "_keepFocus" }); @@ -727,9 +727,9 @@ if ( $.uiBackCompat !== false ) { if ( position ) { if ( typeof position === "string" || (typeof position === "object" && "0" in position ) ) { - myAt = position.split ? position.split( " " ) : [ position[ 0 ], position[ 1 ] ]; + myAt = position.split ? position.split(" ") : [ position[0], position[1] ]; if ( myAt.length === 1 ) { - myAt[ 1 ] = myAt[ 0 ]; + myAt[1] = myAt[0]; } $.each( [ "left", "top" ], function( i, offsetPosition ) { @@ -742,7 +742,7 @@ if ( $.uiBackCompat !== false ) { position = { my: myAt[0] + (offset[0] < 0 ? offset[0] : "+" + offset[0]) + " " + myAt[1] + (offset[1] < 0 ? offset[1] : "+" + offset[1]), - at: myAt.join( " " ) + at: myAt.join(" ") }; } @@ -752,7 +752,7 @@ if ( $.uiBackCompat !== false ) { } // need to show the dialog to get the actual offset in the position plugin - isVisible = this.uiDialog.is( ":visible" ); + isVisible = this.uiDialog.is(":visible"); if ( !isVisible ) { this.uiDialog.show(); } -- cgit v1.2.3 From 747d8534520fc3abad81b3c171fa931149398d99 Mon Sep 17 00:00:00 2001 From: Scott González Date: Wed, 12 Dec 2012 08:54:53 -0500 Subject: Core: Removed $.ui.contains. Fixes #8902 - Remove $.ui.contains. --- ui/jquery.ui.core.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'ui') diff --git a/ui/jquery.ui.core.js b/ui/jquery.ui.core.js index 17fad86b4..bd3e30758 100644 --- a/ui/jquery.ui.core.js +++ b/ui/jquery.ui.core.js @@ -289,8 +289,6 @@ $.extend( $.ui, { } }, - contains: $.contains, - // only used by resizable hasScroll: function( el, a ) { -- cgit v1.2.3