1
0
Fork 0
forked from 0x2620/oxjs

- remove editItem from Ox.List

- use ArrayEditable for text too
This commit is contained in:
j 2012-01-04 22:57:32 +05:30
commit 093edd57d0
12 changed files with 180 additions and 403 deletions

View file

@ -16,6 +16,7 @@ Ox.ArrayEditable = function(options, self) {
items: [],
position: -1,
selected: '',
type: 'input',
width: 256
})
.options(options || {})
@ -40,10 +41,14 @@ Ox.ArrayEditable = function(options, self) {
function anyclick(e) {
var $target = $(e.target),
$parent = $target.parent();
$target.is(':not(input)') && that.gainFocus();
$parent = $target.parent(),
position = $parent.data('position');
!$target.is('.OxInput') && that.gainFocus();
if ($parent.is('.OxEditableElement')) {
selectItem($parent.data('position'));
selectItem(
e.metaKey && position == self.selected
? -1 : $parent.data('position')
);
} else {
selectNone();
}
@ -58,10 +63,11 @@ Ox.ArrayEditable = function(options, self) {
}
function doubleclick(e) {
var $parent = $(e.target).parent();
var $target = $(e.target),
$parent = $target.parent();
if ($parent.is('.OxEditableElement')) {
that.editItem(self.options.selected);
} else {
} else if(!$target.is('.OxInput')) {
that.triggerEvent('add');
}
}
@ -88,9 +94,10 @@ Ox.ArrayEditable = function(options, self) {
function renderItems() {
that.empty();
self.options.items.forEach(function(item, i) {
i && $('<span>')
.html(', ')
.appendTo(that);
i && self.options.type == 'input'
&& $('<span>')
.html(', ')
.appendTo(that);
self.$items[i] = Ox.Editable({
editable: item.editable,
format: function(value) {
@ -99,13 +106,18 @@ Ox.ArrayEditable = function(options, self) {
tooltip: 'Click to select' + (
item.editable ? ', doubleclick to edit' : ''
),
value: item.value
type: self.options.type,
value: item.value,
width: self.options.type == 'input' ? 0 : self.options.width
})
.addClass(item.id == self.options.selected ? 'OxSelected' : '')
.data({position: i})
.bindEvent({
cancel: function(data) {
},
edit: function(data) {
that.triggerEvent('edit', data);
},
submit: function(data) {
submit(i, data.value);
@ -159,6 +171,8 @@ Ox.ArrayEditable = function(options, self) {
self.setOption = function(key, value) {
if (key == 'items') {
renderItems();
} else if (key == 'selected') {
that.selectItem(value);
}
}