some changes towards fixed height icon lists
This commit is contained in:
parent
4642b56a95
commit
b05be138cc
2 changed files with 17 additions and 6 deletions
|
@ -1,4 +1,4 @@
|
||||||
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
// vim: et:ts=4:sw=4:sts=4:ft=js
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
Ox.IconItem <f:Ox.Element> IconItem Object
|
Ox.IconItem <f:Ox.Element> IconItem Object
|
||||||
|
@ -6,6 +6,7 @@ Ox.IconItem <f:Ox.Element> IconItem Object
|
||||||
(options) -> <f> IconItem Object
|
(options) -> <f> IconItem Object
|
||||||
(options, self) -> <f> IconItem Object
|
(options, self) -> <f> IconItem Object
|
||||||
options <o> Options object
|
options <o> Options object
|
||||||
|
fixedRatio <b|n|false> if set to a number, icons have a fixed ratio
|
||||||
height <n|128> icon height
|
height <n|128> icon height
|
||||||
id <s> element id
|
id <s> element id
|
||||||
info <s> icon info
|
info <s> icon info
|
||||||
|
@ -23,6 +24,7 @@ Ox.IconItem = function(options, self) {
|
||||||
self = self || {};
|
self = self || {};
|
||||||
var that = Ox.Element({}, self)
|
var that = Ox.Element({}, self)
|
||||||
.defaults({
|
.defaults({
|
||||||
|
fixedRatio: false,
|
||||||
height: 128,
|
height: 128,
|
||||||
id: '',
|
id: '',
|
||||||
info: '',
|
info: '',
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
// vim: et:ts=4:sw=4:sts=4:ft=js
|
||||||
/*@
|
/*@
|
||||||
Ox.IconList <f:Ox.Element> IconList Object
|
Ox.IconList <f:Ox.Element> IconList Object
|
||||||
() -> <f> IconList Object
|
() -> <f> IconList Object
|
||||||
|
@ -6,7 +6,9 @@ Ox.IconList <f:Ox.Element> IconList Object
|
||||||
(options, self) -> <f> IconList Object
|
(options, self) -> <f> IconList Object
|
||||||
options <o> Options object
|
options <o> Options object
|
||||||
centerSelection <b|false> scroll list so selection is always centered
|
centerSelection <b|false> scroll list so selection is always centered
|
||||||
|
defaultRatio <n|1> aspect ratio of icon placeholders
|
||||||
draggable <b|true> can be dragged
|
draggable <b|true> can be dragged
|
||||||
|
fixedRatio <b|n|false> if set to a number, icons have a fixed ratio
|
||||||
id <s|''> element id
|
id <s|''> element id
|
||||||
item <f|null> called with data, sort, size,
|
item <f|null> called with data, sort, size,
|
||||||
extends data with information needed for constructor
|
extends data with information needed for constructor
|
||||||
|
@ -28,7 +30,9 @@ Ox.IconList = function(options, self) {
|
||||||
var that = Ox.Element({}, self)
|
var that = Ox.Element({}, self)
|
||||||
.defaults({
|
.defaults({
|
||||||
centerSelection: false,
|
centerSelection: false,
|
||||||
|
defaultRatio: 1,
|
||||||
draggable: true,
|
draggable: true,
|
||||||
|
fixedRatio: false,
|
||||||
id: '',
|
id: '',
|
||||||
item: null,
|
item: null,
|
||||||
itemConstructor: Ox.IconItem,
|
itemConstructor: Ox.IconItem,
|
||||||
|
@ -43,6 +47,10 @@ Ox.IconList = function(options, self) {
|
||||||
})
|
})
|
||||||
.options(options || {});
|
.options(options || {});
|
||||||
|
|
||||||
|
if (self.options.fixedRatio) {
|
||||||
|
self.options.defaultRatio = self.options.fixedRatio;
|
||||||
|
}
|
||||||
|
|
||||||
$.extend(self, {
|
$.extend(self, {
|
||||||
itemHeight: self.options.size * 1.5,
|
itemHeight: self.options.size * 1.5,
|
||||||
itemWidth: self.options.size
|
itemWidth: self.options.size
|
||||||
|
@ -78,11 +86,12 @@ Ox.IconList = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function constructItem(data) {
|
function constructItem(data) {
|
||||||
var data = !$.isEmptyObject(data) ?
|
var isEmpty = Ox.isEmpty(data);
|
||||||
self.options.item(data, self.options.sort, self.options.size) :
|
data = !isEmpty ?
|
||||||
{height: 8, width: 5},
|
self.options.item(data, self.options.sort, self.options.size) : {}
|
||||||
ratio = data.width / data.height;
|
ratio = !isEmpty ? data.width / data.height : self.options.defaultRatio;
|
||||||
return self.options.itemConstructor($.extend(data, {
|
return self.options.itemConstructor($.extend(data, {
|
||||||
|
fixedRatio: self.options.fixedRatio,
|
||||||
height: Math.round(self.options.size / (ratio <= 1 ? 1 : ratio)),
|
height: Math.round(self.options.size / (ratio <= 1 ? 1 : ratio)),
|
||||||
size: self.options.size,
|
size: self.options.size,
|
||||||
width: Math.round(self.options.size * (ratio >= 1 ? 1 : ratio))
|
width: Math.round(self.options.size * (ratio >= 1 ? 1 : ratio))
|
||||||
|
|
Loading…
Add table
Reference in a new issue