");
$('_ie_ready_').addEvent('readystatechange', function(){
if (this.readyState == 'complete') init();
});
return;
} else { //others
var myInit = function() {
if (arguments.callee.done) return;
arguments.callee.done = true;
init();
};
window.addEvent("load", myInit);
document.addEvent("DOMContentLoaded", myInit);
}
}
};
var Cookie = {
set: function(key, value, duration){
var date = new Date();
date.setTime(date.getTime()+((duration || 365)*86400000));
document.cookie = key+"="+value+"; expires="+date.toGMTString()+"; path=/";
},
get: function(key){
var myValue, myVal;
document.cookie.split(';').each(function(cookie){
if(myVal = cookie.trim().test(key+'=(.*)')) myValue = myVal[1];
});
return myValue;
},
remove: function(key){
this.set(key, '', -1);
}
};
var Json = {
toString: function(el){
var string = [];
var isArray = function(array){
var string = [];
array.each(function(ar){
string.push(Json.toString(ar));
});
return string.join(',');
};
var isObject = function(object){
var string = [];
for (var property in object) string.push('"'+property+'":'+Json.toString(object[property]));
return string.join(',');
};
switch($type(obj)){
case 'number': string.push(obj); break;
case 'string': string.push('"'+obj+'"'); break;
case 'function': string.push(obj); break;
case 'object': string.push('{'+isObject(obj)+'}'); break;
case 'array': string.push('['+isArray(obj)+']');
}
return string.join(',');
},
evaluate: function(str){
return eval('(' + str + ')');
}
};
var Sortables = new Class({
setOptions: function(options) {
this.options = {
handles: false,
fxDuration: 250,
fxTransition: Fx.Transitions.sineInOut,
maxOpacity: 0.5,
onComplete: Class.empty,
onStart: Class.empty,
contain: false
};
Object.extend(this.options, options || {});
},
initialize: function(elements, options){
this.setOptions(options);
this.options.handles = this.options.handles || elements;
var trash = new Element('div').injectInside($(document.body));
$A(elements).each(function(el, i){
var copy = $(el).clone().setStyles({
'position': 'absolute',
'opacity': '0',
'display': 'none'
}).injectInside(trash);
var elEffect = el.effect('opacity', {
duration: this.options.fxDuration,
wait: false,
transition: this.options.fxTransition
}).set(1);
var copyEffects = copy.effects({
duration: this.options.fxDuration,
wait: false,
transition: this.options.fxTransition,
onComplete: function(){
copy.setStyle('display', 'none');
}
});
var yMax = false;
var yMin = false;
if (this.options.contain){
yMax = $(el.parentNode).getTop()+el.parentNode.offsetHeight-el.offsetHeight;
yMin = el.parentNode.getTop();
}
var dragger = new Drag.Move(copy, {
handle: this.options.handles[i],
yMax: yMax,
yMin: yMin,
xModifier: false,
onStart: function(){
this.options.onStart.bind(this).delay(10);
copy.setHTML(el.innerHTML).setStyles({
'display': 'block',
'opacity': this.options.maxOpacity,
'top': el.getTop()+'px',
'left': el.getLeft()+'px'
});
elEffect.custom(elEffect.now, this.options.maxOpacity);
}.bind(this),
onComplete: function(){
this.options.onComplete.bind(this).delay(10);
copyEffects.custom({
'opacity': [this.options.maxOpacity, 0],
'top': [copy.getTop(), el.getTop()]
});
elEffect.custom(elEffect.now, 1);
}.bind(this),
onDrag: function(){
if (el.getPrevious() && copy.getTop() < (el.getPrevious().getTop())) el.injectBefore(el.getPrevious());
else if (el.getNext() && copy.getTop() > (el.getNext().getTop())) el.injectAfter(el.getNext());
}
});
}, this);
}
});
Fx.Scroll = Fx.Base.extend({
initialize: function(el, options) {
this.element = $(el);
this.setOptions(options);
},
down: function(){
return this.custom(this.element.scrollTop, this.element.scrollHeight-this.element.offsetHeight);
},
up: function(){
return this.custom(this.element.scrollTop, 0);
},
increase: function(){
this.element.scrollTop = this.now;
}
});
Fx.Slide = Fx.Base.extend({
initialize: function(el, options){
this.element = $(el);
this.wrapper = new Element('div').injectAfter(this.element).setStyle('overflow', 'hidden').adopt(this.element);
this.setOptions(options);
if (!this.options.mode) this.options.mode = 'vertical';
this.now = [];
},
setNow: function(){
[0,1].each(function(i){
this.now[i] = this.compute(this.from[i], this.to[i]);
}, this);
},
vertical: function(){
this.margin = 'top';
this.layout = 'height';
this.startPosition = [this.element.scrollHeight, '0'];
this.endPosition = ['0', -this.element.scrollHeight];
return this;
},
horizontal: function(){
this.margin = 'left';
this.layout = 'width';
this.startPosition = [this.element.scrollWidth, '0'];
this.endPosition = ['0', -this.element.scrollWidth];
return this;
},
hide: function(){
this[this.options.mode]();
this.wrapper.setStyle(this.layout, '0');
this.element.setStyle('margin-'+this.margin, -this.element['scroll'+this.layout.capitalize()]+this.options.unit);
return this;
},
show: function(){
this[this.options.mode]();
this.wrapper.setStyle(this.layout, this.element['scroll'+this.layout.capitalize()]+this.options.unit);
this.element.setStyle('margin-'+this.margin, '0');
return this;
},
toggle: function(mode){
this[this.options.mode]();
if (this.wrapper['offset'+this.layout.capitalize()] > 0) return this.custom(this.startPosition, this.endPosition);
else return this.custom(this.endPosition, this.startPosition);
},
increase: function(){
this.wrapper.setStyle(this.layout, this.now[0]+this.options.unit);
this.element.setStyle('margin-'+this.margin, this.now[1]+this.options.unit);
}
});
Fx.Color = Fx.Base.extend({
initialize: function(el, property, options){
this.element = $(el);
this.setOptions(options);
this.property = property;
this.now = [];
},
custom: function(from, to){
return this.parent(from.hexToRgb(true), to.hexToRgb(true));
},
setNow: function(){
[0,1,2].each(function(i){
this.now[i] = Math.round(this.compute(this.from[i], this.to[i]));
}, this);
},
increase: function(){
this.element.setStyle(this.property, "rgb("+this.now[0]+","+this.now[1]+","+this.now[2]+")");
},
fromColor: function(color){
return this.custom(color, this.element.getStyle(this.property));
},
toColor: function(color){
return this.custom(this.element.getStyle(this.property), color);
}
});
Fx.Height = Fx.Style.extend({
initialize: function(el, options){
this.parent(el, 'height', options);
this.element.setStyle('overflow', 'hidden');
},
toggle: function(){
if (this.element.offsetHeight > 0) return this.custom(this.element.offsetHeight, 0);
else return this.custom(0, this.element.scrollHeight);
},
show: function(){
return this.set(this.element.scrollHeight);
}
});
Fx.Width = Fx.Style.extend({
initialize: function(el, options){
this.parent(el, 'width', options);
this.element.setStyle('overflow', 'hidden');
this.iniWidth = this.element.offsetWidth;
},
toggle: function(){
if (this.element.offsetWidth > 0) return this.custom(this.element.offsetWidth, 0);
else return this.custom(0, this.iniWidth);
},
show: function(){
return this.set(this.iniWidth);
}
});
Fx.Opacity = Fx.Style.extend({
initialize: function(el, options){
this.parent(el, 'opacity', options);
this.now = 1;
},
toggle: function(){
if (this.now > 0) return this.custom(1, 0);
else return this.custom(0, 1);
},
show: function(){
return this.set(1);
}
});
Fx.Transitions = {
linear: function(t, b, c, d){
return c*t/d + b;
},
quadIn: function(t, b, c, d){
return c*(t/=d)*t + b;
},
quadOut: function(t, b, c, d){
return -c *(t/=d)*(t-2) + b;
},
quadInOut: function(t, b, c, d){
if ((t/=d/2) < 1) return c/2*t*t + b;
return -c/2 * ((--t)*(t-2) - 1) + b;
},
cubicIn: function(t, b, c, d){
return c*(t/=d)*t*t + b;
},
cubicOut: function(t, b, c, d){
return c*((t=t/d-1)*t*t + 1) + b;
},
cubicInOut: function(t, b, c, d){
if ((t/=d/2) < 1) return c/2*t*t*t + b;
return c/2*((t-=2)*t*t + 2) + b;
},
quartIn: function(t, b, c, d){
return c*(t/=d)*t*t*t + b;
},
quartOut: function(t, b, c, d){
return -c * ((t=t/d-1)*t*t*t - 1) + b;
},
quartInOut: function(t, b, c, d){
if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
return -c/2 * ((t-=2)*t*t*t - 2) + b;
},
quintIn: function(t, b, c, d){
return c*(t/=d)*t*t*t*t + b;
},
quintOut: function(t, b, c, d){
return c*((t=t/d-1)*t*t*t*t + 1) + b;
},
quintInOut: function(t, b, c, d){
if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
return c/2*((t-=2)*t*t*t*t + 2) + b;
},
sineIn: function(t, b, c, d){
return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
},
sineOut: function(t, b, c, d){
return c * Math.sin(t/d * (Math.PI/2)) + b;
},
sineInOut: function(t, b, c, d){
return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
},
expoIn: function(t, b, c, d){
return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
},
expoOut: function(t, b, c, d){
return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
},
expoInOut: function(t, b, c, d){
if (t==0) return b;
if (t==d) return b+c;
if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
},
circIn: function(t, b, c, d){
return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
},
circOut: function(t, b, c, d){
return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
},
circInOut: function(t, b, c, d){
if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
},
elasticIn: function(t, b, c, d, a, p){
if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; if (!a) a = 1;
if (a < Math.abs(c)){ a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin(c/a);
return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
},
elasticOut: function(t, b, c, d, a, p){
if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; if (!a) a = 1;
if (a < Math.abs(c)){ a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin(c/a);
return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
},
elasticInOut: function(t, b, c, d, a, p){
if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5); if (!a) a = 1;
if (a < Math.abs(c)){ a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin(c/a);
if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
},
backIn: function(t, b, c, d, s){
if (!s) s = 1.70158;
return c*(t/=d)*t*((s+1)*t - s) + b;
},
backOut: function(t, b, c, d, s){
if (!s) s = 1.70158;
return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
},
backInOut: function(t, b, c, d, s){
if (!s) s = 1.70158;
if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
},
bounceIn: function(t, b, c, d){
return c - Fx.Transitions.bounceOut (d-t, 0, c, d) + b;
},
bounceOut: function(t, b, c, d){
if ((t/=d) < (1/2.75)){
return c*(7.5625*t*t) + b;
} else if (t < (2/2.75)){
return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
} else if (t < (2.5/2.75)){
return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
} else {
return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
}
},
bounceInOut: function(t, b, c, d){
if (t < d/2) return Fx.Transitions.bounceIn(t*2, 0, c, d) * .5 + b;
return Fx.Transitions.bounceOut(t*2-d, 0, c, d) * .5 + c*.5 + b;
}
};
var Tips = new Class({
setOptions: function(options){
this.options = {
transitionStart: Fx.Transitions.sineInOut,
transitionEnd: Fx.Transitions.sineInOut,
maxTitleChars: 30,
fxDuration: 150,
maxOpacity: 1,
timeOut: 100,
className: 'tooltip'
}
Object.extend(this.options, options || {});
},
initialize: function(elements, options){
this.elements = elements;
this.setOptions(options);
this.toolTip = new Element('div').addClassName(this.options.className).setStyle('position', 'absolute').injectInside(document.body);
this.toolTitle = new Element('H4').injectInside(this.toolTip);
this.toolText = new Element('p').injectInside(this.toolTip);
this.fx = new fx.Style(this.toolTip, 'opacity', {duration: this.options.fxDuration, wait: false}).hide();
$A(elements).each(function(el){
$(el).myText = el.title || false;
if (el.myText) el.removeAttribute('title');
if (el.href){
if (el.href.test('http://')) el.myTitle = el.href.replace('http://', '');
if (el.href.length > this.options.maxTitleChars) el.myTitle = el.href.substr(0,this.options.maxTitleChars-3)+"...";
}
if (el.myText && el.myText.test('::')){
var dual = el.myText.split('::');
el.myTitle = dual[0].trim();
el.myText = dual[1].trim();
}
el.onmouseover = function(){
this.show(el);
return false;
}.bind(this);
el.onmousemove = this.locate.bindAsEventListener(this);
el.onmouseout = function(){
this.timer = $clear(this.timer);
this.disappear();
}.bind(this);
}, this);
},
show: function(el){
this.toolTitle.innerHTML = el.myTitle;
this.toolText.innerHTML = el.myText;
this.timer = $clear(this.timer);
this.fx.options.transition = this.options.transitionStart;
this.timer = this.appear.delay(this.options.timeOut, this);
},
appear: function(){
this.fx.custom(this.fx.now, this.options.maxOpacity);
},
locate: function(evt){
var doc = document.documentElement;
this.toolTip.setStyles({'top': evt.clientY + doc.scrollTop + 15 + 'px', 'left': evt.clientX + doc.scrollLeft - 30 + 'px'});
},
disappear: function(){
this.fx.options.transition = this.options.transitionEnd;
this.fx.custom(this.fx.now, 0);
}
});
Fx.Elements = Fx.Base.extend({
initialize: function(elements, options){
this.elements = [];
elements.each(function(el){
this.elements.push($(el));
}, this);
this.setOptions(options);
this.now = {};
},
setNow: function(){
for (var i in this.from){
var iFrom = this.from[i];
var iTo = this.to[i];
var iNow = this.now[i] = {};
for (var p in iFrom) iNow[p] = this.compute(iFrom[p], iTo[p]);
}
},
custom: function(objObjs){
if (this.timer && this.options.wait) return;
var from = {};
var to = {};
for (var i in objObjs){
var iProps = objObjs[i];
var iFrom = from[i] = {};
var iTo = to[i] = {};
for (var prop in iProps){
iFrom[prop] = iProps[prop][0];
iTo[prop] = iProps[prop][1];
}
}
return this.parent(from, to);
},
increase: function(){
for (var i in this.now){
var iNow = this.now[i];
for (var p in iNow) this.setStyle(this.elements[i.toInt()], p, iNow[p]);
}
}
});
Fx.Accordion = Fx.Elements.extend({
extendOptions: function(options){
Object.extend(this.options, Object.extend({
start: 'open-first',
fixedHeight: false,
fixedWidth: false,
alwaysHide: false,
wait: false,
onActive: Class.empty,
onBackground: Class.empty,
height: true,
opacity: true,
width: false
}, options || {}));
},
initialize: function(togglers, elements, options){
this.parent(elements, options);
this.extendOptions(options);
this.previousClick = 'nan';
togglers.each(function(tog, i){
$(tog).addEvent('click', function(){this.showThisHideOpen(i)}.bind(this));
}, this);
this.togglers = togglers;
this.h = {}; this.w = {}; this.o = {};
this.elements.each(function(el, i){
this.now[i] = {};
$(el).setStyles({'height': 0, 'overflow': 'hidden'});
}, this);
switch(this.options.start){
case 'first-open': this.elements[0].setStyle('height', this.elements[0].scrollHeight+this.options.unit); break;
case 'open-first': this.showThisHideOpen(0); break;
}
},
hideThis: function(i){
if (this.options.height) this.h = {'height': [this.elements[i].offsetHeight, 0]};
if (this.options.width) this.w = {'width': [this.elements[i].offsetWidth, 0]};
if (this.options.opacity) this.o = {'opacity': [this.now[i]['opacity'] || 1, 0]};
},
showThis: function(i){
if (this.options.height) this.h = {'height': [this.elements[i].offsetHeight, this.options.fixedHeight || this.elements[i].scrollHeight]};
if (this.options.width) this.w = {'width': [this.elements[i].offsetWidth, this.options.fixedWidth || this.elements[i].scrollWidth]};
if (this.options.opacity) this.o = {'opacity': [this.now[i]['opacity'] || 0, 1]};
},
showThisHideOpen: function(iToShow){
if (iToShow != this.previousClick || this.options.alwaysHide){
this.previousClick = iToShow;
var objObjs = {};
var err = false;
var madeInactive = false;
this.elements.each(function(el, i){
this.now[i] = this.now[i] || {};
if (i != iToShow){
this.hideThis(i);
} else if (this.options.alwaysHide){
if (el.offsetHeight == el.scrollHeight){
this.hideThis(i);
madeInactive = true;
} else if (el.offsetHeight == 0){
this.showThis(i);
} else {
err = true;
}
} else if (this.options.wait && this.timer){
this.previousClick = 'nan';
err = true;
} else {
this.showThis(i);
}
objObjs[i] = Object.extend(this.h, Object.extend(this.o, this.w));
}, this);
if (err) return;
if (!madeInactive) this.options.onActive.call(this, this.togglers[iToShow], iToShow);
this.togglers.each(function(tog, i){
if (i != iToShow || madeInactive) this.options.onBackground.call(this, tog, i);
}, this);
return this.custom(objObjs);
}
}
});
-->
Accordion with color transition example - solutoire.com
Accordion with color transition example - solutoire.com
See the 'Javascript used in this example' tab for the options used in this example.
Click me!
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In eu elit. Sed consequat neque et sapien. In hac habitasse platea dictumst. In hac habitasse platea
dictumst. Donec justo dui, aliquam ac, feugiat nec, malesuada ac, enim. Etiam consequat nulla eget metus malesuada tincidunt. Ut ultrices nonummy metus.
Pellentesque pharetra neque eu urna. In nec ligula. Curabitur purus ligula, consectetuer id, auctor et, gravida pretium, est. Aenean vitae neque. Integer dolor
enim, ultricies semper, ullamcorper at, mollis at, mauris.
Click me!
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In eu elit. Sed consequat neque et sapien. In hac habitasse platea dictumst. In hac habitasse platea
dictumst. Donec justo dui, aliquam ac, feugiat nec, malesuada ac, enim. Etiam consequat nulla eget metus malesuada tincidunt. Ut ultrices nonummy metus.
Pellentesque pharetra neque eu urna. In nec ligula. Curabitur purus ligula, consectetuer id, auctor et, gravida pretium, est. Aenean vitae neque. Integer dolor
enim, ultricies semper, ullamcorper at, mollis at, mauris.
Javascript used in this example
var accordion;
var accordionTogglers;
var accordionContents;
window.onload = function() {
accordionTogglers = document.getElementsByClassName('accToggler');
accordionTogglers.each(function(toggler){
//remember the original color
toggler.origColor = toggler.getStyle('background-color');
//set the effect
toggler.fx = new Fx.Color(toggler, 'background-color');
});
accordionContents = document.getElementsByClassName('accContent');
accordion = new Fx.Accordion(accordionTogglers,
accordionContents,{
//when an element is opened change the
//background color to blue
onActive: function(toggler){
toggler.fx.toColor('#6899CE');
},
onBackground: function(toggler){
//change the background color to the original (green)
//color when another toggler is pressed
toggler.setStyle('background-color', toggler.origColor);
}
});
}
CSS used in this example
.accToggler{
margin: 3px auto;
padding: 3px;
width: 400px;
background: #acc95f;
color: #f4f4f4;
border: 1px solid #fff;
cursor: pointer;
}
.accContent{
margin: 0px auto;
width: 400px;
}
©2006 solutoire.com