53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
/*@
|
|
Ox.ListItem <f:Ox.Element> ListItem Object
|
|
([options[, self]]) -> <o> ListItem Object
|
|
options <o> Options object
|
|
construct <f> construct function
|
|
data <o|{}> item data
|
|
draggable <b|false> can be dragged
|
|
position <n|0> item position
|
|
unique <s|''> unique key
|
|
self <o> shared private variable
|
|
cancel <!> triggered if cancel button is pressed
|
|
save <!> triggered if save button is pressed
|
|
@*/
|
|
|
|
Ox.ListItem = function(options, self) {
|
|
|
|
self = self || {};
|
|
var that = Ox.Element({}, self)
|
|
.defaults({
|
|
construct: null,
|
|
data: {},
|
|
draggable: false,
|
|
position: 0,
|
|
unique: ''
|
|
})
|
|
.options(options || {});
|
|
|
|
constructItem();
|
|
|
|
function constructItem(update) {
|
|
var $element = self.options.construct(self.options.data)
|
|
.addClass('OxItem')
|
|
.data({
|
|
id: self.options.data[self.options.unique],
|
|
position: self.options.position
|
|
});
|
|
if (update) {
|
|
that.$element.hasClass('OxSelected') && $element.addClass('OxSelected');
|
|
}
|
|
that.setElement($element);
|
|
}
|
|
|
|
self.setOption = function(key, value) {
|
|
if (key == 'data') {
|
|
constructItem(true);
|
|
}
|
|
};
|
|
|
|
return that;
|
|
|
|
};
|