Project

General

Profile

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

    
23
    $.fn.derivationTree = function () {
24
        // firebug console stub (avoids errors if firebug is not active)
25
        if (typeof console === "undefined") {
26
            console = {
27
                log: function () {
28
                }
29
            };
30
        }
31

    
32
        var $element = $(this);
33
        $element.find(".derived-unit-item").each(function () {
34
            var $listItem = $(this);
35
            var unitLabel = $listItem.children('.unit-header');
36
            var unitContent = $listItem.children('.unit-content')
37
            if(unitContent.length == 0){
38
                // must be the root unit, we gonna dig one level deeper
39
                unitContent = $listItem.children('.unit-content-wrapper').children('.unit-content')
40
            }
41
            unitContent.hide();
42
            unitLabel.click(function(){
43
                unitContent.toggle();
44
            });
45
        });
46

    
47
    };
48
})(jQuery, document, window);
(5-5/16)