diff --git a/demos/datepicker/date-range.html b/demos/datepicker/date-range.html index 1e3beb2a2..6bce3f776 100644 --- a/demos/datepicker/date-range.html +++ b/demos/datepicker/date-range.html @@ -17,7 +17,7 @@ numberOfMonths: 3, onSelect: function( selectedDate ) { var option = this.id == "from" ? "minDate" : "maxDate", - instance = $( this ).data( "datepicker" ); + instance = $( this ).data( "datepicker" ), date = $.datepicker.parseDate( instance.settings.dateFormat || $.datepicker._defaults.dateFormat, diff --git a/demos/datepicker/localization.html b/demos/datepicker/localization.html index 33d03c98c..767cdaa54 100644 --- a/demos/datepicker/localization.html +++ b/demos/datepicker/localization.html @@ -10,6 +10,7 @@ + @@ -87,6 +88,7 @@ " ); + $.ui.testWidget.prototype._create = function() { + same( this.element[ 0 ], elem[ 0 ], "from element" ); + same( elem.data( "testWidget" ), this, "instace stored in .data()" ); + }; + $.ui.testWidget( {}, elem[ 0 ] ); + + elem = $( "
" ); + $.ui.testWidget.prototype._create = function() { + same( this.element[ 0 ], elem[ 0 ], "from jQuery object" ); + same( elem.data( "testWidget" ), this, "instace stored in .data()" ); + }; + $.ui.testWidget( {}, elem ); + + elem = $( "
" ) + .appendTo( "#main" ); + $.ui.testWidget.prototype._create = function() { + same( this.element[ 0 ], elem[ 0 ], "from selector" ); + same( elem.data( "testWidget" ), this, "instace stored in .data()" ); + }; + $.ui.testWidget( {}, "#element-normalization-selector" ); + + $.ui.testWidget.prototype.defaultElement = null; + $.ui.testWidget.prototype._create = function() { + // using strictEqual throws an error (Maximum call stack size exceeded) + ok( this.element[ 0 ] === this, "instance as element" ); + }; + $.ui.testWidget(); +}); + test( "jQuery usage", function() { expect( 11 ); @@ -55,7 +100,7 @@ test( "jQuery usage", function() { }); shouldCreate = true; - var elem = $( "
" ) + var elem = $( "
" ) .bind( "testwidgetcreate", function() { ok( shouldCreate, "create event triggered on instantiation" ); }) @@ -101,7 +146,7 @@ test( "direct usage", function() { } }); - var elem = $( "
" )[ 0 ]; + var elem = $( "
" )[ 0 ]; shouldCreate = true; var instance = new $.ui.testWidget( {}, elem ); @@ -153,7 +198,7 @@ test( "merge multiple option arguments", function() { }); } }); - $( "
" ).testWidget({ + $( "
" ).testWidget({ option1: "valuex", option2: "valuex", option3: "value3", @@ -200,7 +245,7 @@ test( "._getCreateOptions()", function() { }); test( "re-init", function() { - var div = $( "
" ), + var div = $( "
" ), actions = []; $.widget( "ui.testWidget", { @@ -286,7 +331,7 @@ test( ".option() - getter", function() { _create: function() {} }); - var div = $( "
" ).testWidget({ + var div = $( "
" ).testWidget({ foo: "bar", baz: 5, qux: [ "quux", "quuux" ] @@ -317,7 +362,7 @@ test( ".option() - delegate to ._setOptions()", function() { calls.push( options ); } }); - var div = $( "
" ).testWidget(); + var div = $( "
" ).testWidget(); calls = []; div.testWidget( "option", "foo", "bar" ); @@ -343,7 +388,7 @@ test( ".option() - delegate to ._setOption()", function() { }); } }); - var div = $( "
" ).testWidget(); + var div = $( "
" ).testWidget(); calls = []; div.testWidget( "option", "foo", "bar" ); @@ -370,7 +415,7 @@ test( ".enable()", function() { same( val, false, "disabled set to false" ); } }); - $( "
" ).testWidget().testWidget( "enable" ); + $( "
" ).testWidget().testWidget( "enable" ); }); test( ".disable()", function() { @@ -382,26 +427,26 @@ test( ".disable()", function() { same( val, true, "disabled set to true" ); } }); - $( "
" ).testWidget().testWidget( "disable" ); + $( "
" ).testWidget().testWidget( "disable" ); }); test( ".widget() - base", function() { $.widget( "ui.testWidget", { _create: function() {} }); - var div = $( "
" ).testWidget(); + var div = $( "
" ).testWidget(); same( div[0], div.testWidget( "widget" )[0]); }); test( ".widget() - overriden", function() { - var wrapper = $( "
" ); + var wrapper = $( "
" ); $.widget( "ui.testWidget", { _create: function() {}, widget: function() { return wrapper; } }); - same( wrapper[0], $( "
" ).testWidget().testWidget( "widget" )[0] ); + same( wrapper[0], $( "
" ).testWidget().testWidget( "widget" )[0] ); }); test( "._bind() to element (default)", function() { @@ -691,6 +736,28 @@ test( "._trigger() - provide event and ui", function() { .testWidget( "testEvent" ); }); +test( "._triger() - instance as element", function() { + expect( 4 ); + $.widget( "ui.testWidget", { + defaultElement: null, + testEvent: function() { + var ui = { foo: "bar" }; + this._trigger( "foo", null, ui ); + } + }); + var instance = $.ui.testWidget({ + foo: function( event, ui ) { + equal( event.type, "testwidgetfoo", "event object passed to callback" ); + same( ui, { foo: "bar" }, "ui object passed to callback" ); + } + }); + $( instance ).bind( "testwidgetfoo", function( event, ui ) { + equal( event.type, "testwidgetfoo", "event object passed to event handler" ); + same( ui, { foo: "bar" }, "ui object passed to event handler" ); + }); + instance.testEvent(); +}); + test( "auto-destroy - .remove()", function() { expect( 1 ); $.widget( "ui.testWidget", { @@ -721,8 +788,6 @@ test( "auto-destroy - .remove() on child", function() { } }); $( "#widget" ).testWidget().children().remove(); - // http://github.com/jquery/qunit/pull/34 - $.ui.testWidget.prototype.destroy = $.noop; }); test( "auto-destroy - .empty()", function() { @@ -733,8 +798,6 @@ test( "auto-destroy - .empty()", function() { } }); $( "#widget" ).testWidget().empty(); - // http://github.com/jquery/qunit/pull/34 - $.ui.testWidget.prototype.destroy = $.noop; }); test( "auto-destroy - .empty() on parent", function() { @@ -758,4 +821,4 @@ test( "auto-destroy - .detach()", function() { $( "#widget" ).testWidget().detach(); }); -})( jQuery ); +}( jQuery ) ); diff --git a/tests/unit/widget/widget_tickets.js b/tests/unit/widget/widget_tickets.js index 21f44b54c..0267c8ff4 100644 --- a/tests/unit/widget/widget_tickets.js +++ b/tests/unit/widget/widget_tickets.js @@ -1,6 +1,3 @@ -/* - * widget unit tests - */ (function( $ ) { module( "widget: tickets" ); @@ -43,4 +40,4 @@ test( "#5830 - Widget: Using inheritance overwrites the base classes options", f delete $.ui.testWidgetExtension; }); -})( jQuery ); +}( jQuery ) ); diff --git a/themes/base/jquery.ui.accordion.css b/themes/base/jquery.ui.accordion.css index 80a80c82c..a260cf9ef 100644 --- a/themes/base/jquery.ui.accordion.css +++ b/themes/base/jquery.ui.accordion.css @@ -10,7 +10,6 @@ /* IE/Win - Fix animation bug - #4615 */ .ui-accordion { width: 100%; } .ui-accordion .ui-accordion-header { cursor: pointer; position: relative; margin-top: 1px; zoom: 1; } -.ui-accordion .ui-accordion-li-fix { display: inline; } .ui-accordion .ui-accordion-header-active { border-bottom: 0 !important; } .ui-accordion .ui-accordion-heading { display: block; font-size: 1em; padding: .5em .5em .5em .7em; } .ui-accordion-icons .ui-accordion-heading { padding-left: 2.2em; } diff --git a/ui/i18n/jquery.ui.datepicker-ar-DZ.js b/ui/i18n/jquery.ui.datepicker-ar-DZ.js new file mode 100644 index 000000000..e0e1685d8 --- /dev/null +++ b/ui/i18n/jquery.ui.datepicker-ar-DZ.js @@ -0,0 +1,23 @@ +/* Algerian Arabic Translation for jQuery UI date picker plugin. (can be used for Tunisia)*/ +/* Mohamed Cherif BOUCHELAGHEM -- cherifbouchelaghem@yahoo.fr */ + +jQuery(function($){ + $.datepicker.regional['ar-DZ'] = { + closeText: 'إغلاق', + prevText: '<السابق', + nextText: 'التالي>', + currentText: 'اليوم', + monthNames: ['جانفي', 'فيفري', 'مارس', 'أفريل', 'ماي', 'جوان', + 'جويلية', 'أوت', 'سبتمبر','أكتوبر', 'نوفمبر', 'ديسمبر'], + monthNamesShort: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'], + dayNames: ['الأحد', 'الاثنين', 'الثلاثاء', 'الأربعاء', 'الخميس', 'الجمعة', 'السبت'], + dayNamesShort: ['الأحد', 'الاثنين', 'الثلاثاء', 'الأربعاء', 'الخميس', 'الجمعة', 'السبت'], + dayNamesMin: ['الأحد', 'الاثنين', 'الثلاثاء', 'الأربعاء', 'الخميس', 'الجمعة', 'السبت'], + weekHeader: 'أسبوع', + dateFormat: 'dd/mm/yy', + firstDay: 6, + isRTL: true, + showMonthAfterYear: false, + yearSuffix: ''}; + $.datepicker.setDefaults($.datepicker.regional['ar-DZ']); +}); diff --git a/ui/jquery.ui.accordion.js b/ui/jquery.ui.accordion.js index 954ee91bd..6c257c8c0 100644 --- a/ui/jquery.ui.accordion.js +++ b/ui/jquery.ui.accordion.js @@ -20,12 +20,10 @@ $.widget( "ui.accordion", { collapsible: false, event: "click", header: "> li > :first-child,> :not(li):even", - // TODO: set to "auto" in 2.0 (#5868, #5872) - heightStyle: null, // "auto" + heightStyle: "auto", icons: { - header: "ui-icon-triangle-1-e", - // TODO: set to "ui-icon-triangle-1-s" in 2.0 (#6835) - activeHeader: null // "ui-icon-triangle-1-s" + activeHeader: "ui-icon-triangle-1-s", + header: "ui-icon-triangle-1-e" } }, @@ -35,12 +33,7 @@ $.widget( "ui.accordion", { self.running = 0; - self.element - .addClass( "ui-accordion ui-widget ui-helper-reset" ) - // in lack of child-selectors in CSS - // we need to mark top-LIs in a UL-accordion for some IE-fix - .children( "li" ) - .addClass( "ui-accordion-li-fix" ); + self.element.addClass( "ui-accordion ui-widget ui-helper-reset" ); self.headers = self.element.find( options.header ) .addClass( "ui-accordion-header ui-helper-reset ui-state-default ui-corner-all" ); @@ -265,6 +258,17 @@ $.widget( "ui.accordion", { return; } + // allow the activation to be canceled + var eventData = { + oldHeader: this.active, + oldContent: this.active.next(), + newHeader: $(), + newContent: $() + }; + if ( this._trigger( "beforeActivate", null, eventData ) === false ) { + return; + } + this.active .removeClass( "ui-state-active ui-corner-top" ) .addClass( "ui-state-default ui-corner-all" ) @@ -275,24 +279,34 @@ $.widget( "ui.accordion", { var toHide = this.active.next(), data = { options: this.options, - newHeader: $( [] ), + newHeader: $(), oldHeader: this.active, - newContent: $( [] ), + newContent: $(), oldContent: toHide }, - toShow = ( this.active = $( [] ) ); + toShow = ( this.active = $() ); this._toggle( toShow, toHide, data ); }, // TODO: add tests/docs for negative values in 2.0 (#6854) _findActive: function( selector ) { - return typeof selector === "number" ? this.headers.eq( selector ) : $( [] ); + return typeof selector === "number" ? this.headers.eq( selector ) : $(); }, _eventHandler: function( event ) { var options = this.options, + active = this.active, clicked = $( event.currentTarget ), - clickedIsActive = clicked[0] === this.active[0]; + clickedIsActive = clicked[ 0 ] === active[ 0 ], + collapsing = clickedIsActive && options.collapsible, + toShow = clicked.next(), + toHide = active.next(), + eventData = { + oldHeader: active, + oldContent: toHide, + newHeader: collapsing ? $() : clicked, + newContent: collapsing ? $() : toShow + }; event.preventDefault(); @@ -305,26 +319,26 @@ $.widget( "ui.accordion", { return; } - options.active = options.collapsible && clickedIsActive ? - false : - this.headers.index( clicked ); + // allow the activation to be canceled + if ( this._trigger( "beforeActivate", null, eventData ) === false ) { + return; + } + + options.active = collapsing ? false : this.headers.index( clicked ); // find elements to show and hide - var active = this.active, - toShow = clicked.next(), - toHide = this.active.next(), - data = { + var data = { options: options, - newHeader: clickedIsActive && options.collapsible ? $([]) : clicked, - oldHeader: this.active, - newContent: clickedIsActive && options.collapsible ? $([]) : toShow, + newHeader: collapsing ? $() : clicked, + oldHeader: active, + newContent: collapsing ? $() : toShow, oldContent: toHide }, - down = this.headers.index( this.active[0] ) > this.headers.index( clicked[0] ); + down = this.headers.index( active[0] ) > this.headers.index( clicked[0] ); // when the call to ._toggle() comes after the class changes // it causes a very odd bug in IE 8 (see #6720) - this.active = clickedIsActive ? $([]) : clicked; + this.active = clickedIsActive ? $() : clicked; this._toggle( toShow, toHide, data, clickedIsActive, down ); // switch classes @@ -362,9 +376,6 @@ $.widget( "ui.accordion", { return self._completed.apply( self, arguments ); }; - // trigger changestart event - self._trigger( "changestart", null, self.data ); - // count elements to animate self.running = toHide.size() === 0 ? toShow.size() : toHide.size(); @@ -373,7 +384,7 @@ $.widget( "ui.accordion", { if ( options.collapsible && clickedIsActive ) { animOptions = { - toShow: $( [] ), + toShow: $(), toHide: toHide, complete: complete, down: down, @@ -468,7 +479,7 @@ $.widget( "ui.accordion", { this.toHide.parent()[0].className = this.toHide.parent()[0].className; } - this._trigger( "change", null, this.data ); + this._trigger( "activate", null, this.data ); } }); @@ -578,115 +589,138 @@ $.extend( $.ui.accordion, { // DEPRECATED - -// navigation options -(function( $, prototype ) { - $.extend( prototype.options, { - navigation: false, - navigationFilter: function() { - return this.href.toLowerCase() === location.href.toLowerCase(); - } - }); - - var _create = prototype._create; - prototype._create = function() { - if ( this.options.navigation ) { - var self = this, - headers = this.element.find( this.options.header ), - content = headers.next(); - current = headers.add( content ) - .find( "a" ) - .filter( this.options.navigationFilter ) - [ 0 ]; - if ( current ) { - headers.add( content ).each( function( index ) { - if ( $.contains( this, current ) ) { - self.options.active = Math.floor( index / 2 ); - return false; - } - }); +if ( $.uiBackCompat !== false ) { + // navigation options + (function( $, prototype ) { + $.extend( prototype.options, { + navigation: false, + navigationFilter: function() { + return this.href.toLowerCase() === location.href.toLowerCase(); } - } - _create.call( this ); - }; -}( jQuery, jQuery.ui.accordion.prototype ) ); - -// height options -(function( $, prototype ) { - $.extend( prototype.options, { - autoHeight: true, // use heightStyle: "auto" - clearStyle: false, // use heightStyle: "content" - fillSpace: false // use heightStyle: "fill" - }); - - var _create = prototype._create, - _setOption = prototype._setOption; - - $.extend( prototype, { - _create: function() { - this.options.heightStyle = this.options.heightStyle || - this._mergeHeightStyle(); + }); + var _create = prototype._create; + prototype._create = function() { + if ( this.options.navigation ) { + var self = this, + headers = this.element.find( this.options.header ), + content = headers.next(); + current = headers.add( content ) + .find( "a" ) + .filter( this.options.navigationFilter ) + [ 0 ]; + if ( current ) { + headers.add( content ).each( function( index ) { + if ( $.contains( this, current ) ) { + self.options.active = Math.floor( index / 2 ); + return false; + } + }); + } + } _create.call( this ); - }, + }; + }( jQuery, jQuery.ui.accordion.prototype ) ); - _setOption: function( key, value ) { - if ( key === "autoHeight" || key === "clearStyle" || key === "fillSpace" ) { - this.options.heightStyle = this._mergeHeightStyle(); + // height options + (function( $, prototype ) { + $.extend( prototype.options, { + heightStyle: null, // remove default so we fall back to old values + autoHeight: true, // use heightStyle: "auto" + clearStyle: false, // use heightStyle: "content" + fillSpace: false // use heightStyle: "fill" + }); + + var _create = prototype._create, + _setOption = prototype._setOption; + + $.extend( prototype, { + _create: function() { + this.options.heightStyle = this.options.heightStyle || + this._mergeHeightStyle(); + + _create.call( this ); + }, + + _setOption: function( key, value ) { + if ( key === "autoHeight" || key === "clearStyle" || key === "fillSpace" ) { + this.options.heightStyle = this._mergeHeightStyle(); + } + _setOption.apply( this, arguments ); + }, + + _mergeHeightStyle: function() { + var options = this.options; + + if ( options.fillSpace ) { + return "fill"; + } + + if ( options.clearStyle ) { + return "content"; + } + + if ( options.autoHeight ) { + return "auto"; + } } - _setOption.apply( this, arguments ); - }, + }); + }( jQuery, jQuery.ui.accordion.prototype ) ); - _mergeHeightStyle: function() { - var options = this.options; + // icon options + (function( $, prototype ) { + $.extend( prototype.options.icons, { + activeHeader: null, // remove default so we fall back to old values + headerSelected: "ui-icon-triangle-1-s" + }); - if ( options.fillSpace ) { - return "fill"; - } + var _createIcons = prototype._createIcons; + prototype._createIcons = function() { + this.options.icons.activeHeader = this.options.icons.activeHeader || + this.options.icons.headerSelected; + _createIcons.call( this ); + }; + }( jQuery, jQuery.ui.accordion.prototype ) ); - if ( options.clearStyle ) { - return "content"; - } + // expanded active option, activate method + (function( $, prototype ) { + prototype.activate = prototype._activate; - if ( options.autoHeight ) { - return "auto"; - } - } - }); -}( jQuery, jQuery.ui.accordion.prototype ) ); - -// icon options -(function( $, prototype ) { - prototype.options.icons.headerSelected = "ui-icon-triangle-1-s"; - - var _createIcons = prototype._createIcons; - prototype._createIcons = function() { - this.options.icons.activeHeader = this.options.icons.activeHeader || - this.options.icons.headerSelected; - _createIcons.call( this ); - }; -}( jQuery, jQuery.ui.accordion.prototype ) ); - -// expanded active option, activate method -(function( $, prototype ) { - prototype.activate = prototype._activate; - - var _findActive = prototype._findActive; - prototype._findActive = function( index ) { - if ( index === -1 ) { - index = false; - } - if ( index && typeof index !== "number" ) { - index = this.headers.index( this.headers.filter( index ) ); + var _findActive = prototype._findActive; + prototype._findActive = function( index ) { if ( index === -1 ) { index = false; } - } - return _findActive.call( this, index ); - }; -}( jQuery, jQuery.ui.accordion.prototype ) ); + if ( index && typeof index !== "number" ) { + index = this.headers.index( this.headers.filter( index ) ); + if ( index === -1 ) { + index = false; + } + } + return _findActive.call( this, index ); + }; + }( jQuery, jQuery.ui.accordion.prototype ) ); -// resize method -jQuery.ui.accordion.prototype.resize = jQuery.ui.accordion.prototype.refresh; + // resize method + jQuery.ui.accordion.prototype.resize = jQuery.ui.accordion.prototype.refresh; + + // change events + (function( $, prototype ) { + var _trigger = prototype._trigger; + prototype._trigger = function( type, event, data ) { + var ret = _trigger.apply( this, arguments ); + if ( !ret ) { + return false; + } + + if ( type === "beforeActivate" ) { + ret = _trigger.call( this, "changestart", event, data ); + } else if ( type === "activate" ) { + ret = _trigger.call( this, "change", event, data ); + } + return ret; + } + }( jQuery, jQuery.ui.accordion.prototype ) ); +} })( jQuery ); diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index 1342f7648..594d59530 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -15,7 +15,11 @@ */ (function( $, undefined ) { +// used to prevent race conditions with remote data sources +var requestIndex = 0; + $.widget( "ui.autocomplete", { + defaultElement: "", options: { appendTo: "body", delay: 300, @@ -256,17 +260,16 @@ $.widget( "ui.autocomplete", { url: url, data: request, dataType: "json", - success: function( data, status, xhr ) { - if ( xhr === self.xhr ) { + autocompleteRequest: ++requestIndex, + success: function( data, status ) { + if ( this.autocompleteRequest === requestIndex ) { response( data ); } - self.xhr = null; }, - error: function( xhr ) { - if ( xhr === self.xhr ) { + error: function() { + if ( this.autocompleteRequest === requestIndex ) { response( [] ); } - self.xhr = null; } }); }; diff --git a/ui/jquery.ui.button.js b/ui/jquery.ui.button.js index b1d060a42..8f63ec57a 100644 --- a/ui/jquery.ui.button.js +++ b/ui/jquery.ui.button.js @@ -43,6 +43,7 @@ var lastActive, }; $.widget( "ui.button", { + defaultElement: "