spinner: changed data list to support any DOM container not just <ul>

This commit is contained in:
Ca-Phun Ung 2008-08-30 19:15:08 +00:00
parent 7c33681e52
commit 66d90af241
2 changed files with 22 additions and 12 deletions

View File

@ -69,13 +69,6 @@ label {
padding: 0;
}
ul.ui-spinner-box {
height: 1.2em;
line-height: 1.2em;
margin: 0;
padding: 0;
}
.ui-spinner-up,
.ui-spinner-down {
width: 10%;
@ -103,6 +96,18 @@ ul.ui-spinner-box {
background: #FEFEFE;
}
.ui-spinner-list {
height: 1.2em;
line-height: 1.2em;
margin: 0;
padding: 0;
}
.ui-spinner-listitem {
margin: 0;
padding: 0;
}
</style>
</head>

View File

@ -25,10 +25,12 @@ $.widget('ui.spinner', {
}
// data list: set contraints to object length and step size
if (this.element.is('ul')) {
if (this.element.children().length > 1) {
this.element.addClass('ui-spinner-list');
$('>*', this.element).addClass('ui-spinner-listitem');
this.options.stepping = 1;
this.options.min = 0;
this.options.max = $('li', this.element).length-1;
this.options.max = $('>*', this.element).length-1;
}
//Initialize needed constants
@ -121,7 +123,7 @@ $.widget('ui.spinner', {
.end();
// data list: fix height of data list spinner
if (this.element.is('ul')) {
if (this.element.hasClass('ui-spinner-list')) {
this.element.parent().css('height', this.element.outerHeight());
}
@ -216,7 +218,7 @@ $.widget('ui.spinner', {
);
},
_animate: function(d) {
if (this.element.is('ul') && ((d == 'up' && this._getValue() <= this.options.max) || (d == 'down' && this._getValue() >= this.options.min)) ) {
if (this.element.hasClass('ui-spinner-list') && ((d == 'up' && this._getValue() <= this.options.max) || (d == 'down' && this._getValue() >= this.options.min)) ) {
this.element.animate({marginTop: '-' + this._getValue() * this.element.outerHeight() }, {
duration: 'fast',
queue: false
@ -243,7 +245,7 @@ $.widget('ui.spinner', {
this.element.unmousewheel();
}
this.element
.removeClass('ui-spinner-box')
.removeClass('ui-spinner-box ui-spinner-list')
.removeAttr('disabled')
.removeAttr('autocomplete')
.removeData('spinner')
@ -251,6 +253,9 @@ $.widget('ui.spinner', {
.siblings()
.remove()
.end()
.children()
.removeClass('ui-spinner-listitem')
.end()
.parent()
.removeClass('ui-spinner ui-spinner-disabled')
.before(this.element.clone())