var Accordion = function() { var container = null; var targetHeight = null; var panes = null; /** * The first parameter is the event, the second is the object passed throught the handler */ function _handleClick(e, pane){ if (YAHOO.util.Dom.hasClass(pane, 'open')){ /* * Pane is open, now close */ // _close(pane); }else{ /* * Pane is closed, now open * Don't forget to close all others */ _open(pane); } } /** * I like it if only one pane is open at any givven time * So loop all panes and close them */ function _closeAll(){ for(var x = 0; x < panes.length; x++){ _close(panes[x]); } } function _open(pane){ if (!YAHOO.util.Dom.hasClass(pane, 'open')){ _closeAll(); /* * Accordion pane is appearantly closed so open it. */ var content = YAHOO.util.Dom.getLastChild(pane); /* * Setup the animation */ var attributes = { height: { to: targetHeight } }; var anim = new YAHOO.util.Anim(content, attributes, 0.5, YAHOO.util.Easing.easeOutStrong); anim.animate(); /* * Do some housekeeping */ YAHOO.util.Dom.setStyle(content, 'overflow', 'auto'); YAHOO.util.Dom.setStyle(content, 'overflow-x', 'hidden'); YAHOO.util.Dom.setStyle(content, 'display', 'block'); YAHOO.util.Dom.addClass(pane, 'open'); } } function _directOpen(pane){ if (!YAHOO.util.Dom.hasClass(pane, 'open')){ _closeAll(); /* * Accordion pane is appearantly closed so open it. */ var content = YAHOO.util.Dom.getLastChild(pane); /* * Setup the animation */ // var attributes = { // height: { to: targetHeight } // }; YAHOO.util.Dom.setStyle(content, 'height', targetHeight); YAHOO.util.Dom.setStyle(content, 'overflow', 'auto'); YAHOO.util.Dom.setStyle(content, 'overflow-x', 'hidden'); YAHOO.util.Dom.setStyle(content, 'display', 'block'); YAHOO.util.Dom.addClass(pane, 'open'); } } function _close(pane){ if (YAHOO.util.Dom.hasClass(pane, 'open')){ /* * Accordion pane is appearantly closed so open it. */ var content = YAHOO.util.Dom.getLastChild(pane); var attributes = { height: { to: 0 } }; var anim = new YAHOO.util.Anim(content, attributes, 0.5, YAHOO.util.Easing.easeOutStrong); anim.animate(); YAHOO.util.Dom.setStyle(content, 'overflow', 'hidden'); YAHOO.util.Dom.setStyle(content, 'display', 'none'); YAHOO.util.Dom.removeClass(pane, 'open'); } } var pub = { init : function(nodeId){ container = document.getElementById(nodeId); YAHOO.util.Dom.setStyle(container, 'height', '420px'); var containerDimensions = YAHOO.util.Dom.getRegion(container); targetHeight = (containerDimensions.bottom - containerDimensions.top); // alert(YAHOO.util.Dom.getStyle(container, 'height')); // alert(containerDimensions); if (container){ panes = YAHOO.util.Dom.getElementsByClassName('pane',null, container); paneHeight = YAHOO.util.Dom.getStyle(YAHOO.util.Dom.getFirstChild(panes[0]), 'height'); paneHeightPx = paneHeight.substring(0, (paneHeight.length - 2)); // alert(paneHeightPx); targetHeight = (targetHeight - panes.length * (paneHeightPx)); for (var x=0; x