From a949ad2cf422bee5ba896ac8ffbdcf75e5f8c0f7 Mon Sep 17 00:00:00 2001
From: rlx <0x0073@0x2620.org>
Date: Thu, 27 Oct 2011 13:13:28 +0000
Subject: [PATCH] use Ox.Editable in Ox.AnnotationPanel
---
source/Ox.UI/css/Ox.UI.css | 4 +-
source/Ox.UI/js/Form/Ox.Editable.js | 41 +++++++++++----------
source/Ox.UI/js/Form/Ox.Input.js | 4 +-
source/Ox.UI/js/Video/Ox.AnnotationPanel.js | 25 +++++++++++--
source/Ox.UI/js/Video/Ox.VideoEditor.js | 6 +--
5 files changed, 53 insertions(+), 27 deletions(-)
diff --git a/source/Ox.UI/css/Ox.UI.css b/source/Ox.UI/css/Ox.UI.css
index d7264183..51020ee8 100644
--- a/source/Ox.UI/css/Ox.UI.css
+++ b/source/Ox.UI/css/Ox.UI.css
@@ -1737,11 +1737,12 @@ Video
.OxAnnotation {
border-width: 0 0 1px 0;
border-style: solid;
- padding: 4px;
+ //padding: 4px 4px 0 4px;
}
.OxAnnotation:last-child {
border-width: 0;
}
+/*
.OxAnnotation.OxEdit {
padding: 0;
}
@@ -1749,6 +1750,7 @@ Video
padding: 4px;
border: 0;
}
+*/
.OxPosterMarker {
position: absolute;
diff --git a/source/Ox.UI/js/Form/Ox.Editable.js b/source/Ox.UI/js/Form/Ox.Editable.js
index e3fd279c..caaae597 100644
--- a/source/Ox.UI/js/Form/Ox.Editable.js
+++ b/source/Ox.UI/js/Form/Ox.Editable.js
@@ -27,7 +27,7 @@ Ox.Editable = function(options, self) {
placeholder: '',
tooltip: '',
value: '',
- width: 256,
+ width: 0,
type: 'input'
})
.options(options || {})
@@ -81,11 +81,13 @@ Ox.Editable = function(options, self) {
}, self.options.type == 'textarea' ? {
width: self.options.width
} : {}))
- .css({display: 'none'})
+ .css({
+ display: 'none',
+ })
.bindEvent({
blur: submit,
cancel: cancel,
- change: change,
+ change: change
//submit: submit
})
//[self.options.editing ? 'show' : 'hide']()
@@ -98,9 +100,13 @@ Ox.Editable = function(options, self) {
}
function cancel() {
- self.$input.hide();
- self.$value.show();
- self.options.editing = false;
+ self.options.value = self.originalValue;
+ self.$input.options({value: formatInputValue()}).hide();
+ self.$test.html(formatTestValue());
+ self.$value.html(formatValue()).show();
+ that.triggerEvent('submit', {
+ value: self.options.value
+ });
}
function change(event) {
@@ -109,10 +115,8 @@ Ox.Editable = function(options, self) {
self.$value.html(formatValue);
self.$test.html(formatTestValue());
height = self.options.height || self.$test.height();
- //height = Math.max(self.$test.height(), 14);
- width = Math.max(self.$test.width() + 2, 8);
- width = Ox.limit(self.$test.width() + 2, self.minWidth, self.maxWidth)
- Ox.print('wxh', width, height)
+ width = self.options.width || Ox.limit(self.$test.width() + 2, self.minWidth, self.maxWidth)
+ Ox.print(self.options.width, self.$test.width(), 'wxh', width, height)
if (self.options.type == 'input') {
self.$input.options({
width: width
@@ -141,6 +145,7 @@ Ox.Editable = function(options, self) {
function edit() {
var height, width;
if (self.options.editable && !self.options.editing) {
+ self.originalValue = self.options.value;
self.minWidth = 8
self.maxWidth = that.parent().width();
Ox.print('MAX WIDTH', self.maxWidth);
@@ -169,6 +174,7 @@ Ox.Editable = function(options, self) {
self.$input.focusInput(false);
}, 0);
self.options.editing = true;
+ that.triggerEvent('edit', {editing: true});
}
}
@@ -179,14 +185,10 @@ Ox.Editable = function(options, self) {
}
function formatTestValue() {
- Ox.print('TEST VALUE =', self.options.type == 'input'
- ? self.options.value.replace(/ /g, ' ')
- : self.options.value.replace(/\n$/, '
')
- .replace(/\n/g, '
'));
return self.options.type == 'input'
? self.options.value.replace(/ /g, ' ')
- : self.options.value.replace(/\n$/, '
')
- .replace(/\n/g, '
');
+ : Ox.parseHTML(self.options.value || ' ')
+ .replace(/
$/, '
');
}
function formatValue() {
@@ -197,9 +199,10 @@ Ox.Editable = function(options, self) {
function submit() {
self.options.value = Ox.parseHTML(self.$input.value());
- self.$input.value(formatInputValue());
- self.$value.html(formatValue());
- cancel();
+ self.$input.options({value: formatInputValue()}).hide();
+ self.$test.html(formatTestValue());
+ self.$value.html(formatValue()).show();
+ self.options.editing = false;
that.triggerEvent('submit', {
value: self.options.value
});
diff --git a/source/Ox.UI/js/Form/Ox.Input.js b/source/Ox.UI/js/Form/Ox.Input.js
index f018f9fb..060968fd 100644
--- a/source/Ox.UI/js/Form/Ox.Input.js
+++ b/source/Ox.UI/js/Form/Ox.Input.js
@@ -103,7 +103,9 @@ Ox.Input = function(options, self) {
)*/
)
.css({width: self.options.width + 'px'})
- .bindEvent(Ox.extend(self.options.type == 'textarea' ? {} : {
+ .bindEvent(Ox.extend(self.options.type == 'textarea' ? {
+ key_shift_enter: submit
+ } : {
key_enter: submit
}, {
key_control_v: paste,
diff --git a/source/Ox.UI/js/Video/Ox.AnnotationPanel.js b/source/Ox.UI/js/Video/Ox.AnnotationPanel.js
index 3c42b029..f5cc50e9 100644
--- a/source/Ox.UI/js/Video/Ox.AnnotationPanel.js
+++ b/source/Ox.UI/js/Video/Ox.AnnotationPanel.js
@@ -55,9 +55,26 @@ Ox.AnnotationPanel = function(options, self) {
self.$annotations = Ox.List({
construct: function(data) {
- return Ox.Element()
- .addClass('OxAnnotation OxEditable OxTarget')
- .html(Ox.parseHTML(data.value));
+ var $item = Ox.Element()
+ .append(
+ Ox.Editable({
+ type: 'textarea',
+ width: self.options.width - 8,
+ value: data.value
+ })
+ .bindEvent({
+ edit: function() {
+ $item.removeClass('OxTarget');
+ },
+ submit: function(data) {
+ $item.addClass('OxTarget')
+ }
+ })
+ )
+ .append($('