Add convenient function to make elements editable and add default JavaScript callback
authorJoey Schulze <joey@infodrom.org>
Mon, 17 Jul 2017 21:10:17 +0000 (23:10 +0200)
committerJoey Schulze <joey@infodrom.org>
Mon, 17 Jul 2017 21:15:14 +0000 (23:15 +0200)
src/infodrom.css
src/infodrom.js

index 79989a0..3d0eae6 100644 (file)
@@ -224,6 +224,10 @@ div#error_div p {
     background: yellow;
 }
 
+[data-is-editing="1"] {
+    background: lightblue !important;
+}
+
 /*
  * Footer
  */
index fa61440..c9b4d2a 100644 (file)
@@ -48,6 +48,32 @@ function hide_error(text)
     return false;
 }
 
+function editable_callback(data)
+{
+    if (data.content) {
+       var elem = $(data.$el);
+        var route = elem.attr('route');
+        var item_id = elem.attr('item_id');
+        if (typeof(route) == 'string' && typeof(item_id) == 'string')
+            $.invoke(route,
+                     {id: item_id,
+                      name: elem.attr('name'),
+                      content: data.content});
+    }
+
+    return false;
+}
+
+function make_editable(selector)
+{
+    var list = $(selector);
+    if (list.length)
+       list.editable({
+           closeOnEnter : true,
+           event : 'click',
+           callback: editable_callback
+       });
+}
 (function($){
     $.fn.ltag = function() {
        return this.prop("tagName").toLowerCase();