summaryrefslogtreecommitdiff
path: root/core/views/in_place_edit.html.php
blob: 2cf0c8a13925d4c8f2f1dc8d0db8ff3472b31297 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<? defined("SYSPATH") or die("No direct script access."); ?>
<script type="text/javascript">
$(document).ready(function() {
  ajax_update = function(className, id) {
    return function(value, settings) {
      $.post("<?= url::site("item/__ID__") ?>".replace("__ID__", id),
             {"key": settings.name, "value": value},
             function(data, textStatus) {
               if (textStatus == "success") {
                 $(className).html(data);
               }
             },
             "html");
    }
  }

  var seen_before = {};
  var editable = $("span.gInPlaceEdit");
  for (i = 0; i < editable.length; i++) {
    var matches = editable[i].className.match(/gEditField-(\d+)-(\S+)/);
    if (matches && matches.length == 3) {
      var className = "." + matches[0];
      if (!seen_before[className]) {
        $(className).editable(
          ajax_update(className, matches[1]),
          {indicator : "<?= _("Saving...") ?>",
           tooltip   : "<?= _("Double-click to edit...") ?>",
           event     : "dblclick",
           style     : "inherit",
           name      : matches[2],
           select    : true}
        );
        seen_before[className] = 1;
      }
    }
  }
});
</script>