Project

General

Profile

Download (2.49 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Expected dom structure like:
3
 *   <div class="item-tree">
4
 *      <div class="item-list">
5
 *          <ul>
6
 *              <li class="derived-unit-item derived-unit-tree-root ">
7
 *                  <div class="unit-label">(B SP-99999).</div>
8
 *                  <div class="unit-content">
9
 *                  <ul class="specimens derivate_tree">
10
 *                      <li class="derived-unit-item">
11
 *                          <div class="unit-label">(B B-923845).</div>
12
 *                          <div class="unit-content">
13
 *                      </li>
14
                        <li class="derived-unit-item">
15
                            <div class="unit-label">(B DNA-9098080).</div>
16
                            <div class="unit-content"></div>
17
                        </li>
18
                    </ul>
19
                </li>
20
            </ul>
21
        </div>
22
 *   </div>
23
 * The plugin function should be bound to outer div with '.derived-unit-tree'
24
 */
25
;(function ($, document, window, undefined) {
26

    
27
    $.fn.derivationTree = function () {
28
        // firebug console stub (avoids errors if firebug is not active)
29
        if (typeof console === "undefined") {
30
            console = {
31
                log: function () {
32
                }
33
            };
34
        }
35

    
36
        let $element = $(this);
37
        $element.find(".derived-unit-item").each(function () {
38
            let $listItem = $(this);
39
            let $itemWrapper = $listItem.children('.item-wrapper');
40
            let $unitHeader = $itemWrapper.children('.unit-header-wrapper').children('.unit-header');
41
            let $collapsibleSymbol = $unitHeader.find('.unit-label > .tree-node-symbol-collapsible');
42

    
43
            $unitHeader.find('.page-link').click(function(event){
44
                event.stopPropagation();
45
            });
46
            let $unitContent = $itemWrapper.children('.unit-content');
47
            $unitContent.hide();
48
            $unitHeader.click(function(){
49
                $unitContent.toggle();
50
            });
51
            $collapsibleSymbol.click(function(event){
52
                $listItem.toggleClass('collapsed').children('.item-list').children('ul.derived-unit-item').toggleClass('collapsed');
53
                    $(this).find('.fa').toggleClass('fa-rotate-90');
54
                    event.stopPropagation();
55
                }
56
            ).hover(function(event){
57
                event.stopsPropagation(); // allows the css hover effect to be handled but stops from bubbling up to the label
58
            });
59

    
60
        });
61

    
62
    };
63
})(jQuery, document, window);
(5-5/16)