aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2011-01-31 22:04:09 -0500
committerScott González <scott.gonzalez@gmail.com>2011-01-31 22:04:09 -0500
commitcb8f5b7f2679ab5473229cac432f28c72521048c (patch)
tree60b63ec0b7f190832dcadef9e04a195985e61621 /ui
parentbb857ddd8d6d4ac7620b49bf765352cd064494c0 (diff)
parenteffbb2c0ec2e60bea6ec5e5822ee52f8ea9e18bc (diff)
downloadjquery-ui-cb8f5b7f2679ab5473229cac432f28c72521048c.tar.gz
jquery-ui-cb8f5b7f2679ab5473229cac432f28c72521048c.zip
Merge branch 'master' into widget-events
Conflicts: ui/jquery.ui.widget.js
Diffstat (limited to 'ui')
-rw-r--r--ui/i18n/jquery.ui.datepicker-ar-DZ.js23
-rw-r--r--ui/jquery.ui.accordion.js296
-rw-r--r--ui/jquery.ui.autocomplete.js15
-rw-r--r--ui/jquery.ui.button.js1
-rw-r--r--ui/jquery.ui.menu.js1
-rw-r--r--ui/jquery.ui.sortable.js32
-rw-r--r--ui/jquery.ui.spinner.js11
-rw-r--r--ui/jquery.ui.widget.js25
8 files changed, 239 insertions, 165 deletions
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: '&#x3c;السابق',
+ nextText: 'التالي&#x3e;',
+ 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();
+ }
+ });
+
+ 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 ) );
-
-// 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();
-
_create.call( this );
- },
+ };
+ }( jQuery, jQuery.ui.accordion.prototype ) );
+
+ // 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 );
- },
+ _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;
+ _mergeHeightStyle: function() {
+ var options = this.options;
- if ( options.fillSpace ) {
- return "fill";
- }
+ if ( options.fillSpace ) {
+ return "fill";
+ }
- if ( options.clearStyle ) {
- return "content";
- }
+ if ( options.clearStyle ) {
+ return "content";
+ }
- if ( options.autoHeight ) {
- return "auto";
+ 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 ) );
+ });
+ }( jQuery, jQuery.ui.accordion.prototype ) );
+
+ // 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"
+ });
+
+ 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;
}
- }
- 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;
+
+ // change events
+ (function( $, prototype ) {
+ var _trigger = prototype._trigger;
+ prototype._trigger = function( type, event, data ) {
+ var ret = _trigger.apply( this, arguments );
+ if ( !ret ) {
+ return false;
+ }
-// resize method
-jQuery.ui.accordion.prototype.resize = jQuery.ui.accordion.prototype.refresh;
+ 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: "<input>",
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: "<button>",
options: {
disabled: null,
text: true,
diff --git a/ui/jquery.ui.menu.js b/ui/jquery.ui.menu.js
index 842557da8..c64057ee0 100644
--- a/ui/jquery.ui.menu.js
+++ b/ui/jquery.ui.menu.js
@@ -16,6 +16,7 @@
var idIncrement = 0;
$.widget("ui.menu", {
+ defaultElement: "<ul>",
_create: function() {
var self = this;
this.menuId = this.element.attr( "id" ) || "ui-menu-" + idIncrement++;
diff --git a/ui/jquery.ui.sortable.js b/ui/jquery.ui.sortable.js
index aa57e3233..05cbf2132 100644
--- a/ui/jquery.ui.sortable.js
+++ b/ui/jquery.ui.sortable.js
@@ -359,7 +359,7 @@ $.widget("ui.sortable", $.ui.mouse, {
if(this.dragging) {
- this._mouseUp();
+ this._mouseUp({ target: null });
if(this.options.helper == "original")
this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper");
@@ -377,21 +377,23 @@ $.widget("ui.sortable", $.ui.mouse, {
}
- //$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node!
- if(this.placeholder[0].parentNode) this.placeholder[0].parentNode.removeChild(this.placeholder[0]);
- if(this.options.helper != "original" && this.helper && this.helper[0].parentNode) this.helper.remove();
-
- $.extend(this, {
- helper: null,
- dragging: false,
- reverting: false,
- _noFinalSort: null
- });
+ if (this.placeholder) {
+ //$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node!
+ if(this.placeholder[0].parentNode) this.placeholder[0].parentNode.removeChild(this.placeholder[0]);
+ if(this.options.helper != "original" && this.helper && this.helper[0].parentNode) this.helper.remove();
- if(this.domPosition.prev) {
- $(this.domPosition.prev).after(this.currentItem);
- } else {
- $(this.domPosition.parent).prepend(this.currentItem);
+ $.extend(this, {
+ helper: null,
+ dragging: false,
+ reverting: false,
+ _noFinalSort: null
+ });
+
+ if(this.domPosition.prev) {
+ $(this.domPosition.prev).after(this.currentItem);
+ } else {
+ $(this.domPosition.parent).prepend(this.currentItem);
+ }
}
return this;
diff --git a/ui/jquery.ui.spinner.js b/ui/jquery.ui.spinner.js
index f444e3126..c8a76f4cf 100644
--- a/ui/jquery.ui.spinner.js
+++ b/ui/jquery.ui.spinner.js
@@ -14,6 +14,7 @@
(function($) {
$.widget('ui.spinner', {
+ defaultElement: "<input>",
options: {
incremental: true,
max: null,
@@ -305,20 +306,14 @@ $.widget('ui.spinner', {
_parse: function(val) {
var input = val;
if (typeof val == 'string') {
- // special case for currency formatting until Globalization handles currencies
- if (this.options.numberformat == "C" && window.Globalization) {
- // parseFloat should accept number format, including currency
- var culture = Globalization.culture || Globalization.cultures['default'];
- val = val.replace(culture.numberFormat.currency.symbol, "");
- }
- val = window.Globalization && this.options.numberformat ? Globalization.parseFloat(val) : +val;
+ val = $.global && this.options.numberformat ? $.global.parseFloat(val) : +val;
}
return isNaN(val) ? null : val;
},
_format: function(num) {
var num = this.options.value;
- this.element.val( window.Globalization && this.options.numberformat ? Globalization.format(num, this.options.numberformat) : num );
+ this.element.val( $.global && this.options.numberformat ? $.global.format(num, this.options.numberformat) : num );
},
destroy: function() {
diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js
index 4f092f9d8..c8e5348ac 100644
--- a/ui/jquery.ui.widget.js
+++ b/ui/jquery.ui.widget.js
@@ -37,7 +37,13 @@ $.widget = function( name, base, prototype ) {
$[ namespace ] = $[ namespace ] || {};
$[ namespace ][ name ] = function( options, element ) {
+ // allow instantiation without "new" keyword
+ if ( !this._createWidget ) {
+ return new $[ namespace ][ name ]( options, element );
+ }
+
// allow instantiation without initializing for simple inheritance
+ // must use "new" keyword (the code above always passes args)
if ( arguments.length ) {
this._createWidget( options, element );
}
@@ -97,7 +103,7 @@ $.widget.bridge = function( name, object ) {
if ( instance ) {
instance.option( options || {} )._init();
} else {
- $.data( this, name, new object( options, this ) );
+ object( options, this );
}
});
}
@@ -107,7 +113,13 @@ $.widget.bridge = function( name, object ) {
};
$.Widget = function( options, element ) {
+ // allow instantiation without "new" keyword
+ if ( !this._createWidget ) {
+ return new $[ namespace ][ name ]( options, element );
+ }
+
// allow instantiation without initializing for simple inheritance
+ // must use "new" keyword (the code above always passes args)
if ( arguments.length ) {
this._createWidget( options, element );
}
@@ -116,13 +128,12 @@ $.Widget = function( options, element ) {
$.Widget.prototype = {
widgetName: "widget",
widgetEventPrefix: "",
+ defaultElement: "<div>",
options: {
disabled: false
},
_createWidget: function( options, element ) {
- // $.widget.bridge stores the plugin instance, but we do it anyway
- // so that it's stored even before the _create function runs
- $.data( element, this.widgetName, this );
+ element = $( element || this.defaultElement || this )[ 0 ];
this.element = $( element );
this.options = $.extend( true, {},
this.options,
@@ -132,7 +143,11 @@ $.Widget.prototype = {
this.bindings = $();
this.hoverable = $();
this.focusable = $();
- this._bind({ remove: "destroy" });
+
+ if ( element !== this ) {
+ $.data( element, this.widgetName, this );
+ this._bind({ remove: "destroy" });
+ }
this._create();
this._trigger( "create" );