Bug 20489 Configure illegal file characters https://bugzilla.wikimedia.org/show_bug...
[mediawiki.git] / js2 / mwEmbed / jquery / plugins / jquery.pngFix.js
blobe80b56890f4d7021b18996034e3aadc27ceb0510
1 /**
2  * --------------------------------------------------------------------
3  * jQuery-Plugin "pngFix"
4  * Version: 1.2, 09.03.2009
5  * by Andreas Eberhard, andreas.eberhard@gmail.com
6  *                      http://jquery.andreaseberhard.de/
7  *
8  * Copyright (c) 2007 Andreas Eberhard
9  * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
10  *
11  * Changelog:
12  *    09.03.2009 Version 1.2
13  *    - Update for jQuery 1.3.x, removed @ from selectors
14  *    11.09.2007 Version 1.1
15  *    - removed noConflict
16  *    - added png-support for input type=image
17  *    - 01.08.2007 CSS background-image support extension added by Scott Jehl, scott@filamentgroup.com, http://www.filamentgroup.com
18  *    31.05.2007 initial Version 1.0
19  * --------------------------------------------------------------------
20  * @example $(function(){$(document).pngFix();});
21  * @desc Fixes all PNG's in the document on document.ready
22  *
23  * jQuery(function(){jQuery(document).pngFix();});
24  * @desc Fixes all PNG's in the document on document.ready when using noConflict
25  *
26  * @example $(function(){$('div.examples').pngFix();});
27  * @desc Fixes all PNG's within div with class examples
28  *
29  * @example $(function(){$('div.examples').pngFix( { blankgif:'ext.gif' } );});
30  * @desc Fixes all PNG's within div with class examples, provides blank gif for input with png
31  * --------------------------------------------------------------------
32  */
34 (function($) {
36 jQuery.fn.pngFix = function(settings) {
38         // Settings
39         settings = jQuery.extend({
40                 blankgif: 'blank.gif'
41         }, settings);
43         var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
44         var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
46         if (jQuery.browser.msie && (ie55 || ie6)) {
48                 //fix images with png-source
49                 jQuery(this).find("img[src$=.png]").each(function() {
51                         jQuery(this).attr('width',jQuery(this).width());
52                         jQuery(this).attr('height',jQuery(this).height());
54                         var prevStyle = '';
55                         var strNewHTML = '';
56                         var imgId = (jQuery(this).attr('id')) ? 'id="' + jQuery(this).attr('id') + '" ' : '';
57                         var imgClass = (jQuery(this).attr('class')) ? 'class="' + jQuery(this).attr('class') + '" ' : '';
58                         var imgTitle = (jQuery(this).attr('title')) ? 'title="' + jQuery(this).attr('title') + '" ' : '';
59                         var imgAlt = (jQuery(this).attr('alt')) ? 'alt="' + jQuery(this).attr('alt') + '" ' : '';
60                         var imgAlign = (jQuery(this).attr('align')) ? 'float:' + jQuery(this).attr('align') + ';' : '';
61                         var imgHand = (jQuery(this).parent().attr('href')) ? 'cursor:hand;' : '';
62                         if (this.style.border) {
63                                 prevStyle += 'border:'+this.style.border+';';
64                                 this.style.border = '';
65                         }
66                         if (this.style.padding) {
67                                 prevStyle += 'padding:'+this.style.padding+';';
68                                 this.style.padding = '';
69                         }
70                         if (this.style.margin) {
71                                 prevStyle += 'margin:'+this.style.margin+';';
72                                 this.style.margin = '';
73                         }
74                         var imgStyle = (this.style.cssText);
76                         strNewHTML += '<span '+imgId+imgClass+imgTitle+imgAlt;
77                         strNewHTML += 'style="position:relative;white-space:pre-line;display:inline-block;background:transparent;'+imgAlign+imgHand;
78                         strNewHTML += 'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;';
79                         strNewHTML += 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + jQuery(this).attr('src') + '\', sizingMethod=\'scale\');';
80                         strNewHTML += imgStyle+'"></span>';
81                         if (prevStyle != ''){
82                                 strNewHTML = '<span style="position:relative;display:inline-block;'+prevStyle+imgHand+'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;'+'">' + strNewHTML + '</span>';
83                         }
85                         jQuery(this).hide();
86                         jQuery(this).after(strNewHTML);
88                 });
90                 // fix css background pngs
91                 jQuery(this).find("*").each(function(){
92                         var bgIMG = jQuery(this).css('background-image');
93                         if(bgIMG.indexOf(".png")!=-1){
94                                 var iebg = bgIMG.split('url("')[1].split('")')[0];
95                                 jQuery(this).css('background-image', 'none');
96                                 jQuery(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')";
97                         }
98                 });
99                 
100                 //fix input with png-source
101                 jQuery(this).find("input[src$=.png]").each(function() {
102                         var bgIMG = jQuery(this).attr('src');
103                         jQuery(this).get(0).runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + bgIMG + '\', sizingMethod=\'scale\');';
104                 jQuery(this).attr('src', settings.blankgif)
105                 });
106         
107         }
108         
109         return jQuery;
113 })(jQuery);