summaryrefslogtreecommitdiff
path: root/jarmonbuild/yuidoc_template/assets/ac-js
blob: 15a6dff078366704def397d98a225097291f7c22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
(function() {
    var Event=YAHOO.util.Event,
        Dom=YAHOO.util.Dom,
        oACDS, oAutoComp,
        show = {
            'private': false,
            'protected': false,
            'deprecated': false
        };

Event.onAvailable('yui-classopts-form', function() {
    //Checkboxes are available..
    var handleClick = function(e) {
        var id, checked = false;
        if (YAHOO.lang.isString(e)) {
            id = e;
        } else {
            var tar = Event.getTarget(e);
            id = tar.id;
        }
        var el = Dom.get(id);
        checked = el.checked;

        var className = id;
        if (checked) {
            show[id.replace('show_', '')] = true;
            Dom.addClass(document.body, className);
            YAHOO.util.Cookie.setSub('yuidoc', id, 'checked');
        } else {
            show[id.replace('show_', '')] = false;
            Dom.removeClass(document.body, className);
            YAHOO.util.Cookie.setSub('yuidoc', id, '');
        }
    };

    var checkCookie = function(id) {
        var value = YAHOO.util.Cookie.getSub('yuidoc', id),
            el = Dom.get(id), checked = (value === 'checked');;

        /*
        if (value === 'checked') {
            el.checked = true;
        } else {
            el.checked = false;
        }
        */

        el.checked = checked;
        return checked;
    };

    var els = ['show_deprecated', 'show_protected', 'show_private'],
        reapplyHash = false;

    for (var i = 0; i < els.length; i++) {
        Event.on(els[i], 'click', handleClick);
        reapplyHash = checkCookie(els[i]) || reapplyHash;
        handleClick(els[i]);
    }

    // If we dynamically show private/protected/etc items during
    // load, we need to reapply anchors so that the search feature
    // works correctly for items that are initially hidden.
    if (reapplyHash) {
        var dl = document.location, hash = dl.hash;
        if (hash) {
            dl.hash = hash;
        }
    }
    
});

//Starting the AutoComplete code
    var getResults = function(query) {
        var results = [];
        if(query && query.length > 0) {

            var q = query.toLowerCase();

            for (var i=0, len=ALL_YUI_PROPS.length; i<len; ++i) {

                var prop = ALL_YUI_PROPS[i];

                if (!show['protected'] && prop.access == "protected") {
                    // skip
                } else if (!show['private'] && prop.access == "private") {
                    // skip
                } else if (!show['deprecated'] && prop.deprecated) {
                    // skip
                } else {
                    var s = (prop.host + "." + prop.name).toLowerCase();
                    if (s.indexOf(q) > -1 ) {
                        results.push([query, prop]);
                    }
                }
            }
        }

        return results;
    };

    // Define Custom Event handlers
    var myOnDataReturn = function(sType, aArgs) {
        var oAutoComp = aArgs[0];
        var query = aArgs[1];
        var aResults = aArgs[2];

        if(aResults.length == 0) {
            if (query.length > 0) {
                oAutoComp.setBody("<div id=\"resultsdefault\">Not found</div>");
            }
        }
    };

    var myOnItemSelect = function(sType, aArgs) {
        var ac = aArgs[0];
        var item = aArgs[2];
        location.href = item[1].url;
    };


    Event.onAvailable("searchresults", function() {

        // Instantiate JS Function DataSource
        oACDS = new YAHOO.widget.DS_JSFunction(getResults);
        oACDS.maxCacheEntries = 30;

        // Instantiate AutoComplete
        oAutoComp = new YAHOO.widget.AutoComplete('searchinput','searchresults', oACDS);
        //oAutoComp.alwaysShowContainer = true;
        oAutoComp.queryDelay = 0.2;
        oAutoComp.maxResultsDisplayed = 200;
        oAutoComp.minQueryLength = 0;
        oAutoComp.formatResult = function(oResultItem, query) {
            var sMarkup = "<em>" + oResultItem[1].host + '</em> <span>' + oResultItem[1].name + '</span>';
            return sMarkup;
        };

        // Subscribe to Custom Events
        oAutoComp.dataReturnEvent.subscribe(myOnDataReturn);
        oAutoComp.itemSelectEvent.subscribe(myOnItemSelect);
        
        // Set initial content in the container
        oAutoComp.sendQuery(Dom.get("searchinput").value);

    });

    var validateForm = function() {
        return false;
    };
    
    YAHOO.util.Event.onAvailable('classTab', function() {
        var tabs = new YAHOO.widget.TabView('classTab');
    });
    /*
    YAHOO.util.Event.onAvailable('codeTree', function() {
        var tree1 = new YAHOO.widget.TreeView('codeTree');
        tree1.render();    
    });
    */

})();