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,28 +425,45 @@ Ox.List = function(options, self) {
}
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() {
if (self.$pages[0]) {
var height = getHeight(),
lastItemHeight = height % self.options.itemHeight || self.options.itemHeight,
visibleItems = Math.ceil(height / self.options.itemHeight);
if (self.listLength < visibleItems) {
Ox.range(self.listLength, visibleItems).forEach(function(v) {
var $item = Ox.ListItem({
construct: self.options.construct,
});
$item.addClass('OxEmpty').removeClass('OxTarget');
if (v == visibleItems - 1) {
$item.$element.css({
height: lastItemHeight + 'px',
overflowY: 'hidden'
});
}
$item.appendTo(self.$pages[0]);
});
if (self.options.type == 'text') {
var height = getHeight(),
lastItemHeight = height % self.options.itemHeight || self.options.itemHeight,
visibleItems = Math.ceil(height / self.options.itemHeight);
if (self.listLength < visibleItems) {
Ox.range(self.listLength, visibleItems).forEach(function(v) {
var $item = Ox.ListItem({
construct: self.options.construct,
});
$item.addClass('OxEmpty').removeClass('OxTarget');
if (v == visibleItems - 1) {
$item.$element.css({
height: lastItemHeight + 'px',
overflowY: 'hidden'
});
}
$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() {
return Math.ceil(self.listLength * (self.options[
self.options.orientation == 'horizontal' ? 'itemWidth' : 'itemHeight'
] + self.itemMargin) / self.rowLength);
return Math.ceil(self.listLength / self.rowLength) * (self.options[
self.options.orientation == 'horizontal' ? 'itemWidth' : 'itemHeight'
] + self.itemMargin);
}
function getNext() {
@ -623,9 +640,9 @@ Ox.List = function(options, self) {
function getPrevious() {
var pos = -1;
if (self.selected.length) {
pos = (self.options.orientation == 'both' ?
self.selected[self.selected.length - 1] :
Ox.min(self.selected)) - 1;
pos = (self.options.orientation == 'both'
? self.selected[self.selected.length - 1]
: Ox.min(self.selected)) - 1;
}
return pos;
}
@ -635,9 +652,9 @@ Ox.List = function(options, self) {
}
function getRowLength() {
return self.options.orientation == 'both' ?
Math.floor((getWidth() - self.listMargin) /
(self.options.itemWidth + self.itemMargin)) : 1;
return self.options.orientation == 'both'
? Math.floor((getWidth() - self.listMargin) /
(self.options.itemWidth + self.itemMargin)) : 1;
}
function getScrollPosition() {
@ -703,7 +720,7 @@ Ox.List = function(options, self) {
range = [offset, offset + getPageLength(page)];
if (Ox.isUndefined(self.$pages[page])) { // fixme: unload will have made this undefined already
self.$pages[page] = constructEmptyPage(page);
self.options.type == 'text' && page == 0 && fillFirstPage();
page == 0 && fillFirstPage();
self.$pages[page].appendTo(that.$content);
self.requests.push(self.options.items({
keys: keys,
@ -725,7 +742,7 @@ Ox.List = function(options, self) {
isSelected(pos) && self.$items[pos].addClass('OxSelected');
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?
//Ox.print('emptyPage', $emptyPage)
$emptyPage.removeElement && $emptyPage.removeElement();
@ -1558,6 +1575,8 @@ Ox.List = function(options, self) {
});
scrollTo(scroll);
}
emptyFirstPage();
fillFirstPage();
} else if (self.options.type == 'text') {
emptyFirstPage();
fillFirstPage();