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