<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1"
http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
I like it, very simple and smooth. I will probably use this
eventually.<br>
<br>
Ian Tyndall wrote:
<blockquote cite="mid4508D7C3.5050908-ue636x8T32g@public.gmane.org"
type="cite">
<pre wrap="">I needed an accordion effect, but all I could
find were either heavy or
had too many requirements. So, I rolled my own...
Any responses are welcome!
Ian
If you have any problems with the attachments, please let me know. Since
I''m going through employment changes, I don''t have a server to
post
examples on (yet ;-) ).
</pre>
<pre wrap="">
<hr size="4" width="90%">
// Copyright (c) 2006 Ian Tyndall - <a
class="moz-txt-link-abbreviated"
href="mailto:ityndall-ue636x8T32g@public.gmane.org">ityndall-ue636x8T32g@public.gmane.org</a>
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
Effect.Accordion = Class.create();
Effect.Accordion.prototype = {
initialize: function(element) {
this.element = $(element);
this.options = ({
openAll: ''false'',
closeAll: ''false''
}, arguments[1] || {});
this._setup(this.element);
this._closeOpen(0, ''start'');
},
_setup: function(element) {
this.accBodies = []; //bodies accordion blind elements
var items = element.getElementsByTagName(''*'');
var manager = function(el, num){
onClickargs = [];
onClickargs[0] = items[num + 2]; //Accordion body element
onClickargs[1] = Element.getDimensions(onClickargs[0]);
this.accBodies.push(onClickargs[0]);
Event.observe(items[num + 1], "click",
this._onClick.bindAsEventListener(this, onClickargs));
}.bind(this);
$A(items).each( function(el, index) {
if(el.parentNode.id == element.id) {
manager(el, index);
}
});
this._setupOptions();
},
_setupOptions: function() {
if(this.options.openAll) { Event.observe($(this.options.openAll),
"click", this._openAll.bindAsEventListener(this, 0.5)); }
if(this.options.closeAll) { Event.observe($(this.options.closeAll),
"click", this._closeAll.bindAsEventListener(this, 0.5)); }
},
_onClick: function(event, args) {
if(!Element.visible(args[0])) {
Effect.BlindDown(args[0], {scaleMode: {originalHeight: args[1].height,
originalWidth: args[1].width}});
}
this._closeOpen(0.5, true);
},
_closeOpen: function(lapse, keepopen) {
this.accBodies.each( function(bod) {
if(keepopen == true) {
if(Element.hasClassName(bod.previous(), ''locked'')) {
return false; }
} else if(keepopen == ''start'') {
if(Element.hasClassName(bod.previous(), ''active'')) {
return false; }
}
if(Element.visible(bod)) { Effect.BlindUp(bod, { duration: lapse }); }
});
},
_openAll: function(event, lapse) {
this.accBodies.each( function(bod) {
if(!Element.visible(bod)) { Effect.BlindDown(bod, { duration: lapse }); }
});
},
_closeAll: function(event, lapse) {
this.accBodies.each( function(bod) {
if(!Element.hasClassName(bod.previous(), ''locked'')
&& Element.visible(bod)) { Effect.BlindUp(bod, { duration: lapse
}); }
});
}
};
</pre>
<br>
<hr size="4" width="90%"><br>
<title>Effect Accordion</title>
<meta http-equiv="content-type" content="text/html;
">
<script src="../../lib/prototype.js"
type="text/javascript"></script>
<script src="../../src/scriptaculous.js"
type="text/javascript"></script>
<script src="../../src/accordion.js"
type="text/javascript"></script>
<style type="text/css" media="screen">
/* <![CDATA[ */
#documentation p {
width: 700px;
margin: 0 auto;
display: block;
}
.accordiontitle { font-size: 14pt; text-align: center; }
#myAccordion { width: 450px; margin: 0 auto; }
#myAccordion div, #myAccordion h3, #myAccordion span {
border: 1px solid #888; display: block;
}
ul#accordion2 { width: 450px; list-style-type: none; margin: 0 auto; padding:
0; }
ul#accordion2 li { list-style-type: none; border: 1px solid black; }
ul#accordion2 li div { border: 1px solid black; }
#options span { cursor: pointer; color: blue; margin-left: 10px; }
.accordionItem { border: none; }
h3 { margin: 0; padding: 0; }
/* ]]> */
</style>
<div id="options"> <span id="openall">Open
All</span> <span
id="closeall">Close All</span>
</div>
<div id="documentation">
<p> I needed an accordion with as little requirements as possible,
and that was lightweight. You can look at the example using various
elements and see that you don''t need specific classnames/ids for
individual parts of the accordion, nor do you need to have specific tag
types. It is the structure that is key here. I''ve added the ability to
add options based on the accordion header classnames, such as: lock
individual partitions of the accordion by assigning the header a
classname of "locked" (look at accordion 4 in the first example), or
allowing an active partition by assigning the header a classname of
"active" (look at accordion 2 in the first example, this allows one
partition to stay open at the beginning). The current options allow for
adding actions to open or close all accordion elements for all
accordions (look at the options for the first example). I hope to be
adding more features and unit tests soon! I am open to any suggestions
or feature requests, and bugs (I think I finally conquered the Blind
Down jumpy bug). </p>
</div>
<h1 class="accordiontitle">Accordion using various
elements</h1>
<div id="myAccordion">
<div>
<div class="memo" style="border: 1px solid
blue;">accordion header 1</div>
<div style="border: 1px solid red; height: 100px;"> accordion
1
accordion 1 accordion 1 accordion 1 accordion 1 accordion 1 accordion 1
accordion 1 accordion 1 accordion 1 accordion 1 accordion 1 accordion 1
accordion 1 accordion 1 accordion 1 accordion 1 accordion 1 accordion 1
accordion 1 accordion 1 accordion 1 accordion 1 accordion 1 </div>
</div>
<div>
<h3 class="active">accordion header 2</h3>
<div> accordion 2 accordion 2 accordion 2 accordion 2 accordion 2
accordion 2 accordion 2 accordion 2 accordion 2 accordion 2 accordion 2
accordion 2 accordion 2 accordion 2 accordion 2 accordion 2 accordion 2
accordion 2 accordion 2 accordion 2 accordion 2 accordion 2 accordion 2
accordion 2 accordion 2 accordion 2 accordion 2 accordion 2 accordion 2
accordion 2 accordion 2 accordion 2 accordion 2 accordion 2 accordion 2
accordion 2 accordion 2 accordion 2 accordion 2 accordion 2 accordion 2
accordion 2 accordion 2 accordion 2 accordion 2 accordion 2 accordion 2
accordion 2 accordion 2 accordion 2 accordion 2 accordion 2 accordion 2
accordion 2 accordion 2 accordion 2 accordion 2 accordion 2 accordion 2
accordion 2 accordion 2 accordion 2 accordion 2 accordion 2 </div>
</div>
<div>
<div style="border: 1px solid black;">accordion header
3</div>
<div> accordion 3 accordion 3 accordion 3 accordion 3 accordion 3
accordion 3 accordion 3 accordion 3 accordion 3 accordion 3 accordion 3
accordion 3 accordion 3 accordion 3 accordion 3 accordion 3 accordion 3
accordion 3 accordion 3 accordion 3 accordion 3 accordion 3 accordion 3
accordion 3 accordion 3 accordion 3 accordion 3 accordion 3 accordion 3
accordion 3 accordion 3 accordion 3 accordion 3 accordion 3 accordion 3
accordion 3 accordion 3 accordion 3 accordion 3 accordion 3 accordion 3
accordion 3 accordion 3 accordion 3 accordion 3 accordion 3 accordion 3
accordion 3 accordion 3 accordion 3 accordion 3 accordion 3 accordion 3
accordion 3 accordion 3 accordion 3 accordion 3 accordion 3 accordion 3
accordion 3 </div>
</div>
<div> <span class="accordionHeader locked">accordion
header 4</span>
<div>accordion body 4</div>
</div>
</div>
<h1 class="accordiontitle">Accordion using list
items</h1>
<ul id="accordion2">
<li>
<div>accordion header 1</div>
<div style="height: 150px;"> accordion 1 accordion 1
accordion 1
accordion 1 accordion 1 accordion 1 accordion 1 accordion 1 accordion 1
accordion 1 accordion 1 accordion 1 accordion 1 accordion 1 accordion 1
accordion 1 accordion 1 accordion 1 accordion 1 accordion 1 accordion 1
accordion 1 accordion 1 accordion 1
</div>
</li>
<li>
<div>accordion header 2</div>
<div> accordion 2 accordion 2 accordion 2 accordion 2 accordion 2
accordion 2 accordion 2 accordion 2 accordion 2 accordion 2 accordion 2
accordion 2 accordion 2 accordion 2 accordion 2 accordion 2 accordion 2
accordion 2 accordion 2 accordion 2 accordion 2 accordion 2 accordion 2
accordion 2 accordion 2 accordion 2 accordion 2 accordion 2 accordion 2
accordion 2 accordion 2 accordion 2 accordion 2 accordion 2 accordion 2
accordion 2 accordion 2 accordion 2 accordion 2 accordion 2 accordion 2
accordion 2 accordion 2 accordion 2 accordion 2 accordion 2 accordion 2
accordion 2 accordion 2 accordion 2 accordion 2 accordion 2 accordion 2
accordion 2 accordion 2 accordion 2 accordion 2 accordion 2 accordion 2
accordion 2 accordion 2 accordion 2 accordion 2 accordion 2
</div>
</li>
</ul>
<script type="text/javascript" language="javascript"
charset="utf-8">
// <![CDATA[
new Effect.Accordion("myAccordion", {openAll:
''openall'', closeAll: ''closeall''});
new Effect.Accordion("accordion2");
// ]]>
</script>
</blockquote>
<br>
--~--~---------~--~----~------------~-------~--~----~<br>
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group. <br> To post to this
group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> To
unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
<br> For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs <br>
-~----------~----~----~----~------~----~------~--~---<br>
</body>
</html>
<br>