r3094 committed - inlineEdit: added a value method and minor refactor

r3094 committed - inlineEdit: added a value method and minor refactor


Revision: 3094
Author: pazu2k@gmail.com
Date: Wed Aug 19 21:25:09 2009
Log: inlineEdit: added a value method and minor refactor
http://code.google.com/p/jquery-ui/source/detail?r=3094
Modified:
/branches/labs/inlineedit/ui.inlineEdit.js
=======================================
--- /branches/labs/inlineedit/ui.inlineEdit.js    Wed Aug 19 09:14:22 2009
+++ /branches/labs/inlineedit/ui.inlineEdit.js    Wed Aug 19 21:25:09 2009
@@ -1,23 +1,28 @@
(function($) {
$.widget('ui.inlineEdit', {
-    _init: function() {
-
- var self = this,
+    _init: function() {
+ this.value(this.element.text() || this.options.value);
+        this._delegate();
+        this._hover(this.options.hover);
+    },
+    _delegate: function() {
+ var self = this,
            originalElement = this.element[0];
- this.options.value = this.element.text() || this.options.value;
-
        this.element.bind('click', function(event) {
            var $this = $(event.target);
- if ($this.is('button')) {
+
+            if ($this.is('button')) {
                self._save(event, $this.siblings('input').val());
- } else if ($this.is(originalElement.tagName)) {
+                return;
+ }
+
+            if ($this.is(originalElement.tagName)) {
                self._render();
- }
- });
-
-        this._hover(this.options.hover);
+                return;
+ }
+ });
    },
    _hover: function(hover) {
        this.element.hover(function(){
@@ -27,7 +32,7 @@
});
    },
    _uiInlineEditHtml: function() {
-        return '<form><input type="text" value="'+ this.options.value +'">
<button type="button">'+ this.options.label +'</button></form>';
+        return '<form><input type="text" value="'+ this.value() +'"> <button
type="button">'+ this.options.label +'</button></form>';
    },
    _render: function() {
this.element.html(this._uiInlineEditHtml());
@@ -52,20 +57,27 @@
window.clearTimeout(self.timer);
}
self.timer = window.setTimeout(function() {
- self.element.text(self.options.value);
+ self.element.text(self.value());
self.element.removeClass(self.options.hover);
}, 200);
})
.focus();
    },
-    _save: function(event, newVal) {
+    _save: function(event, newValue) {
var hash = {
- value: newVal
+ value: newValue
};
if (this._trigger('save', event, hash) !== false) {
- this.options.value = hash.value;
- }
+ this.value(newValue);
+ }
+    },
+
+    value: function(newValue) {
+        if (arguments.length) {
+            this._setData('value', newValue);
+        }
+        return this._getData('value');
    }
});