Ox.EditableContent: self.editing -> self.options.editiing

This commit is contained in:
rolux 2013-02-26 10:42:43 +05:30
parent 0aa4c42ecf
commit 5b5a133533

View file

@ -8,7 +8,13 @@ Ox.EditableContent = function(options, self) {
.defaults({ .defaults({
clickLink: null, clickLink: null,
editable: true, editable: true,
editing: false,
format: null,
highlight: null,
placeholder: '', placeholder: '',
replaceTags: {},
submitOnBlur: true,
tags: null,
tooltip: '', tooltip: '',
type: 'span', type: 'span',
value: '' value: ''
@ -16,10 +22,10 @@ Ox.EditableContent = function(options, self) {
.options(options || {}) .options(options || {})
.update({ .update({
highlight: function() { highlight: function() {
!self.editing && self.$value.html(formatValue()); !self.options.editing && self.$value.html(formatValue());
}, },
value: function() { value: function() {
!self.editing && self.$value.html(formatValue()); !self.options.editing && self.$value.html(formatValue());
} }
}) })
.addClass('OxEditableContent') .addClass('OxEditableContent')
@ -44,14 +50,12 @@ Ox.EditableContent = function(options, self) {
self.options.value = self.options.value.toString(); self.options.value = self.options.value.toString();
self.editing = false;
self.$value = Ox.Element(self.options.type == 'span' ? '<span>' : '<div>') self.$value = Ox.Element(self.options.type == 'span' ? '<span>' : '<div>')
.html(formatValue(self.options.value)) .html(formatValue())
.on({ .on({
blur: submit, blur: submit,
keydown: function(e) { keydown: function(e) {
if (self.editing) { if (self.options.editing) {
if (self.options.type == 'span' && e.keyCode == 13) { if (self.options.type == 'span' && e.keyCode == 13) {
submit(); submit();
return false; return false;
@ -63,11 +67,15 @@ Ox.EditableContent = function(options, self) {
} }
}) })
.appendTo(that); .appendTo(that);
function blur() {
}
function cancel() { function cancel() {
if (self.editing) { if (self.options.editing) {
that.loseFocus(); that.loseFocus();
self.editing = false; self.options.editing = false;
self.$value self.$value
.attr({contenteditable: false}) .attr({contenteditable: false})
.removeClass('OxEditableContentInput') .removeClass('OxEditableContentInput')
@ -77,7 +85,7 @@ Ox.EditableContent = function(options, self) {
} }
function edit() { function edit() {
if (self.options.editable && !self.editing) { if (self.options.editable && !self.options.editing) {
var value = formatInputValue(); var value = formatInputValue();
self.$value self.$value
.addClass('OxEditableContentInput') .addClass('OxEditableContentInput')
@ -87,7 +95,7 @@ Ox.EditableContent = function(options, self) {
} else { } else {
self.$value.html('&nbsp;'); self.$value.html('&nbsp;');
} }
self.editing = true; self.options.editing = true;
that.gainFocus(); that.gainFocus();
setTimeout(updateSelection, 50); setTimeout(updateSelection, 50);
} }
@ -132,9 +140,9 @@ Ox.EditableContent = function(options, self) {
} }
function submit() { function submit() {
if (self.editing) { if (self.options.editing) {
that.loseFocus(); that.loseFocus();
self.editing = false; self.options.editing = false;
self.options.value = self.$value.text(); self.options.value = self.$value.text();
if (self.options.value.charCodeAt(0) == 160) { if (self.options.value.charCodeAt(0) == 160) {
self.options.value = ''; self.options.value = '';
@ -146,6 +154,7 @@ Ox.EditableContent = function(options, self) {
that.triggerEvent('submit', {value: self.options.value}); that.triggerEvent('submit', {value: self.options.value});
} }
} }
function updateSelection() { function updateSelection() {
var range, selection; var range, selection;
self.$value[0].focus(); self.$value[0].focus();