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