/*
This file contains proprietary software owned by Motorola Mobility, Inc.
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
*/
/* ComputedStyleSubPanel.js */
var Montage = require("montage").Montage,
Component = require("montage/ui/component").Component;
/*
EDITABLE - Methods
- startEdit
- stopEdit
- value
-
- _suggest
- _suggestNext
- _suggestPrev
- _clearSuggest
- _accept
- _revert
- _setCaret
*/
exports.Editable = Montage.create(Component, {
hasTemplate: { value: false },
_element : { value : null },
element : {
get : function() {
return this._element;
},
set : function(el) {
this._element = el;
this._element.addEventListener('keydown', this, false);
this._element.addEventListener('keyup', this, false);
this._element.addEventListener('input', this, false);
this._element.addEventListener('paste', this, false);
if(this.startOnEvent) {
this._element.addEventListener(this.startOnEvent, this, false);
}
}
},
_readOnly : {
value: false
},
readOnly : {
get : function() { return this._readOnly; },
set : function(makeReadOnly) {
var action = makeReadOnly ? 'add' : 'remove';
this._element.classList[action](this.readOnlyClass);
if(this.isEditable) {
this.stop();
}
this._readOnly = makeReadOnly;
}
},
_isEditable : {
value : false
},
isEditable : {
get : function() {
return this._isEditable;
},
set: function(makeEditable) {
if(this._readOnly && makeEditable) { return false; }
this._isEditable = makeEditable;
}
},
_isDirty : {
value: false
},
isDirty : {
get : function() {
return this._isDirty;
},
set : function(setDirty) {
if(setDirty) {
this._isDirty = true;
this._sendEvent('dirty');
} else {
this._isDirty = false;
}
}
},
_value : { value: null },
value : {
get : function() { return this._value; },
set : function(value) {
if(value === this._value) { return; }
var node = this._getFirstTextNode();
node.textContent = value;
this._value = value;
}
},
_getFirstTextNode : {
value : function(el) {
///// optional el argument specified container element
var e = el || this._element,
nodes = e.childNodes, node;
if(nodes.length) {
for(var i=0; i