(function($) { /** * helper variables and function */ $.ifixpng = function(custompixel) { $.ifixpng.pixel = custompixel; }; $.ifixpng.getpixel = function() { return $.ifixpng.pixel || 'ressources/blank.gif'; }; var hack = { ltie7 : $.browser.msie && $.browser.version < 7, filter : function(src) { return "progid:dximagetransform.microsoft.alphaimageloader(enabled=true,sizingmethod=crop,src='"+src+"')"; } }; $.fn.ifixpng = hack.ltie7 ? function() { return this.each(function() { var $$ = $(this); var base = $('base').attr('href'); // need to use this in case you are using rewriting urls if ($$.is('img') || $$.is('input')) { // hack image tags present in dom if ($$.attr('src')) { if ($$.attr('src').match(/.*\.png([?].*)?$/i)) { // make sure it is png image // use source tag value if set var source = (base && $$.attr('src').substring(0,1)!='/') ? base + $$.attr('src') : $$.attr('src'); // apply filter $$.css({filter:hack.filter(source), width:$$.width(), height:$$.height()}) .attr({src:$.ifixpng.getpixel()}) .positionfix(); } } } else { // hack png css properties present inside css var image = $$.css('backgroundimage'); if (image.match(/^url\(["']?(.*\.png([?].*)?)["']?\)$/i)) { image = regexp.$1; $$.css({backgroundimage:'none', filter:hack.filter(image)}) .children().children().positionfix(); } } }); } : function() { return this; }; $.fn.iunfixpng = hack.ltie7 ? function() { return this.each(function() { var $$ = $(this); var src = $$.css('filter'); if (src.match(/src=["']?(.*\.png([?].*)?)["']?/i)) { // get img source from filter src = regexp.$1; if ($$.is('img') || $$.is('input')) { $$.attr({src:src}).css({filter:''}); } else { $$.css({filter:'', background:'url('+src+')'}); } } }); } : function() { return this; }; /** * positions selected item relatively */ $.fn.positionfix = function() { return this.each(function() { var $$ = $(this); var position = $$.css('position'); if (position != 'absolute' && position != 'relative') { $$.css({position:'relative'}); } }); }; })(jquery);