slightly improved treelist
This commit is contained in:
parent
ffa8f1738a
commit
baf0f72912
1 changed files with 15 additions and 12 deletions
|
@ -31,10 +31,7 @@ Ox.TreeList = function(options, self) {
|
||||||
selected: [],
|
selected: [],
|
||||||
width: 256
|
width: 256
|
||||||
})
|
})
|
||||||
.options(options || {})
|
.options(options || {});
|
||||||
.bindEvent({
|
|
||||||
select: selectItem
|
|
||||||
});
|
|
||||||
|
|
||||||
if (self.options.data) {
|
if (self.options.data) {
|
||||||
self.options.items = [];
|
self.options.items = [];
|
||||||
|
@ -62,10 +59,13 @@ Ox.TreeList = function(options, self) {
|
||||||
})
|
})
|
||||||
.bindEvent({
|
.bindEvent({
|
||||||
anyclick: clickItem,
|
anyclick: clickItem,
|
||||||
|
select: selectItem,
|
||||||
toggle: toggleItems
|
toggle: toggleItems
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
self.options.selected.length && selectItem({ids: self.options.selected});
|
||||||
|
|
||||||
function clickItem(e) {
|
function clickItem(e) {
|
||||||
var $target = $(e.target),
|
var $target = $(e.target),
|
||||||
$item, id, item;
|
$item, id, item;
|
||||||
|
@ -107,7 +107,7 @@ Ox.TreeList = function(options, self) {
|
||||||
.appendTo($item);
|
.appendTo($item);
|
||||||
}
|
}
|
||||||
$('<div>')
|
$('<div>')
|
||||||
.addClass('OxCell OxTarget'+(!data.items?' OxSelectable':''))
|
.addClass('OxCell OxTarget' + (!data.items ? ' OxSelectable' : ''))
|
||||||
.css({
|
.css({
|
||||||
width: (self.options.width - padding - 32 + !data.items * 16) + 'px'
|
width: (self.options.width - padding - 32 + !data.items * 16) + 'px'
|
||||||
})
|
})
|
||||||
|
@ -140,13 +140,13 @@ Ox.TreeList = function(options, self) {
|
||||||
function getParent(id, items) {
|
function getParent(id, items) {
|
||||||
var ret;
|
var ret;
|
||||||
Ox.forEach(items, function(item) {
|
Ox.forEach(items, function(item) {
|
||||||
if(item.items) {
|
if (item.items) {
|
||||||
if(Ox.getObjectById(item.items, id)) {
|
if (Ox.getObjectById(item.items, id)) {
|
||||||
ret = item.id;
|
ret = item.id;
|
||||||
} else {
|
} else {
|
||||||
ret = getParent(id, item.items);
|
ret = getParent(id, item.items);
|
||||||
}
|
}
|
||||||
if(ret) {
|
if (ret) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,6 @@ Ox.TreeList = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseData(key, value) {
|
function parseData(key, value) {
|
||||||
//Ox.Log('List', 'parseData', key, value)
|
|
||||||
var ret = {
|
var ret = {
|
||||||
expanded: false,
|
expanded: false,
|
||||||
id: Ox.uid().toString(),
|
id: Ox.uid().toString(),
|
||||||
|
@ -199,8 +198,8 @@ Ox.TreeList = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectItem(data) {
|
function selectItem(data) {
|
||||||
var id = data.ids[0], parent = id, parents=[];
|
var id = data.ids[0], parent = id, parents = [];
|
||||||
while(parent = getParent(parent, self.options.items)) {
|
while (parent = getParent(parent, self.options.items)) {
|
||||||
parents.push(parent);
|
parents.push(parent);
|
||||||
}
|
}
|
||||||
parents = parents.reverse();
|
parents = parents.reverse();
|
||||||
|
@ -208,7 +207,9 @@ Ox.TreeList = function(options, self) {
|
||||||
expanded: true,
|
expanded: true,
|
||||||
ids: parents
|
ids: parents
|
||||||
});
|
});
|
||||||
|
self.$list.options({selected: data.ids})
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleItem(item, expanded) {
|
function toggleItem(item, expanded) {
|
||||||
var $img, pos;
|
var $img, pos;
|
||||||
item.expanded = expanded;
|
item.expanded = expanded;
|
||||||
|
@ -248,7 +249,9 @@ Ox.TreeList = function(options, self) {
|
||||||
if (key == 'data') {
|
if (key == 'data') {
|
||||||
// ...
|
// ...
|
||||||
} else if (key == 'selected') {
|
} else if (key == 'selected') {
|
||||||
self.$list.options({selected: value});
|
//self.$list.options({selected: value});
|
||||||
|
selectItem({ids: value});
|
||||||
|
self.$list.scrollToSelection();
|
||||||
} else if (key == 'width') {
|
} else if (key == 'width') {
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue