/* * flip! jquery plugin (http://lab.smashup.it/flip/) * @author luca manno (luca@smashup.it) [http://i.smashup.it] * [original idea by nicola rizzo (thanks!)] * * @version 0.9.9 [nov. 2009] * * @changelog * v 0.9.9 -> fix transparency over non-colored background. added dontchangecolor option. * added $clone and $this parameters to on.. callback functions. * force hexadecimal color values. made safe for noconflict use. * some refactoring. [henrik hjelte, jul. 10, 2009] * added revert options, fixes and improvements on color management. * released in nov 2009 * v 0.5 -> added patch to make it work with opera (thanks to peter siewert), added callbacks [feb. 1, 2008] * v 0.4.1 -> fixed a regression in chrome and safari caused by gettransparent [oct. 1, 2008] * v 0.4 -> fixed some bugs with transparent color. now flip! works on non-white backgrounds | update: jquery.color.js plugin or jqueryui still needed :( [sept. 29, 2008] * v 0.3 -> now is possibile to define the content after the animation. * (jquery object or text/html is allowed) [sept. 25, 2008] * v 0.2 -> fixed chainability and buggy innertext rendering (xnephilimx thanks!) * v 0.1 -> starting release [sept. 11, 2008] * */ (function($) { function int_prop(fx){ fx.elem.style[ fx.prop ] = parseint(fx.now,10) + fx.unit; } var throwerror=function(message) { throw({name:"jquery.flip.js plugin error",message:message}); }; var isie6orolder=function() { // user agent sniffing is clearly out of fashion and $.browser will be be deprectad. // now, i can't think of a way to feature detect that ie6 doesn't show transparent // borders in the correct way. // until then, this function will do, and be partly political correct, allowing // 0.01 percent of the internet users to tweak with their useragent string. // // not leadingwhitespace is to separate ie family from, well who knows? // maybe some version of opera? // the second guess behind this is that ie7+ will keep supporting maxheight in the future. // first guess changed to dean edwards ie sniffing http://dean.edwards.name/weblog/2007/03/sniff/ return (/*@cc_on!@*/false && (typeof document.body.style.maxheight === "undefined")); }; // some named colors to work with // from interface by stefan petre // http://interface.eyecon.ro/ var colors = { aqua:[0,255,255], azure:[240,255,255], beige:[245,245,220], black:[0,0,0], blue:[0,0,255], brown:[165,42,42], cyan:[0,255,255], darkblue:[0,0,139], darkcyan:[0,139,139], darkgrey:[169,169,169], darkgreen:[0,100,0], darkkhaki:[189,183,107], darkmagenta:[139,0,139], darkolivegreen:[85,107,47], darkorange:[255,140,0], darkorchid:[153,50,204], darkred:[139,0,0], darksalmon:[233,150,122], darkviolet:[148,0,211], fuchsia:[255,0,255], gold:[255,215,0], green:[0,128,0], indigo:[75,0,130], khaki:[240,230,140], lightblue:[173,216,230], lightcyan:[224,255,255], lightgreen:[144,238,144], lightgrey:[211,211,211], lightpink:[255,182,193], lightyellow:[255,255,224], lime:[0,255,0], magenta:[255,0,255], maroon:[128,0,0], navy:[0,0,128], olive:[128,128,0], orange:[255,165,0], pink:[255,192,203], purple:[128,0,128], violet:[128,0,128], red:[255,0,0], silver:[192,192,192], white:[255,255,255], yellow:[255,255,0], transparent: [255,255,255] }; var accepthexcolor=function(color) { if(color && color.indexof("#")==-1 && color.indexof("(")==-1){ return "rgb("+colors[color].tostring()+")"; } else { return color; } }; $.extend( $.fx.step, { bordertopwidth : int_prop, borderbottomwidth : int_prop, borderleftwidth: int_prop, borderrightwidth: int_prop }); $.fn.revertflip = function(){ return this.each( function(){ var $this = $(this); $this.flip($this.data('fliprevertedsettings')); }); }; $.fn.flip = function(settings){ return this.each( function() { var $this=$(this), flipobj, $clone, diroption, diroptions, newcontent, ie6=isie6orolder(); if($this.data('fliplock')){ return false; } var revertedsettings = { direction: (function(direction){ switch(direction) { case "tb": return "bt"; case "bt": return "tb"; case "lr": return "rl"; case "rl": return "lr"; default: return "bt"; } })(settings.direction), bgcolor: accepthexcolor(settings.color) || "#999", color: accepthexcolor(settings.bgcolor) || $this.css("background-color"), content: $this.html(), speed: settings.speed || 500, onbefore: settings.onbefore || function(){}, onend: settings.onend || function(){}, onanimation: settings.onanimation || function(){} }; $this .data('fliprevertedsettings',revertedsettings) .data('fliplock',1) .data('flipsettings',revertedsettings); flipobj = { width: $this.width(), height: $this.height(), bgcolor: accepthexcolor(settings.bgcolor) || $this.css("background-color"), fontsize: $this.css("font-size") || "12px", direction: settings.direction || "tb", tocolor: accepthexcolor(settings.color) || "#fdfcf6", speed: settings.speed || 500, top: $this.offset().top, left: $this.offset().left, target: settings.content || null, transparent: "transparent", dontchangecolor: settings.dontchangecolor || false, onbefore: settings.onbefore || function(){}, onend: settings.onend || function(){}, onanimation: settings.onanimation || function(){} }; // this is the first part of a trick to support // transparent borders using chroma filter for ie6 // the color below is arbitrary, lets just hope it is not used in the animation ie6 && (flipobj.transparent="#fdfcf6"); $clone= $this.css("visibility","hidden") .clone(true) .data('fliplock',1) .appendto("body") .html("") .css({visibility:"visible",position:"absolute",left:flipobj.left,top:flipobj.top,margin:0,zindex:9999,"-webkit-box-shadow":"0px 0px 0px #000","-moz-box-shadow":"0px 0px 0px #000"}); var defaultstart=function() { return { backgroundcolor: flipobj.transparent, fontsize:0, lineheight:0, bordertopwidth:0, borderleftwidth:0, borderrightwidth:0, borderbottomwidth:0, bordertopcolor:flipobj.transparent, borderbottomcolor:flipobj.transparent, borderleftcolor:flipobj.transparent, borderrightcolor:flipobj.transparent, background: "none", borderstyle:'solid', height:0, width:0 }; }; var defaulthorizontal=function() { var waist=(flipobj.height/100)*25; var start=defaultstart(); start.width=flipobj.width; return { "start": start, "first": { bordertopwidth: 0, borderleftwidth: waist, borderrightwidth: waist, borderbottomwidth: 0, bordertopcolor: '#fdfcf6', borderbottomcolor: '#fdfcf6', top: (flipobj.top+(flipobj.height/2)), left: (flipobj.left-waist)}, "second": { borderbottomwidth: 0, bordertopwidth: 0, borderleftwidth: 0, borderrightwidth: 0, bordertopcolor: flipobj.transparent, borderbottomcolor: flipobj.transparent, top: flipobj.top, left: flipobj.left} }; }; var defaultvertical=function() { var waist=(flipobj.height/100)*25; var start=defaultstart(); start.height=flipobj.height; return { "start": start, "first": { bordertopwidth: waist, borderleftwidth: 0, borderrightwidth: 0, borderbottomwidth: waist, borderleftcolor: '#fdfcf6', borderrightcolor: '#fdfcf6', top: flipobj.top-waist, left: flipobj.left+(flipobj.width/2)}, "second": { bordertopwidth: 0, borderleftwidth: 0, borderrightwidth: 0, borderbottomwidth: 0, borderleftcolor: flipobj.transparent, borderrightcolor: flipobj.transparent, top: flipobj.top, left: flipobj.left} }; }; diroptions = { "tb": function () { var d=defaulthorizontal(); d.start.bordertopwidth=flipobj.height; d.start.bordertopcolor=flipobj.bgcolor; d.second.borderbottomwidth= flipobj.height; d.second.borderbottomcolor= flipobj.tocolor; return d; }, "bt": function () { var d=defaulthorizontal(); d.start.borderbottomwidth=flipobj.height; d.start.borderbottomcolor= flipobj.bgcolor; d.second.bordertopwidth= flipobj.height; d.second.bordertopcolor= flipobj.tocolor; return d; }, "lr": function () { var d=defaultvertical(); d.start.borderleftwidth=flipobj.width; d.start.borderleftcolor=flipobj.bgcolor; d.second.borderrightwidth= flipobj.width; d.second.borderrightcolor= flipobj.tocolor; return d; }, "rl": function () { var d=defaultvertical(); d.start.borderrightwidth=flipobj.width; d.start.borderrightcolor=flipobj.bgcolor; d.second.borderleftwidth= flipobj.width; d.second.borderleftcolor= flipobj.tocolor; return d; } }; diroption=diroptions[flipobj.direction](); // second part of ie6 transparency trick. ie6 && (diroption.start.filter="chroma(color="+flipobj.transparent+")"); newcontent = function(){ var target = flipobj.target; return target && target.jquery ? target.html() : target; }; $clone.queue(function(){ flipobj.onbefore($clone,$this); $clone.html('').css(diroption.start); $clone.dequeue(); }); $clone.animate(diroption.first,flipobj.speed); $clone.queue(function(){ flipobj.onanimation($clone,$this); $clone.dequeue(); }); $clone.animate(diroption.second,flipobj.speed); $clone.queue(function(){ if (!flipobj.dontchangecolor) { $this.css({backgroundcolor: flipobj.tocolor}); } $this.css({visibility: "visible"}); var nc = newcontent(); if(nc){$this.html(nc);} $clone.remove(); flipobj.onend($clone,$this); $this.removedata('fliplock'); $clone.dequeue(); }); }); }; })(jquery);