41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
Ox.ListItem = function(options, self) {
|
|
|
|
var self = self || {},
|
|
that = new Ox.Element({}, self)
|
|
.defaults({
|
|
construct: function() {},
|
|
data: {},
|
|
draggable: false,
|
|
position: 0,
|
|
unique: ''
|
|
})
|
|
.options(options || {});
|
|
|
|
constructItem();
|
|
|
|
function constructItem(update) {
|
|
var $element = self.options.construct(self.options.data)
|
|
.addClass('OxItem')
|
|
.attr({
|
|
draggable: self.options.draggable
|
|
})
|
|
.data({
|
|
id: self.options.data[self.options.unique],
|
|
position: self.options.position
|
|
});
|
|
if (update) {
|
|
that.$element.hasClass('OxSelected') && $element.addClass('OxSelected');
|
|
that.$element.replaceWith($element);
|
|
}
|
|
that.$element = $element;
|
|
}
|
|
|
|
self.onChange = function(key, value) {
|
|
if (key == 'data') {
|
|
constructItem(true);
|
|
}
|
|
}
|
|
|
|
return that;
|
|
|
|
};
|