diff --git jquery.pngFix.js jquery.pngFix.js index 9dc4edb..6adfcc9 100644 --- jquery.pngFix.js +++ jquery.pngFix.js @@ -1,111 +1,113 @@ -/** - * -------------------------------------------------------------------- - * jQuery-Plugin "pngFix" - * Version: 1.1, 11.09.2007 - * by Andreas Eberhard, andreas.eberhard@gmail.com - * http://jquery.andreaseberhard.de/ - * - * Copyright (c) 2007 Andreas Eberhard - * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php) - * - * Changelog: - * 11.09.2007 Version 1.1 - * - removed noConflict - * - added png-support for input type=image - * - 01.08.2007 CSS background-image support extension added by Scott Jehl, scott@filamentgroup.com, http://www.filamentgroup.com - * 31.05.2007 initial Version 1.0 - * -------------------------------------------------------------------- - * @example $(function(){$(document).pngFix();}); - * @desc Fixes all PNG's in the document on document.ready - * - * jQuery(function(){jQuery(document).pngFix();}); - * @desc Fixes all PNG's in the document on document.ready when using noConflict - * - * @example $(function(){$('div.examples').pngFix();}); - * @desc Fixes all PNG's within div with class examples - * - * @example $(function(){$('div.examples').pngFix( { blankgif:'ext.gif' } );}); - * @desc Fixes all PNG's within div with class examples, provides blank gif for input with png - * -------------------------------------------------------------------- - */ - -(function($) { - -jQuery.fn.pngFix = function(settings) { - - // Settings - settings = jQuery.extend({ - blankgif: 'blank.gif' - }, settings); - - var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1); - var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1); - - if (jQuery.browser.msie && (ie55 || ie6)) { - - //fix images with png-source - jQuery(this).find("img[@src$=.png]").each(function() { - - jQuery(this).attr('width',jQuery(this).width()); - jQuery(this).attr('height',jQuery(this).height()); - - var prevStyle = ''; - var strNewHTML = ''; - var imgId = (jQuery(this).attr('id')) ? 'id="' + jQuery(this).attr('id') + '" ' : ''; - var imgClass = (jQuery(this).attr('class')) ? 'class="' + jQuery(this).attr('class') + '" ' : ''; - var imgTitle = (jQuery(this).attr('title')) ? 'title="' + jQuery(this).attr('title') + '" ' : ''; - var imgAlt = (jQuery(this).attr('alt')) ? 'alt="' + jQuery(this).attr('alt') + '" ' : ''; - var imgAlign = (jQuery(this).attr('align')) ? 'float:' + jQuery(this).attr('align') + ';' : ''; - var imgHand = (jQuery(this).parent().attr('href')) ? 'cursor:hand;' : ''; - if (this.style.border) { - prevStyle += 'border:'+this.style.border+';'; - this.style.border = ''; - } - if (this.style.padding) { - prevStyle += 'padding:'+this.style.padding+';'; - this.style.padding = ''; - } - if (this.style.margin) { - prevStyle += 'margin:'+this.style.margin+';'; - this.style.margin = ''; - } - var imgStyle = (this.style.cssText); - - strNewHTML += ''; - if (prevStyle != ''){ - strNewHTML = '' + strNewHTML + ''; - } - - jQuery(this).hide(); - jQuery(this).after(strNewHTML); - - }); - - // fix css background pngs - jQuery(this).find("*").each(function(){ - var bgIMG = jQuery(this).css('background-image'); - if(bgIMG.indexOf(".png")!=-1){ - var iebg = bgIMG.split('url("')[1].split('")')[0]; - jQuery(this).css('background-image', 'none'); - jQuery(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')"; - } - }); - - //fix input with png-source - jQuery(this).find("input[@src$=.png]").each(function() { - var bgIMG = jQuery(this).attr('src'); - jQuery(this).get(0).runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + bgIMG + '\', sizingMethod=\'scale\');'; - jQuery(this).attr('src', settings.blankgif) - }); - - } - - return jQuery; - -}; - -})(jQuery); +/** + * -------------------------------------------------------------------- + * jQuery-Plugin "pngFix" + * Version: 1.2, 09.03.2009 + * by Andreas Eberhard, andreas.eberhard@gmail.com + * http://jquery.andreaseberhard.de/ + * + * Copyright (c) 2007 Andreas Eberhard + * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php) + * + * Changelog: + * 09.03.2009 Version 1.2 + * - Update for jQuery 1.3.x, removed @ from selectors + * 11.09.2007 Version 1.1 + * - removed noConflict + * - added png-support for input type=image + * - 01.08.2007 CSS background-image support extension added by Scott Jehl, scott@filamentgroup.com, http://www.filamentgroup.com + * 31.05.2007 initial Version 1.0 + * -------------------------------------------------------------------- + * @example $(function(){$(document).pngFix();}); + * @desc Fixes all PNG's in the document on document.ready + * + * jQuery(function(){jQuery(document).pngFix();}); + * @desc Fixes all PNG's in the document on document.ready when using noConflict + * + * @example $(function(){$('div.examples').pngFix();}); + * @desc Fixes all PNG's within div with class examples + * + * @example $(function(){$('div.examples').pngFix( { blankgif:'ext.gif' } );}); + * @desc Fixes all PNG's within div with class examples, provides blank gif for input with png + * -------------------------------------------------------------------- + */ + +(function($) { + +jQuery.fn.pngFix = function(settings) { + + // Settings + settings = jQuery.extend({ + blankgif: 'blank.gif' + }, settings); + + var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1); + var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1); + + if (jQuery.browser.msie && (ie55 || ie6)) { + + //fix images with png-source + jQuery(this).find("img[src$=.png]").each(function() { + + jQuery(this).attr('width',jQuery(this).width()); + jQuery(this).attr('height',jQuery(this).height()); + + var prevStyle = ''; + var strNewHTML = ''; + var imgId = (jQuery(this).attr('id')) ? 'id="' + jQuery(this).attr('id') + '" ' : ''; + var imgClass = (jQuery(this).attr('class')) ? 'class="' + jQuery(this).attr('class') + '" ' : ''; + var imgTitle = (jQuery(this).attr('title')) ? 'title="' + jQuery(this).attr('title') + '" ' : ''; + var imgAlt = (jQuery(this).attr('alt')) ? 'alt="' + jQuery(this).attr('alt') + '" ' : ''; + var imgAlign = (jQuery(this).attr('align')) ? 'float:' + jQuery(this).attr('align') + ';' : ''; + var imgHand = (jQuery(this).parent().attr('href')) ? 'cursor:hand;' : ''; + if (this.style.border) { + prevStyle += 'border:'+this.style.border+';'; + this.style.border = ''; + } + if (this.style.padding) { + prevStyle += 'padding:'+this.style.padding+';'; + this.style.padding = ''; + } + if (this.style.margin) { + prevStyle += 'margin:'+this.style.margin+';'; + this.style.margin = ''; + } + var imgStyle = (this.style.cssText); + + strNewHTML += ''; + if (prevStyle != ''){ + strNewHTML = '' + strNewHTML + ''; + } + + jQuery(this).hide(); + jQuery(this).after(strNewHTML); + + }); + + // fix css background pngs + jQuery(this).find("*").each(function(){ + var bgIMG = jQuery(this).css('background-image'); + if(bgIMG.indexOf(".png")!=-1){ + var iebg = bgIMG.split('url("')[1].split('")')[0]; + jQuery(this).css('background-image', 'none'); + jQuery(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')"; + } + }); + + //fix input with png-source + jQuery(this).find("input[src$=.png]").each(function() { + var bgIMG = jQuery(this).attr('src'); + jQuery(this).get(0).runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + bgIMG + '\', sizingMethod=\'scale\');'; + jQuery(this).attr('src', settings.blankgif) + }); + + } + + return jQuery; + +}; + +})(jQuery); diff --git jquery.pngFix.pack.js jquery.pngFix.pack.js new file mode 100644 index 0000000..ef4c0c0 --- /dev/null +++ jquery.pngFix.pack.js @@ -0,0 +1,11 @@ +/** + * -------------------------------------------------------------------- + * jQuery-Plugin "pngFix" + * Version: 1.1, 11.09.2007 + * by Andreas Eberhard, andreas.eberhard@gmail.com + * http://jquery.andreaseberhard.de/ + * + * Copyright (c) 2007 Andreas Eberhard + * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php) + */ +eval(function(p,a,c,k,e,r){e=function(c){return(c<62?'':e(parseInt(c/62)))+((c=c%62)>35?String.fromCharCode(c+29):c.toString(36))};if('0'.replace(0,e)==0){while(c--)r[e(c)]=k[c];k=[function(e){return r[e]||e}];e=function(){return'([237-9n-zA-Z]|1\\w)'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(s(m){3.fn.pngFix=s(c){c=3.extend({P:\'blank.gif\'},c);8 e=(o.Q=="t R S"&&T(o.u)==4&&o.u.A("U 5.5")!=-1);8 f=(o.Q=="t R S"&&T(o.u)==4&&o.u.A("U 6.0")!=-1);p(3.browser.msie&&(e||f)){3(2).B("img[n$=.C]").D(s(){3(2).7(\'q\',3(2).q());3(2).7(\'r\',3(2).r());8 a=\'\';8 b=\'\';8 g=(3(2).7(\'E\'))?\'E="\'+3(2).7(\'E\')+\'" \':\'\';8 h=(3(2).7(\'F\'))?\'F="\'+3(2).7(\'F\')+\'" \':\'\';8 i=(3(2).7(\'G\'))?\'G="\'+3(2).7(\'G\')+\'" \':\'\';8 j=(3(2).7(\'H\'))?\'H="\'+3(2).7(\'H\')+\'" \':\'\';8 k=(3(2).7(\'V\'))?\'float:\'+3(2).7(\'V\')+\';\':\'\';8 d=(3(2).parent().7(\'href\'))?\'cursor:hand;\':\'\';p(2.9.v){a+=\'v:\'+2.9.v+\';\';2.9.v=\'\'}p(2.9.w){a+=\'w:\'+2.9.w+\';\';2.9.w=\'\'}p(2.9.x){a+=\'x:\'+2.9.x+\';\';2.9.x=\'\'}8 l=(2.9.cssText);b+=\'\';p(a!=\'\'){b=\'\'+b+\'\'}3(2).hide();3(2).after(b)});3(2).B("*").D(s(){8 a=3(2).11(\'I-12\');p(a.A(".C")!=-1){8 b=a.13(\'url("\')[1].13(\'")\')[0];3(2).11(\'I-12\',\'none\');3(2).14(0).15.J="K:L.t.M(n=\'"+b+"\',N=\'O\')"}});3(2).B("input[n$=.C]").D(s(){8 a=3(2).7(\'n\');3(2).14(0).15.J=\'K:L.t.M(n=\\\'\'+a+\'\\\', N=\\\'O\\\');\';3(2).7(\'n\',c.P)})}return 3}})(3);',[],68,'||this|jQuery||||attr|var|style||||||||||||||src|navigator|if|width|height|function|Microsoft|appVersion|border|padding|margin|span|px|indexOf|find|png|each|id|class|title|alt|background|filter|progid|DXImageTransform|AlphaImageLoader|sizingMethod|scale|blankgif|appName|Internet|Explorer|parseInt|MSIE|align|position|relative|display|inline|block|css|image|split|get|runtimeStyle'.split('|'),0,{})) \ No newline at end of file diff --git pngfix.admin.inc pngfix.admin.inc index 665ad5a..53599b9 100644 --- pngfix.admin.inc +++ pngfix.admin.inc @@ -5,10 +5,10 @@ * @file * Provides the administration page for PNG Fix. */ - + /** * Administration settings page - */ + */ function pngfix_admin() { $form = array(); $form['pngfix_css_classes'] = array( @@ -17,5 +17,14 @@ function pngfix_admin() { '#default_value' => variable_get('pngfix_css_classes', ''), '#description' => t('Comma seperated list of CSS classes to apply the PNG Fix to (use jQuery Selectors). The CSS class must be for the element that surrounds the image, and not for the image itself. In the case of <div class="pngfix"><img ... /></div>, use .pngfix to apply the PNG Fix to the image.', array('@jqueryselector' => 'http://docs.jquery.com/Selectors')), ); + + $form['pngfix_packed_js'] = array( + '#type' => 'radios', + '#title' => t('Enable packed version'), + '#default_value' => variable_get('pngfix_packed_js', 0), + '#description' => t("When enabled packed version of pngFix will be used."), + '#options' => array(t('Disabled'), t('Enabled')), + ); + return system_settings_form($form); } // function pngfix_admin diff --git pngfix.info pngfix.info index 6d44ddc..c07c6ee 100644 --- pngfix.info +++ pngfix.info @@ -1,4 +1,4 @@ ; $Id$ name = PNG Fix description = "Includes a fix to correctly handle PNG transparency in Windows IE 5.5 & 6." -core = 6.x +core = 7.x diff --git pngfix.install pngfix.install index 65b2ae2..214423a 100644 --- pngfix.install +++ pngfix.install @@ -2,9 +2,21 @@ // $Id$ /** - * Implementation of hook_uninstall() - * + * @file + * Module's installation hooks. + */ + +/** + * Implements hook_install(). + */ +function hook_install() { + variable_set('pngfix_packed_js', 0); +} + +/** + * Implements hook_uninstall(). */ function pngfix_uninstall() { variable_del('pngfix_css_classes'); + variable_del('pngfix_packed_js'); } diff --git pngfix.module pngfix.module index 263853e..5adaba5 100644 --- pngfix.module +++ pngfix.module @@ -2,38 +2,47 @@ // $Id$ /** -* Implementation of hook_help -*/ + * Implements hook_help(). + */ function pngfix_help($path = '', $arg = NULL) { $output = ''; switch ($path) { case 'admin/help#pngfix': - case 'admin/settings/pngfix': - $output = '

'. t("Includes a fix to correctly handle PNG transparency in Windows IE 5.5 & 6."). '

'; + case 'admin/config/development/pngfix': + $output = '

' . t("Includes a fix to correctly handle PNG transparency in Windows IE 5.5 & 6.") . '

'; break; } return $output; } // function pngfix_help /** - * Implementation of hook_init - */ + * Implements hook_init(). + */ function pngfix_init() { $pngfixclasses = variable_get('pngfix_css_classes', ''); + $library = variable_get('pngfix_packed_js', 0) ? 'jquery.pngFix.pack.js' : 'jquery.pngFix.js'; if (!empty($pngfixclasses)) { - $jquerypngfixjs = drupal_get_path('module', 'pngfix') .'/jquery.pngFix.js'; - drupal_add_js($jquerypngfixjs, 'module'); - $js = "Drupal.behaviors.pngfix = function(){ $('$pngfixclasses').pngFix(); };"; - drupal_add_js($js, 'inline'); + $jquerypngfixjs = drupal_get_path('module', 'pngfix') . '/' . $library; + drupal_add_js($jquerypngfixjs); + $js = "(function ($) { + + Drupal.behaviors.pngfix = { + attach: function(context, settings) { + $('$pngfixclasses').pngFix(); + } + }; + + })(jQuery);"; + drupal_add_js($js, array('type' => 'inline', 'scope' => 'footer')); } } // function pngfix_init /** - * Implementation of hook_menu - */ + * Implements hook_menu(). + */ function pngfix_menu() { $items = array(); - $items['admin/settings/pngfix'] = array( + $items['admin/config/development/pngfix'] = array( 'title' => 'PNG Fix', 'description' => 'Configure how the PNG Fix operates.', 'access arguments' => array('administer site configuration'),