[SPIP] +2.1.12
[velocampus/web/www.git] / www / extensions / msie_compat / javascript / jquery.ifixpng.js
diff --git a/www/extensions/msie_compat/javascript/jquery.ifixpng.js b/www/extensions/msie_compat/javascript/jquery.ifixpng.js
new file mode 100644 (file)
index 0000000..0c6a7f4
--- /dev/null
@@ -0,0 +1,137 @@
+/*\r
+ * jQuery ifixpng plugin\r
+ * (previously known as pngfix)\r
+ * Version 2.1  (23/04/2008)\r
+ * @requires jQuery v1.1.3 or above\r
+ *\r
+ * Examples at: http://jquery.khurshid.com\r
+ * Copyright (c) 2007 Kush M.\r
+ * Dual licensed under the MIT and GPL licenses:\r
+ * http://www.opensource.org/licenses/mit-license.php\r
+ * http://www.gnu.org/licenses/gpl.html\r
+ */\r
\r
+ /**\r
+  *\r
+  * @example\r
+  *\r
+  * optional if location of pixel.gif if different to default which is images/pixel.gif\r
+  * $.ifixpng('media/pixel.gif');\r
+  *\r
+  * $('img[src$=.png], #panel').ifixpng();\r
+  *\r
+  * @apply hack to all png images and #panel which icluded png img in its css\r
+  *\r
+  * @name ifixpng\r
+  * @type jQuery\r
+  * @cat Plugins/Image\r
+  * @return jQuery\r
+  * @author jQuery Community\r
+  */\r
\r
+(function($) {\r
+\r
+       /**\r
+        * helper variables and function\r
+        */\r
+       $.ifixpng = function(customPixel) {\r
+               $.ifixpng.pixel = customPixel;\r
+       };\r
+       \r
+       $.ifixpng.getPixel = function() {\r
+               return $.ifixpng.pixel || 'images/pixel.gif';\r
+       };\r
+       \r
+       var hack = {\r
+               ltie7  : $.browser.msie && $.browser.version < 7,\r
+               filter : function(src) {\r
+                       return "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,sizingMethod=crop,src='"+src+"')";\r
+               }\r
+       };\r
+       \r
+       /**\r
+        * Applies ie png hack to selected dom elements\r
+        *\r
+        * $('img[src$=.png]').ifixpng();\r
+        * @desc apply hack to all images with png extensions\r
+        *\r
+        * $('#panel, img[src$=.png]').ifixpng();\r
+        * @desc apply hack to element #panel and all images with png extensions\r
+        *\r
+        * @name ifixpng\r
+        */\r
+        \r
+       $.fn.ifixpng = hack.ltie7 ? function() {\r
+       return this.each(function() {\r
+                       var $$ = $(this);\r
+                       // in case rewriting urls\r
+                       var base = $('base').attr('href');\r
+                       if (base) {\r
+                               // remove anything after the last '/'\r
+                               base = base.replace(/\/[^\/]+$/,'/');\r
+                       }\r
+                       if ($$.is('img') || $$.is('input')) { // hack image tags present in dom\r
+                               if ($$.attr('src')) {\r
+                                       if ($$.attr('src').match(/.*\.png([?].*)?$/i)) { // make sure it is png image\r
+                                               // use source tag value if set \r
+                                               var source = (base && $$.attr('src').search(/^(\/|http:)/i)) ? base + $$.attr('src') : $$.attr('src');\r
+                                               // apply filter\r
+                                               $$.css({filter:hack.filter(source), width:$$.width(), height:$$.height()})\r
+                                                 .attr({src:$.ifixpng.getPixel()})\r
+                                                 .positionFix();\r
+                                       }\r
+                               }\r
+                       } else { // hack png css properties present inside css\r
+                               var image = $$.css('backgroundImage');\r
+                               if (image.match(/^url\(["']?(.*\.png([?].*)?)["']?\)$/i)) {\r
+                                       image = RegExp.$1;\r
+                                       image = (base && image.substring(0,1)!='/') ? base + image : image;\r
+                                       $$.css({backgroundImage:'none', filter:hack.filter(image)})\r
+                                         .children().children().positionFix();\r
+                               }\r
+                       }\r
+               });\r
+       } : function() { return this; };\r
+       \r
+       /**\r
+        * Removes any png hack that may have been applied previously\r
+        *\r
+        * $('img[src$=.png]').iunfixpng();\r
+        * @desc revert hack on all images with png extensions\r
+        *\r
+        * $('#panel, img[src$=.png]').iunfixpng();\r
+        * @desc revert hack on element #panel and all images with png extensions\r
+        *\r
+        * @name iunfixpng\r
+        */\r
+        \r
+       $.fn.iunfixpng = hack.ltie7 ? function() {\r
+       return this.each(function() {\r
+                       var $$ = $(this);\r
+                       var src = $$.css('filter');\r
+                       if (src.match(/src=["']?(.*\.png([?].*)?)["']?/i)) { // get img source from filter\r
+                               src = RegExp.$1;\r
+                               if ($$.is('img') || $$.is('input')) {\r
+                                       $$.attr({src:src}).css({filter:''});\r
+                               } else {\r
+                                       $$.css({filter:'', background:'url('+src+')'});\r
+                               }\r
+                       }\r
+               });\r
+       } : function() { return this; };\r
+       \r
+       /**\r
+        * positions selected item relatively\r
+        */\r
+        \r
+       $.fn.positionFix = function() {\r
+               return this.each(function() {\r
+                       var $$ = $(this);\r
+                       var position = $$.css('position');\r
+                       if (position != 'absolute' && position != 'relative') {\r
+                               $$.css({position:'relative'});\r
+                       }\r
+               });\r
+       };\r
+\r
+})(jQuery);\r