xref: /webtrees/resources/views/modules/descendancy/sidebar.phtml (revision cd51dbdfbd6a6a2e8b78479e839819cddc801c34)
1<?php
2
3use Fisharebest\Webtrees\I18N;
4use Fisharebest\Webtrees\View;
5
6?>
7
8<form method="post" action="<?= e(route('module', ['module' => 'descendancy', 'action' => 'Descendants', 'tree' => $tree->name()])) ?>" onsubmit="return false;">
9    <?= csrf_field() ?>
10    <input type="search" name="sb_desc_name" id="sb_desc_name" placeholder="<?= I18N::translate('Search') ?>">
11</form>
12
13<div id="sb_desc_content">
14    <ul>
15        <?= $individual_list ?>
16    </ul>
17</div>
18
19<?php View::push('javascript') ?>
20<script>
21  function dsearchQ() {
22    var query = $("#sb_desc_name").val();
23    if (query.length>1) {
24      $("#sb_desc_content").load(<?= json_encode(route('module', ['module' => 'descendancy', 'action' => 'Search', 'tree' => $tree->name(), 'search' => ''])) ?> + encodeURIComponent(query));
25    }
26  }
27
28  $("#sb_desc_name").focus(function(){this.select();});
29  $("#sb_desc_name").blur(function(){if (this.value === "") this.value="<?= I18N::translate('Search') ?>";});
30  var dtimerid = null;
31  $("#sb_desc_name").keyup(function(e) {
32    if (dtimerid) window.clearTimeout(dtimerid);
33    dtimerid = window.setTimeout("dsearchQ()", 500);
34  });
35
36  $("#sb_desc_content").on("click", ".sb_desc_indi", function() {
37    var self = $(this),
38        state = self.children(".plusminus"),
39        target = self.siblings("div");
40    if(state.hasClass("icon-plus")) {
41      if (jQuery.trim(target.html())) {
42        target.show("fast"); // already got content so just show it
43      } else if (self.attr("href") !== "#") {
44        target
45          .hide()
46          .load(self.attr("href"), function(response, status, xhr) {
47            if(status === "success" && response !== "") {
48              target.show("fast");
49            }
50          })
51      }
52    } else {
53      target.hide("fast");
54    }
55    state.toggleClass("icon-minus icon-plus");
56    return false;
57  });
58</script>
59<?php View::endpush() ?>
60