// Foggy, v1.1 // // Description: jQuery plugin for blurring page elements // Homepage: http://nbartlomiej.github.com/foggy // Author: nbartlomiej@gmail.com (function(a){a.fn.foggy=function(b){var c={opacity:.8,blurRadius:2,quality:16,cssFilterSupport:true};var d={opacity:1,blurRadius:0};var e;if(b==false){e=a.extend(c,d)}else{e=a.extend(c,b)}var f=function(a,b,c,d){this.content=a;this.position=b;this.offset=c;this.opacity=d};f.prototype.render=function(b){a("
",{html:this.content,"class":"foggy-pass-"+this.position}).css({position:this.position,opacity:this.opacity,top:this.offset[0],left:this.offset[1]}).appendTo(b)};var g=function(a){this.radius=a};g.prototype.includes=function(a,b){if(Math.pow(a,2)+Math.pow(b,2)<=Math.pow(this.radius,2)){return true}else{return false}};g.prototype.points=function(){var a=[];for(var b=-this.radius;b<=this.radius;b++){for(var c=-this.radius;c<=this.radius;c++){if(this.includes(b,c)){a.push([b,c])}}}return a};var h=function(a,b){this.element=a;this.settings=b};h.prototype.calculateOffsets=function(b,c){var d=a.grep((new g(b)).points(),function(a){return a[0]!=0||a[1]!=0});var e;if(d.length<=c){e=d}else{var f=d.length-c;var h=[];for(var i=0;i=0){return false}else{return true}})}return e};h.prototype.getContent=function(){var b=a(this.element).find(".foggy-pass-relative")[0];if(b){return a(b).html()}else{return a(this.element).html()}};h.prototype.render=function(){var b=this.getContent();a(this.element).empty();var c=a("
").css({position:"relative"});var d=this.calculateOffsets(this.settings.blurRadius*2,this.settings.quality);var e=this.settings.opacity*1.2/(d.length+1);(new f(b,"relative",[0,0],e)).render(c);a(d).each(function(a,d){(new f(b,"absolute",d,e)).render(c)});c.appendTo(this.element)};var i=function(a,b){this.element=a;this.settings=b};i.prototype.render=function(){var b=(""+e.opacity).slice(2,4);var c=this.settings.blurRadius;a(this.element).css({"-webkit-filter":"blur("+c+"px)",opacity:e.opacity})};return this.each(function(a,b){if(e.cssFilterSupport&&"-webkit-filter"in document.body.style){(new i(b,e)).render()}else{(new h(b,e)).render()}})}})(jQuery)