forked from 0x2620/oxjs
some documentation
This commit is contained in:
parent
275dcbb356
commit
bdb8d98787
45 changed files with 775 additions and 255 deletions
|
|
@ -1,52 +1,61 @@
|
|||
// vim: et:ts=4:sw=4:sts=4:ft=js
|
||||
|
||||
/*@
|
||||
Basic list object
|
||||
(options) -> that
|
||||
(options, self) -> that
|
||||
options <obj> the list's options
|
||||
self <obj> shared private variable
|
||||
Ox.List <f:Ox.Element> List Element
|
||||
() -> <f> List Object
|
||||
(options) -> <f> List Object
|
||||
(options, self) -> <f> List Object
|
||||
options <o> Options object
|
||||
centered <b|false> if true, and orientation is 'horizontal',
|
||||
then keep the selected item centered
|
||||
construct <f|null> (data) returns the list item HTML
|
||||
draggable <b|false> true if the items can be reordered
|
||||
format <[]> ???
|
||||
itemHeight <n|16> item height
|
||||
items <a|f|null> <a> list of items,
|
||||
<f> (data) returns {items, size, ...}
|
||||
(data, callback) returns [items]
|
||||
itemWidth <n|16> item width
|
||||
keys <a|[]> keys of the list items
|
||||
max <n|-1> max number of items that can be selected
|
||||
min <n|0> min number of items that must be selected
|
||||
orientation <s|vertical> 'horizontal' or 'vertical'
|
||||
pageLength <n|100> number of items per page
|
||||
selected <a|[]> ids of the selected elements
|
||||
sort <a|[]> sort order
|
||||
sortable <b|false>
|
||||
type <s|text>
|
||||
unique <s|''> name of the key that acts as unique id
|
||||
self <o> shared private variable
|
||||
|
||||
@*/
|
||||
|
||||
|
||||
Ox.List = function(options, self) {
|
||||
|
||||
/***
|
||||
basic list object
|
||||
Options
|
||||
centered boolean if true, and orientation is 'horizontal',
|
||||
then keep the selected item centered
|
||||
construct function function(data), returns the list item HTML
|
||||
items function function(callback) returns {items, size, ...}
|
||||
function(data, callback) returns [items]
|
||||
or array of items
|
||||
Methods
|
||||
Events
|
||||
***/
|
||||
|
||||
var self = self || {},
|
||||
that = new Ox.Container({}, self)
|
||||
.defaults({
|
||||
centered: false, //@ <boo> if true, and orientation is 'horizontal',
|
||||
//@ then keep the selected item centered
|
||||
construct: null, //@ <fun> (data) returns the list item HTML
|
||||
draggable: false, //@ <boo> true if the items can be reordered
|
||||
format: [], //@ <arr> ???
|
||||
itemHeight: 16, //@ <num> item height
|
||||
items: null, //@ <arr> list items
|
||||
//@ <fun> (data) returns {items, size, ...}
|
||||
//@ (data, callback) returns [items]
|
||||
itemWidth: 16, //@ <num> item width
|
||||
keys: [], //@ <arr> keys of the list items
|
||||
max: -1, //@ <num> max number of items that can be selected
|
||||
min: 0, //@ <num> min number of items that must be selected
|
||||
orientation: 'vertical', //@ <str> 'horizontal' or 'vertical'
|
||||
pageLength: 100, //@ <num> number of items per page
|
||||
selected: [], //@ <arr> ids of the selected elements
|
||||
sort: [], //@ <arr>
|
||||
sortable: false, //@ <boo>
|
||||
type: 'text', //@ <str>
|
||||
unique: '' //@ <str> name of the key that acts as unique id
|
||||
centered: false,
|
||||
|
||||
construct: null,
|
||||
draggable: false,
|
||||
format: [],
|
||||
itemHeight: 16,
|
||||
items: null,
|
||||
|
||||
|
||||
itemWidth: 16,
|
||||
keys: [],
|
||||
max: -1,
|
||||
min: 0,
|
||||
orientation: 'vertical',
|
||||
pageLength: 100,
|
||||
selected: [],
|
||||
sort: [],
|
||||
sortable: false,
|
||||
type: 'text',
|
||||
unique: ''
|
||||
})
|
||||
.options(options || {})
|
||||
.scroll(scroll);
|
||||
|
|
@ -265,7 +274,7 @@ Ox.List = function(options, self) {
|
|||
// fixme: why does chainging fail here?
|
||||
new Ox.ListItem({
|
||||
construct: self.options.construct
|
||||
}).appendTo($page);
|
||||
}).appendTo($page);
|
||||
}
|
||||
//Ox.print('cEP done')
|
||||
return $page;
|
||||
|
|
@ -1070,7 +1079,7 @@ Ox.List = function(options, self) {
|
|||
self.selected.splice(self.selected.indexOf(pos), 1);
|
||||
!Ox.isUndefined(self.$items[pos]) &&
|
||||
self.$items[pos].removeClass('OxSelected');
|
||||
}
|
||||
}
|
||||
});
|
||||
ids.forEach(function(id, i) {
|
||||
var pos = getPositionById(id);
|
||||
|
|
@ -1232,6 +1241,12 @@ Ox.List = function(options, self) {
|
|||
}
|
||||
};
|
||||
|
||||
/*@
|
||||
addItems <f> add item to list
|
||||
(pos, items) -> <u> add items to list at position
|
||||
pos <n> position to add items
|
||||
items <a> array of items ot add
|
||||
@*/
|
||||
that.addItems = function(pos, items) {
|
||||
var $items = [],
|
||||
length = items.length
|
||||
|
|
@ -1268,6 +1283,11 @@ Ox.List = function(options, self) {
|
|||
updatePositions();
|
||||
}
|
||||
|
||||
/*@
|
||||
editItem <f> turn item into edit form
|
||||
(pos) -> <u> edit item at position
|
||||
pos <n> position of item to edit
|
||||
@*/
|
||||
that.editItem = function(pos) {
|
||||
var $input,
|
||||
item = self.options.items[pos],
|
||||
|
|
@ -1307,26 +1327,47 @@ Ox.List = function(options, self) {
|
|||
}
|
||||
}
|
||||
|
||||
/*@
|
||||
clearCache <f> empy list cache
|
||||
() -> <f> empy cache, returns List Element
|
||||
@*/
|
||||
that.clearCache = function() { // fixme: was used by TextList resizeColumn, now probably no longer necessary
|
||||
self.$pages = [];
|
||||
return that;
|
||||
};
|
||||
|
||||
/*@
|
||||
closePreview <f> close preview
|
||||
() -> <f> close preview, returns List Element
|
||||
@*/
|
||||
that.closePreview = function() {
|
||||
self.preview = false;
|
||||
return that;
|
||||
};
|
||||
|
||||
/*@
|
||||
paste <f> paste data
|
||||
(data) -> <f> paste data into list
|
||||
data <o> paste object
|
||||
@*/
|
||||
that.paste = function(data) {
|
||||
pasteItems(data);
|
||||
return that;
|
||||
};
|
||||
|
||||
/*@
|
||||
reloadList <f> reload list contents
|
||||
() -> <f> returns List Element
|
||||
@*/
|
||||
that.reloadList = function() {
|
||||
updateQuery();
|
||||
return that;
|
||||
};
|
||||
|
||||
/*@
|
||||
reloadPages <f> reload list pages
|
||||
() -> <f> returns List Element
|
||||
@*/
|
||||
that.reloadPages = function() {
|
||||
//Ox.print('---------------- list reload, page', self.page)
|
||||
var page = self.page;
|
||||
|
|
@ -1337,12 +1378,15 @@ Ox.List = function(options, self) {
|
|||
return that;
|
||||
};
|
||||
|
||||
/*@
|
||||
removeItems <f> remove items from list
|
||||
(ids) -> <u> remove items
|
||||
(pos, length) -> <u> remove items
|
||||
ids <a> array of item ids
|
||||
pos <n> delete items starting at this position
|
||||
length <n> number of items to remove
|
||||
@*/
|
||||
that.removeItems = function(pos, length) {
|
||||
/*
|
||||
removeItems(ids)
|
||||
or
|
||||
removeItems(pos, length)
|
||||
*/
|
||||
if(!length) { //pos is list of ids
|
||||
pos.forEach(function(id) {
|
||||
var p = getPositionById(id);
|
||||
|
|
@ -1363,12 +1407,19 @@ Ox.List = function(options, self) {
|
|||
updatePositions();
|
||||
}
|
||||
}
|
||||
|
||||
/*@
|
||||
scrollToSelection <f> scroll list to current selection
|
||||
() -> <f> returns List Element
|
||||
@*/
|
||||
that.scrollToSelection = function() {
|
||||
self.selected.length && scrollToPosition(self.selected[0]);
|
||||
return that;
|
||||
};
|
||||
|
||||
/*@
|
||||
size <f> fixme: not a good function name
|
||||
() -> <f> returns List Element
|
||||
@*/
|
||||
that.size = function() { // fixme: not a good function name
|
||||
if (self.options.orientation == 'both') {
|
||||
var rowLength = getRowLength(),
|
||||
|
|
@ -1404,6 +1455,12 @@ Ox.List = function(options, self) {
|
|||
return that;
|
||||
}
|
||||
|
||||
/*@
|
||||
sortList <f> sort list
|
||||
(key, operator) -> <f> returns List Element
|
||||
key <s> key to sort list by
|
||||
operator <s> +/- sort ascending or descending
|
||||
@*/
|
||||
that.sortList = function(key, operator) {
|
||||
Ox.print('sortList', key, operator)
|
||||
if (key != self.options.sort[0].key || operator != self.options.sort[0].operator) {
|
||||
|
|
@ -1414,6 +1471,15 @@ Ox.List = function(options, self) {
|
|||
return that;
|
||||
}
|
||||
|
||||
/*@
|
||||
value <f> get/set list value
|
||||
(id, key, value) -> <f> sets value, returns List Element
|
||||
(id, key) -> <a> returns value
|
||||
(id) -> <o> returns all values of id
|
||||
id <s> id of item
|
||||
key <s> key if item property
|
||||
value <s> value, can be whatever that property is
|
||||
@*/
|
||||
that.value = function(id, key, value) {
|
||||
var pos = getPositionById(id),
|
||||
$item = self.$items[pos],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue