forked from 0x2620/oxjs
various annotation-related bugfixes
This commit is contained in:
parent
198e11c59b
commit
a7a3f167c9
10 changed files with 135 additions and 75 deletions
|
|
@ -7,9 +7,7 @@ Ox.ArrayEditable <f> Array Editable Object
|
|||
Ox.ArrayEditable = function(options, self) {
|
||||
|
||||
self = self || {};
|
||||
var that = Ox.Element(options.editable === false ? {} : {
|
||||
tooltip: 'Doubleclick to add ' + (options.itemName || 'item')
|
||||
}, self)
|
||||
var that = Ox.Element({}, self)
|
||||
.defaults({
|
||||
clickLink: null,
|
||||
editable: true,
|
||||
|
|
@ -29,8 +27,6 @@ Ox.ArrayEditable = function(options, self) {
|
|||
.addClass('OxArrayEditable OxArrayEditable' + Ox.toTitleCase(self.options.type))
|
||||
.css({width: self.options.width - (self.options.type == 'input' ? 8 : 0) + 'px'}) // 2 x 4 px padding
|
||||
.bindEvent({
|
||||
anyclick: anyclick,
|
||||
doubleclick: doubleclick,
|
||||
key_delete: deleteItem,
|
||||
key_enter: function() {
|
||||
// make sure the newline does
|
||||
|
|
@ -43,7 +39,8 @@ Ox.ArrayEditable = function(options, self) {
|
|||
key_down: self.options.type == 'input' ? selectLast : selectNext,
|
||||
key_left: self.options.type == 'input' ? selectPrevious : selectFirst,
|
||||
key_right: self.options.type == 'input' ? selectNext : selectLast,
|
||||
key_up: self.options.type == 'input' ? selectFirst : selectPrevious
|
||||
key_up: self.options.type == 'input' ? selectFirst : selectPrevious,
|
||||
singleclick: singleclick
|
||||
});
|
||||
|
||||
self.$items = [];
|
||||
|
|
@ -53,35 +50,6 @@ Ox.ArrayEditable = function(options, self) {
|
|||
|
||||
self.selected = getSelectedPosition();
|
||||
|
||||
function anyclick(e) {
|
||||
Ox.print('SELF EDITING', self.editing)
|
||||
var $target = $(e.target),
|
||||
$parent = $target.parent(),
|
||||
position = $parent.data('position');
|
||||
if (!$target.is('.OxInput')) {
|
||||
Ox.print('BLURRED EDITING', self.blurred, self.editing)
|
||||
if ($parent.is('.OxEditableElement')) {
|
||||
if (!$parent.is('.OxSelected')) {
|
||||
// select another item
|
||||
selectItem(
|
||||
e.metaKey && position == self.selected
|
||||
? '' : $parent.data('position')
|
||||
);
|
||||
}
|
||||
} else if (!self.blurred) {
|
||||
// if there wasn't an active input element
|
||||
if (self.editing) {
|
||||
// blur if still in editing mode
|
||||
that.blurItem();
|
||||
} else {
|
||||
// othewise deselect selected
|
||||
selectNone();
|
||||
}
|
||||
}
|
||||
that.gainFocus();
|
||||
}
|
||||
}
|
||||
|
||||
function deleteItem() {
|
||||
if (self.options.editable) {
|
||||
self.options.items.splice(self.selected, 1);
|
||||
|
|
@ -95,6 +63,7 @@ Ox.ArrayEditable = function(options, self) {
|
|||
}
|
||||
|
||||
function doubleclick(e) {
|
||||
// fixme: unused
|
||||
var $target = $(e.target),
|
||||
$parent = $target.parent();
|
||||
if ($parent.is('.OxEditableElement')) {
|
||||
|
|
@ -119,9 +88,8 @@ Ox.ArrayEditable = function(options, self) {
|
|||
that.empty();
|
||||
if (self.options.items.length == 0) {
|
||||
Ox.Editable({
|
||||
clickLink: self.options.clickLink,
|
||||
editable: false,
|
||||
type: 'text',
|
||||
type: self.options.type,
|
||||
value: self.options.placeholder
|
||||
})
|
||||
.addClass('OxPlaceholder')
|
||||
|
|
@ -182,6 +150,9 @@ Ox.ArrayEditable = function(options, self) {
|
|||
});
|
||||
},
|
||||
edit: function(data) {
|
||||
if (item.id != self.options.selected) {
|
||||
selectItem(item.id);
|
||||
}
|
||||
self.editing = true;
|
||||
that.triggerEvent('edit', data);
|
||||
},
|
||||
|
|
@ -237,6 +208,33 @@ Ox.ArrayEditable = function(options, self) {
|
|||
self.selected > 0 && selectItem(self.selected - 1);
|
||||
}
|
||||
|
||||
function singleclick(e) {
|
||||
var $target = $(e.target),
|
||||
$element = $target.parents('.OxEditableElement'),
|
||||
position = $element.data('position');
|
||||
if (!$target.is('.OxInput')) {
|
||||
if ($element.length) {
|
||||
if (!$element.is('.OxSelected')) {
|
||||
// select another item
|
||||
selectItem(
|
||||
e.metaKey && position == self.selected
|
||||
? '' : position
|
||||
);
|
||||
}
|
||||
} else if (!self.blurred) {
|
||||
// if there wasn't an active input element
|
||||
if (self.editing) {
|
||||
// blur if still in editing mode
|
||||
that.blurItem();
|
||||
} else {
|
||||
// othewise deselect selected
|
||||
selectNone();
|
||||
}
|
||||
}
|
||||
that.gainFocus();
|
||||
}
|
||||
}
|
||||
|
||||
function sortItems() {
|
||||
if (!Ox.isEmpty(self.options.sort)) {
|
||||
self.options.items = Ox.sortBy(self.options.items, self.options.sort);
|
||||
|
|
|
|||
|
|
@ -43,13 +43,8 @@ Ox.Editable = function(options, self) {
|
|||
.bindEvent({
|
||||
doubleclick: edit,
|
||||
singleclick: function(e) {
|
||||
var $target = $(e.target),
|
||||
$parent = $target.parent();
|
||||
while(!$target.is('a') && !$parent.is('.OxEditableElement')) {
|
||||
$target = $parent;
|
||||
$parent = $target.parent();
|
||||
}
|
||||
if($target.is('a')) {
|
||||
var $target = $(e.target);
|
||||
if ($target.is('a') || ($target = $target.parents('a')).length) {
|
||||
if (self.options.clickLink) {
|
||||
e.target = $target[0];
|
||||
self.options.clickLink(e);
|
||||
|
|
@ -107,6 +102,7 @@ Ox.Editable = function(options, self) {
|
|||
function edit() {
|
||||
var height, width;
|
||||
if (self.options.editable && !self.options.editing) {
|
||||
Ox.print('EDIT???')
|
||||
self.options.editing = true;
|
||||
that.addClass('OxEditing');
|
||||
self.originalValue = self.options.value;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue