1/* 2 * jQuery pngfix plugin 3 * Version 1.6 (05/09/2007) 4 * @requires jQuery v1.1.3 5 * 6 * Examples at: http://khurshid.com/jquery/iepnghack/ 7 * Copyright (c) 2007 Kush M. 8 * Dual licensed under the MIT and GPL licenses: 9 * http://www.opensource.org/licenses/mit-license.php 10 * http://www.gnu.org/licenses/gpl.html 11 */ 12 /** 13 * 14 * @example 15 * 16 * optional if location of pixel.gif if different to default which is images/pixel.gif 17 * $.pngfix('media/pixel.gif'); 18 * 19 * $('img[@src$=.png], #panel').pngfix(); 20 * 21 * @apply hack to all png images and #panel which icluded png img in its css 22 * 23 * @name pngfix 24 * @type jQuery 25 * @cat Plugins/Image 26 * @return jQuery 27 * @author jQuery Community 28 */ 29 30(function($) { 31 32 /** 33 * helper variables and function 34 */ 35 $.pngfix = function(customPixel) { 36 $.pngfix.pixel = customPixel; 37 }; 38 39 $.pngfix.getPixel = function() { 40 return $.pngfix.pixel || '/images/pixel.gif'; 41 }; 42 43 var hack = { 44 ltie7 : $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent), 45 filter : function(src) { 46 return "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,sizingMethod=crop,src='"+src+"')"; 47 } 48 }; 49 /** 50 * Applies ie png hack to selected dom elements 51 * 52 * $('img[@src$=.png]').pngfix(); 53 * @desc apply hack to all images with png extensions 54 * 55 * $('#panel, img[@src$=.png]').pngfix(); 56 * @desc apply hack to element #panel and all images with png extensions 57 * 58 * @name pngfix 59 * @type jQuery 60 * @cat Plugins/pngfix 61 */ 62 $.fn.pngfix = hack.ltie7 ? function() { 63 return this.each(function() { 64 var $$ = $(this); 65 var base = $('base').attr('href'); // need to use this in case you are using rewriting urls 66 if ($$.is('img') || $$.is('input')) { // hack image tags present in dom 67 if ($$.attr('src').match(/.*\.png([?].*)?$/i)) { // make sure it is png image 68 // use source tag value if set 69 var source = (base && $$.attr('src').substring(0,1)!='/') ? base + $$.attr('src') : $$.attr('src'); 70 // apply filter 71 $$.css({filter:hack.filter(source), width:$$.width(), height:$$.height()}) 72 .attr({src:$.pngfix.getPixel()}) 73 .positionFix(); 74 } 75 } else { // hack png css properties present inside css 76 var image = $$.css('backgroundImage'); 77 if (image.match(/^url\(["']?(.*\.png([?].*)?)["']?\)$/i)) { 78 image = RegExp.$1; 79 $$.css({backgroundImage:'none', filter:hack.filter(image)}) 80 .positionFix(); 81 } 82 } 83 }); 84 } : function() { return this; }; 85 /** 86 * Removes any png hack that may have been applied previously 87 * 88 * $('img[@src$=.png]').pngunfix(); 89 * @desc revert hack on all images with png extensions 90 * 91 * $('#panel, img[@src$=.png]').iepnghack(); 92 * @desc revert hack on element #panel and all images with png extensions 93 * 94 * @name pngunfix 95 * @type jQuery 96 * @cat Plugins/iepnghack 97 */ 98 $.fn.pngunfix = hack.ltie7 ? function() { 99 return this.each(function() { 100 var $$ = $(this); 101 var src = $$.css('filter'); 102 if (src.match(/src=["']?(.*\.png([?].*)?)["']?/i)) { // get img source from filter 103 src = RegExp.$1; 104 if ($$.is('img') || $$.is('input')) { 105 $$.attr({src:src}).css({filter:''}); 106 } else { 107 $$.css({filter:'', background:'url('+src+')'}); 108 } 109 } 110 }); 111 } : function() { return this; }; 112 /** 113 * positions selected item relatively 114 */ 115 $.fn.positionFix = function() { 116 return this.each(function() { 117 var $$ = $(this); 118 var position = $$.css('position'); 119 if (position != 'absolute' && position != 'relative') { 120 $$.css({position:'relative'}); 121 } 122 }); 123 }; 124 125})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.