/** * The MIT License * * Copyright (c) 2009 Jason Wyatt Feinstein * * 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. */ (function($){var logging=false;if($==null){throw new Error("jQuery must be available for jQSlickWrap to be "+"activated.")}if($.fn.slickwrap){throw new Error("A plugin which introduces the function 'slickwrap' to "+"the NodeList object already exists and jQSlickWrap will not "+"function.")}function log(){if(window.console&&logging){if(window.console.log){window.console.log.apply(console,Array.prototype.slice.call(arguments))}}}function slickWrapImage(settings){log("Inside %o calling %s()",this,arguments.callee.name);var $image=$(this);var $parent=$image.parent();var floatDirection=$image.css("float");log(" $(this)=%o, $(this).parent()=$o, floatDirection=%s",$image,$parent,floatDirection);if(floatDirection!="left"&&floatDirection!="right"){return}var padding={top:$image.css('padding-top'),right:$image.css('padding-right'),bottom:$image.css('padding-bottom'),left:$image.css('padding-left')};padding.top=parseInt(padding.top.replace(/[^\d]*/g,""));padding.right=parseInt(padding.right.replace(/[^\d]*/g,""));padding.bottom=parseInt(padding.bottom.replace(/[^\d]*/g,""));padding.left=parseInt(padding.left.replace(/[^\d]*/g,""));var canvas=document.createElement("CANVAS");canvas.width=$image.width()+padding.left+padding.right;canvas.height=$image.height()+padding.top+padding.bottom;var width=canvas.width;var height=canvas.height;var context=canvas.getContext("2d");context.drawImage(this,0,0);var imageData=context.getImageData(0,0,width,height);var data=Array.prototype.slice.call(imageData.data);if(settings.bgColor==null){settings.bgColor={r:data[0],g:data[1],b:data[2],a:data[3]}}context.clearRect(0,0,width,height);context.fillStyle="rgba("+settings.bgColor.r+","+settings.bgColor.g+","+settings.bgColor.b+","+settings.bgColor.a+")";context.fillRect(0,0,width,height);context.drawImage(this,padding.left,padding.top);$parent.css({"background-image":"url("+canvas.toDataURL()+")","background-position":"top "+floatDirection,"background-repeat":"no-repeat"});var divWidths=calculateDivWidths.call(this,canvas,padding,settings.bgColor,settings.resolution,settings.bloomPadding,settings.cutoff);var divs=[];var divHeight=settings.resolution;var divWidths_length=divWidths.length;for(var i=0;i')}$parent.prepend(divs.join(""));var parentHeight=$parent.height();var imageHeight=$image.height()+padding.top;if(parentHeight=0){var upLocation=(x+(y-1)*width)*4+3;bloomedData[dataLocation]=data[upLocation]>0?255:bloomedData[dataLocation]}if(y+10?255:bloomedData[dataLocation]}if(x-1>=0){var leftLocation=(x-1+y*width)*4+3;bloomedData[dataLocation]=data[leftLocation]>0?255:bloomedData[dataLocation]}if(x+10?255:bloomedData[dataLocation]}}}data=bloomedData.slice()}}var paddingSize=bloomPadding?0:(floatDirection=="left"?padding.right:padding.left);var result=[];var rows=height/lineHeight;rows=height%lineHeight==0?rows:rows+1;for(var row=0;row=height?height-1:endY;if(floatDirection=="right"){for(var y=startY;y<=endY;y++){var offset=y*(width*4);var foundAt=width-x;for(var x=startX;x<=endX;x++){var location=x*4+offset;if(data[location+3]==255){foundAt=width-x;break}}if(foundAt>maxWidth){maxWidth=foundAt}}}else{for(var y=startY;y<=endY;y++){var offset=y*(width*4);var foundAt=0;for(var x=startX;x>=endX;x--){var location=x*4+offset;if(data[location+3]==255){foundAt=x;break}}if(foundAt>maxWidth){maxWidth=foundAt}}}result.push(maxWidth+(maxWidth!=0?paddingSize:0))}return result}$.fn.slickWrap=function(args){var settings={bgColor:null,bloomPadding:false,resolution:20,cutoff:5};$.extend(settings,args);return this.each(function(i){if(this.tagName!="img"&&this.tagName!="IMG"){return}if(this.complete){log("%o was already loaded, calling "+"slickWrapImage.call(this)",this);slickWrapImage.call(this,settings)}else{log("%o wasn't loaded yet, calling "+"bind('load', slickWrapImage)",this);$(this).bind("load",function(){slickWrapImage.call(this,settings)})}})};$.fn.slickWrapLineHeight=function(){return 12};var testCanvas=document.createElement("CANVAS");if(testCanvas.getContext==null){$.fn.slickWrap=function(nodes){return this}}})(jQuery);