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