fix a bug where in orientation=both icon lists with less than one screen full of icons, clicking below the icons would not cause a deselect

This commit is contained in:
rlx 2011-09-03 17:54:17 +00:00
parent 74873e3bfb
commit 2043dc7a12

View file

@ -425,11 +425,18 @@ Ox.List = function(options, self) {
} }
function emptyFirstPage() { function emptyFirstPage() {
self.$pages[0] && self.$pages[0].find('.OxEmpty').remove(); if (self.$pages[0]) {
if (self.options.type == 'text') {
self.$pages[0].find('.OxEmpty').remove();
} else if (self.options.orientation == 'both') {
that.$content.css({height: getListSize() + 'px'});
}
}
} }
function fillFirstPage() { function fillFirstPage() {
if (self.$pages[0]) { if (self.$pages[0]) {
if (self.options.type == 'text') {
var height = getHeight(), var height = getHeight(),
lastItemHeight = height % self.options.itemHeight || self.options.itemHeight, lastItemHeight = height % self.options.itemHeight || self.options.itemHeight,
visibleItems = Math.ceil(height / self.options.itemHeight); visibleItems = Math.ceil(height / self.options.itemHeight);
@ -448,6 +455,16 @@ Ox.List = function(options, self) {
$item.appendTo(self.$pages[0]); $item.appendTo(self.$pages[0]);
}); });
} }
} else if (self.options.orientation == 'both') {
var height = getHeight(),
listSize = getListSize();
if (listSize < height) {
that.$element.css({overflowY: 'hidden'});
that.$content.css({height: height + 'px'});
} else {
that.$element.css({overflowY: 'auto'});
}
}
} }
} }
@ -503,9 +520,9 @@ Ox.List = function(options, self) {
} }
function getListSize() { function getListSize() {
return Math.ceil(self.listLength * (self.options[ return Math.ceil(self.listLength / self.rowLength) * (self.options[
self.options.orientation == 'horizontal' ? 'itemWidth' : 'itemHeight' self.options.orientation == 'horizontal' ? 'itemWidth' : 'itemHeight'
] + self.itemMargin) / self.rowLength); ] + self.itemMargin);
} }
function getNext() { function getNext() {
@ -623,9 +640,9 @@ Ox.List = function(options, self) {
function getPrevious() { function getPrevious() {
var pos = -1; var pos = -1;
if (self.selected.length) { if (self.selected.length) {
pos = (self.options.orientation == 'both' ? pos = (self.options.orientation == 'both'
self.selected[self.selected.length - 1] : ? self.selected[self.selected.length - 1]
Ox.min(self.selected)) - 1; : Ox.min(self.selected)) - 1;
} }
return pos; return pos;
} }
@ -635,8 +652,8 @@ Ox.List = function(options, self) {
} }
function getRowLength() { function getRowLength() {
return self.options.orientation == 'both' ? return self.options.orientation == 'both'
Math.floor((getWidth() - self.listMargin) / ? Math.floor((getWidth() - self.listMargin) /
(self.options.itemWidth + self.itemMargin)) : 1; (self.options.itemWidth + self.itemMargin)) : 1;
} }
@ -703,7 +720,7 @@ Ox.List = function(options, self) {
range = [offset, offset + getPageLength(page)]; range = [offset, offset + getPageLength(page)];
if (Ox.isUndefined(self.$pages[page])) { // fixme: unload will have made this undefined already if (Ox.isUndefined(self.$pages[page])) { // fixme: unload will have made this undefined already
self.$pages[page] = constructEmptyPage(page); self.$pages[page] = constructEmptyPage(page);
self.options.type == 'text' && page == 0 && fillFirstPage(); page == 0 && fillFirstPage();
self.$pages[page].appendTo(that.$content); self.$pages[page].appendTo(that.$content);
self.requests.push(self.options.items({ self.requests.push(self.options.items({
keys: keys, keys: keys,
@ -725,7 +742,7 @@ Ox.List = function(options, self) {
isSelected(pos) && self.$items[pos].addClass('OxSelected'); isSelected(pos) && self.$items[pos].addClass('OxSelected');
self.$items[pos].appendTo(self.$pages[page]); self.$items[pos].appendTo(self.$pages[page]);
}); });
self.options.type == 'text' && page == 0 && fillFirstPage(); page == 0 && fillFirstPage();
// fixme: why does emptyPage sometimes have no methods? // fixme: why does emptyPage sometimes have no methods?
//Ox.print('emptyPage', $emptyPage) //Ox.print('emptyPage', $emptyPage)
$emptyPage.removeElement && $emptyPage.removeElement(); $emptyPage.removeElement && $emptyPage.removeElement();
@ -1558,6 +1575,8 @@ Ox.List = function(options, self) {
}); });
scrollTo(scroll); scrollTo(scroll);
} }
emptyFirstPage();
fillFirstPage();
} else if (self.options.type == 'text') { } else if (self.options.type == 'text') {
emptyFirstPage(); emptyFirstPage();
fillFirstPage(); fillFirstPage();