edit table cells in place
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 23 May 2010 13:18:30 +0000 (15:18 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 23 May 2010 13:18:30 +0000 (15:18 +0200)
public/edit_table.js [new file with mode: 0644]

diff --git a/public/edit_table.js b/public/edit_table.js
new file mode 100644 (file)
index 0000000..93deeae
--- /dev/null
@@ -0,0 +1,34 @@
+$(document).ready( function() {
+
+var cell_blur = function() {
+       console.debug( 'cell_blur'
+               , this
+               , $(this).val()
+       );
+       var content = $(this).val();
+       var cell = $('<td>'+content+'</td>');
+       $(this).replaceWith( cell );
+       console.info( cell );
+}
+
+var cell_click = function(event) {
+       console.debug( 'cell_click'
+               , this
+               , event
+               , $(this).text()
+       );
+       var content = $(this).text(); // we don't want para markup
+       var textarea = $('<textarea />');
+       textarea.val( content );
+       $(this).html( textarea );
+       textarea.focus();
+       textarea.blur( cell_blur )
+};
+
+
+console.info('double-click on cell to edit it');
+$('table td').live( 'dblclick', cell_click );
+
+}); // document.ready
+
+