fix some bugs in insert html dialog

This commit is contained in:
rlx 2012-02-16 18:04:25 +00:00
parent e1d8e2aeea
commit 7d4fd8f706
2 changed files with 33 additions and 8 deletions

View file

@ -12,6 +12,9 @@ Ox.InsertHTMLDialog = function(options, self) {
start: 0 start: 0
}, options || {}); }, options || {});
self.type = self.options.selection.indexOf('\n') > -1
? 'textarea' : 'input';
self.items = [ self.items = [
{id: 'img', title: 'Image'}, {id: 'img', title: 'Image'},
{id: 'a', title: 'Link'}, {id: 'a', title: 'Link'},
@ -48,12 +51,15 @@ Ox.InsertHTMLDialog = function(options, self) {
} else if (item.id == 'a') { } else if (item.id == 'a') {
form = [ form = [
Ox.Input({ Ox.Input({
height: 104,
id: 'text', id: 'text',
label: 'Text', label: 'Text',
labelWidth: 128, labelWidth: 128,
type: self.type,
width: 384, width: 384,
value: self.options.selection value: self.options.selection
}), })
.css({background: 'transparent'}),
Ox.Input({ Ox.Input({
id: 'url', id: 'url',
label: 'URL', label: 'URL',
@ -80,6 +86,7 @@ Ox.InsertHTMLDialog = function(options, self) {
id: 'items', id: 'items',
label: 'Items', label: 'Items',
max: 10, max: 10,
value: self.options.selection.split('\n'),
width: 384 width: 384
}) })
]; ];
@ -91,12 +98,15 @@ Ox.InsertHTMLDialog = function(options, self) {
} else if (['p', 'blockquote', 'div'].indexOf(item.id) > -1) { } else if (['p', 'blockquote', 'div'].indexOf(item.id) > -1) {
form = [ form = [
Ox.Input({ Ox.Input({
id: 'text',
height: 128, height: 128,
id: 'text',
label: 'Text',
labelWidth: 128,
type: 'textarea', type: 'textarea',
width: 384, value: self.options.selection,
value: self.options.selection width: 384
}) })
.css({background: 'transparent'})
]; ];
format = function(values) { format = function(values) {
return '<' + item.id + ( return '<' + item.id + (
@ -104,14 +114,18 @@ Ox.InsertHTMLDialog = function(options, self) {
) + '>' + values.text + '</' + item.id + '>'; ) + '>' + values.text + '</' + item.id + '>';
}; };
} else if (['h1', 'b', 'i', 'code', 's', 'sub', 'sup', 'u'].indexOf(item.id) > -1) { } else if (['h1', 'b', 'i', 'code', 's', 'sub', 'sup', 'u'].indexOf(item.id) > -1) {
Ox.print(self.options.selection.indexOf('\n'), '?????????')
form = [ form = [
Ox.Input({ Ox.Input({
height: 128,
id: 'text', id: 'text',
label: 'Text', label: 'Text',
labelWidth: 128, labelWidth: 128,
width: 384, type: self.type,
value: self.options.selection value: self.options.selection,
width: 384
}) })
.css({background: 'transparent'})
]; ];
format = function(values) { format = function(values) {
return '<' + item.id + '>' + values.text + '</' + item.id + '>'; return '<' + item.id + '>' + values.text + '</' + item.id + '>';
@ -164,7 +178,6 @@ Ox.InsertHTMLDialog = function(options, self) {
}) })
.bindEvent({ .bindEvent({
click: function() { click: function() {
Ox.print('SFV:::::', self.$form.values())
var item = Ox.getObjectById(self.items, self.$select.value()), var item = Ox.getObjectById(self.items, self.$select.value()),
value = item.format( value = item.format(
item.form.length ? self.$form.values() : void 0 item.form.length ? self.$form.values() : void 0
@ -179,6 +192,7 @@ Ox.InsertHTMLDialog = function(options, self) {
} }
}) })
], ],
closeButton: true,
content: self.$content, content: self.$content,
height: 184, height: 184,
keys: {enter: 'insert', escape: 'cancel'}, keys: {enter: 'insert', escape: 'cancel'},
@ -188,6 +202,7 @@ Ox.InsertHTMLDialog = function(options, self) {
function renderForm() { function renderForm() {
var items = Ox.getObjectById(self.items, self.$select.value()).form; var items = Ox.getObjectById(self.items, self.$select.value()).form;
Ox.print('??::""""????', self.$select.value())
self.$form && self.$form.remove(); self.$form && self.$form.remove();
if (items.length) { if (items.length) {
self.$form = Ox.Form({ self.$form = Ox.Form({

View file

@ -258,6 +258,7 @@ Ox.AnnotationPanel = function(options, self) {
} }
function insert(data) { function insert(data) {
Ox.print('insert', data);
var id = data.id; var id = data.id;
Ox.InsertHTMLDialog(Ox.extend({ Ox.InsertHTMLDialog(Ox.extend({
callback: function(data) { callback: function(data) {
@ -334,7 +335,16 @@ Ox.AnnotationPanel = function(options, self) {
} else if (data.id == 'findannotations') { } else if (data.id == 'findannotations') {
that.triggerEvent('findannotations', {key: key, value: value}); that.triggerEvent('findannotations', {key: key, value: value});
} else if (data.id == 'insert') { } else if (data.id == 'insert') {
insert({}); var id = $('.OxEditableElement div.OxInput').data('oxid'),
element = $('.OxEditableElement textarea.OxInput')[0];
insert({
end: element.selectionEnd,
id: id,
selection: element.value
.substr(element.selectionStart, element.selectionEnd),
start: element.selectionStart,
value: element.value
});
} else if (data.id == 'manage') { } else if (data.id == 'manage') {
that.triggerEvent('define', { that.triggerEvent('define', {
id: self.options.selected, id: self.options.selected,