------------------------------------------------------------
expand.js:
------------------------------------------------------------
(function($) {
$.fn.expandAll = function(options) {
var defaults = {
expTxt : 'Show All',
cllpsTxt : 'Hide All',
cllpsEl : '.collapse', // the collapsible element
trigger : '.expand', // the elements that contain the trigger of the toggle effect on the individual collapsible sections
ref : '.expand', // the switch 'Expand All/Collapse All' is inserted before the 'ref'
showMethod : 'show',
hideMethod : 'hide',
state : 'hidden', // the collapsible elements are hidden by default: use 'hidden' or 'shown'
speed : 0,
oneSwitch : true
};
var o = $.extend({}, defaults, options);
var toggleTxt = o.expTxt;
if (o.state == 'hidden') {
$(this).find(o.cllpsEl + ':not(.shown)').hide()
.prev().find(o.trigger + ' > a.open').removeClass('open');
} else {
toggleTxt = o.cllpsTxt;
}
return this.each(function(index) {
var referent, $cllps, $tr;
if (o.ref) {
var container;
if (this.id.length) {
container = '#' + this.id;
} else if (this.className.length) {
container = this.tagName.toLowerCase() + '.' + this.className.split(' ').join('.');
} else {container = this.tagName.toLowerCase();}
referent = $(this).find("'" + o.ref + ":first'");
$cllps = $(this).closest(container).find(o.cllpsEl);
$tr = $(this).closest(container).find(o.trigger + ' > a');
} else {
referent = $(this);
$cllps = $(this).find(o.cllpsEl);
$tr = $(this).find(o.trigger + ' > a');
}
if (o.oneSwitch) {
referent.before('<p class="switch"><a href="#">' + toggleTxt + '</a></p>');
} else {
referent.before('<p class="switch"><a href="#">' + o.expTxt + '</a> | <a href="#">' + o.cllpsTxt + '</a></p>');
}
referent.prev('p').find('a').click(function() {
if ($(this).text() == o.expTxt) {
if (o.oneSwitch) {$(this).text(o.cllpsTxt);}
$tr.addClass('open');
$cllps[o.showMethod](o.speed);
} else {
if (o.oneSwitch) {$(this).text(o.expTxt);}
$tr.removeClass('open');
$cllps[o.hideMethod](o.speed);
}
return false;
});
});};
------------------------------------------------------------
function that goes in the .cfm file
------------------------------------------------------------
$(function() {
// --- Using the default options:
$("h3.expand").toggler({initShow: "div.collapse:first"});
// --- Other options:
//$("h3.expand").toggler({method: "toggle", speed: 0});
//$("h3.expand").toggler({method: "toggle"});
//$("h3.expand").toggler({speed: "fast"});
//$("h3.expand").toggler({method: "fadeToggle"});
//$("h3.expand").toggler({method: "slideFadeToggle"});
$("#content").expandAll({trigger: "h3.expand", ref: "div.demo", showMethod: "slideDown", hideMethod: "slideUp", speed: 400, oneSwitch: false});
});
------------------------------------------------------------
css
------------------------------------------------------------
/*css for Expandable Containers*
/* --------
The CSS rules offered here are just an example, you may use them as a base.
Shape your 'expand/collapse' content so that it meets the style of your site.
--------- */
* {margin:0; padding:0}
/* --- Page Structure --- */
#wrapper{
margin:0 auto;
/*padding:15px 15%;*/
text-align:left;
}
#wrapper h3 {
margin:0;
}
#content {
/*max-width:70em;*/
width:100%;
margin:0 auto;
padding-bottom:0px;
overflow:hidden
}
.demo {
margin:0 auto;
padding:0;
position:relative;
background:#000;
}
.collapse h4 {padding:0;}
#DocumentID, .DocumentID {margin-bottom:5px; text-align:center; color:#000;}
/* --- Headings --- */
.expand {padding-bottom:0;}
/* --- Links --- */
#switch, .switch {
color:#BCB39A;
width:220px;
margin:0;
padding:0 0 0 10px;
text-align:left;
}
.expand a {
display:block;
padding:5px 40px 5px 10px;
color:#8A5D3C;
}
.expand a:link, .expand a:visited {
color:#8A5D3C;
background:url(../images/arrow-down.gif) no-repeat;
margin:0;
padding:0 0 0 10px;
}
.expand a:hover, .expand a:active, .expand a:focus {
text-decoration:none;
}
.expand a.open:link, .expand a.open:visited {
background:url(../images/arrow-up.gif) no-repeat;
margin:0;
padding:0 0 0 10px;
}
/*subNav*/
.subNav a {
color:#BCB39A;
text-decoration:none;
}
.subNav a:hover {
color:#8A5D3C;
text-decoration:none;
}
.focus a {text-decoration:none; color:#fff;}
.focus a:hover {text-decoration:none;}
h3.expand {
margin:0;
padding:15px 0 0 0;
font-weight:normal;
}
h4.subNav, h4.focus {
margin:0;
padding:0 0 5px 10px;
font-weight:normal;
text-transform:none;
}
------------------------------------------------------------
section that displays the menu from the .cfm file:
------------------------------------------------------------
<div class="grid_4 omega subNav">
<div id="wrapper">
<div id="content">
<div class="demo">
<cfoutput query="getCategories" group="MainCategoryID">
<h3 class="expand">#MainCategory#</h3>
<div class="collapse">
<cfoutput group="CategoryID">
<cfif CategoryID EQ URL.CategoryID>
<cfset theClass = "focus">
<cfelse>
<cfset theClass = "subNav">
</cfif>
<h4 class="#theClass#"><a href="products.cfm?MainCategoryID=#MainCategoryID#&CategoryID=#CategoryID#">#Category#</a></h4>
</div>
</cfoutput>
</div>
</div>
</div>
</div>
|