Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
YUI.add('moodle-mod_assign-history', function (Y, NAME) {
2
 
3
// Define a function that will run in the context of a
4
// Node instance:
5
var CSS = {
6
        LINK: 'mod-assign-history-link',
7
        OPEN: 'mod-assign-history-link-open',
8
        CLOSED: 'mod-assign-history-link-closed',
9
        PANEL: 'mod-assign-history-panel'
10
    },
11
    COUNT = 0,
12
    TOGGLE = function() {
13
        var id = this.get('for'),
14
            panel = Y.one('#' + id);
15
        if (this.hasClass(CSS.OPEN)) {
16
            this.removeClass(CSS.OPEN);
17
            this.addClass(CSS.CLOSED);
18
            this.setStyle('overflow', 'hidden');
19
            panel.hide();
20
        } else {
21
            this.removeClass(CSS.CLOSED);
22
            this.addClass(CSS.OPEN);
23
            panel.show();
24
        }
25
    },
26
    HISTORY = function() {
27
        var link = null,
28
            panel = null,
29
            wrapper = null,
30
            container = this;
31
 
32
        // Loop through all the children of this container and turn
33
        // every odd node to a link to open/close the following panel.
34
        this.get('children').each(function() {
35
            if (link) {
36
                COUNT++;
37
                // First convert the link to an anchor.
38
                wrapper = Y.Node.create('<a/>');
39
                panel = this;
40
                container.insertBefore(wrapper, link);
41
                link.remove(false);
42
                wrapper.appendChild(link);
43
 
44
                // Add a for attribute to the link to link to the id of the panel.
45
                if (!panel.get('id')) {
46
                    panel.set('id', CSS.PANEL + COUNT);
47
                }
48
                wrapper.set('for', panel.get('id'));
49
                // Add an aria attribute for the live region.
50
                panel.set('aria-live', 'polite');
51
 
52
                wrapper.addClass(CSS.LINK);
53
                if (COUNT == 1) {
54
                    wrapper.addClass(CSS.OPEN);
55
                } else {
56
                    wrapper.addClass(CSS.CLOSED);
57
                }
58
                panel.addClass(CSS.PANEL);
59
                if (COUNT == 1) {
60
                    panel.show();
61
                } else {
62
                    panel.hide();
63
                }
64
                link = null;
65
            } else {
66
                link = this;
67
            }
68
        });
69
 
70
        // Setup event listeners.
71
        this.delegate('click', TOGGLE, '.' + CSS.LINK);
72
    };
73
 
74
// Use addMethod to add history to the Node prototype:
75
Y.Node.addMethod("history", HISTORY);
76
 
77
// Extend this functionality to NodeLists.
78
Y.NodeList.importMethod(Y.Node.prototype, "history");
79
 
80
 
81
}, '@VERSION@', {"requires": ["node", "transition"]});