From 865b6e7755447b707c18dac18d14eac1a5743e31 Mon Sep 17 00:00:00 2001 From: Fil <fil@rezo.net> Date: Fri, 5 Oct 2007 21:29:14 +0000 Subject: [PATCH] on isole la gestion du fix pour MSIE (et on le rend surchargeable) ; le script est maintenant envoye inline, c'est plus rapide et meilleur en bande passante (et encore plus moche en 'voir source' mais peu importe) --- .gitattributes | 1 + ecrire/inc/msiefix.php | 56 +++++++++++++++++++++++++++++++++++++ ecrire/inc/presentation.php | 18 ++++++------ ecrire/public/assembler.php | 35 +++++++---------------- 4 files changed, 75 insertions(+), 35 deletions(-) create mode 100644 ecrire/inc/msiefix.php diff --git a/.gitattributes b/.gitattributes index c62c56e496..9ad6384844 100644 --- a/.gitattributes +++ b/.gitattributes @@ -618,6 +618,7 @@ ecrire/inc/lien.php -text ecrire/inc/message_select.php -text ecrire/inc/minipres.php -text ecrire/inc/modifier.php -text +ecrire/inc/msiefix.php -text ecrire/inc/nfslock.php -text ecrire/inc/notifications.php -text ecrire/inc/petitionner.php -text diff --git a/ecrire/inc/msiefix.php b/ecrire/inc/msiefix.php new file mode 100644 index 0000000000..c7d3908b13 --- /dev/null +++ b/ecrire/inc/msiefix.php @@ -0,0 +1,56 @@ +<?php + +/***************************************************************************\ + * SPIP, Systeme de publication pour l'internet * + * * + * Copyright (c) 2001-2007 * + * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * + * * + * Ce programme est un logiciel libre distribue sous licence GNU/GPL. * + * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * +\***************************************************************************/ + + +if (!defined("_ECRIRE_INC_VERSION")) return; + +// Pour MSIE: reparer le cache des images de background +// Inserer le script jquery.ifixpng.js si necessaire +// Comme MSIE est goret, on n'a pas honte d'inserer comme un goret +// en fin de page +// http://doc.spip.org/@msiefix +function inc_msiefix_dist($texte) { + $texte .= "<script type='text/javascript'><!-- + try { document.execCommand('BackgroundImageCache', false, true); } catch(err) {}; + // --></script>\n"; + + // Si jQuery n'est pas la on ne fixe pas les PNG + if (strpos($texte, 'jquery.js') + AND strpos($texte, '.png') + AND true /* ... autres tests si on veut affiner ... */ + AND lire_fichier(_DIR_RACINE.'dist/javascript/jquery.ifixpng.js', $ifixpng)) { + $texte .= +"<script type='text/javascript'><!-- +if (window.jQuery && jQuery.browser.msie) { +$ifixpng +jQuery.ifixpng('".str_repeat('../', $GLOBALS['profondeur_url']).'rien.gif'."'); +} +// --></script>\n"; + } + + return $texte; +} + + +function presentation_msiefix() { + lire_fichier(_DIR_RACINE.'dist/javascript/jquery.ifixpng.js', $ifixpng); + return "<script type='text/javascript'><!-- + try { document.execCommand('BackgroundImageCache', false, true); } catch(err) {}; + if (window.jQuery && jQuery.browser.msie) { +$ifixpng + jQuery.ifixpng('".str_repeat('../', $GLOBALS['profondeur_url']).'rien.gif'."'); + } + // --></script>"; +} + + +?> diff --git a/ecrire/inc/presentation.php b/ecrire/inc/presentation.php index acac9b8279..9933f4aff4 100644 --- a/ecrire/inc/presentation.php +++ b/ecrire/inc/presentation.php @@ -1258,16 +1258,14 @@ function fin_page() // cf. public/assembler, fonction f_msie() // test si MSIE et sinon quitte - $msie = strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'msie') - AND preg_match('/MSIE /i', $_SERVER['HTTP_USER_AGENT']); - $fix_png = $msie - ? "<script type='text/javascript'><!-- - try { document.execCommand('BackgroundImageCache', false, true); } catch(err) {}; - if (window.jQuery && jQuery.browser.msie) jQuery.getScript( '" - .url_absolue(find_in_path('javascript/jquery.ifixpng.js')) - ."' , function() { $.ifixpng('".url_absolue(_DIR_RACINE.'rien.gif')."'); jQuery('img').ifixpng(); } ); - // --></script>" - : ''; + if ( + strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'msie') + AND preg_match('/MSIE /i', $_SERVER['HTTP_USER_AGENT']) + AND $msiefix = charger_fonction('msiefix', 'inc') + ) + $fix_png = presentation_msiefix(); + else + $fix_png = ''; return debut_grand_cadre(true) . (($spip_display == 4) diff --git a/ecrire/public/assembler.php b/ecrire/public/assembler.php index 522d8b82e2..728be8cd33 100644 --- a/ecrire/public/assembler.php +++ b/ecrire/public/assembler.php @@ -400,33 +400,18 @@ function f_msie ($texte) { if (!$GLOBALS['html']) return $texte; // test si MSIE et sinon quitte - $msie = strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'msie') - AND preg_match('/MSIE /i', $_SERVER['HTTP_USER_AGENT']); - if (!$msie) return $texte; - - // Comme MSIE est goret, on n'a pas honte d'inserer comme un goret - // en fin de page - - // fixer les images background - $texte .= "<script type='text/javascript'><!-- - try { document.execCommand('BackgroundImageCache', false, true); } catch(err) {}; - // --></script>\n"; - - // Si jQuery n'est pas la on ne fixe pas les PNG - if (strpos(strtolower($texte), 'jquery.js') - AND strpos(strtolower($texte), '.png') - AND true /* ... autres tests si on veut affiner ... */) { - include_spip('inc/filtres'); # pour url_absolue :( - $texte .= -"<script type='text/javascript'><!-- -if (window.jQuery && jQuery.browser.msie) jQuery.getScript( '".url_absolue(find_in_path('javascript/jquery.ifixpng.js'))."' , function() { $.ifixpng('".url_absolue(_DIR_RACINE.'rien.gif')."'); jQuery('img').ifixpng(); } ); -// --></script>\n"; - } - - return $texte; + if ( + strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'msie') + AND preg_match('/MSIE /i', $_SERVER['HTTP_USER_AGENT']) + AND $msiefix = charger_fonction('msiefix', 'inc') + ) + return $msiefix($texte); + else + return $texte; } -//ajoute a la volee scripts a le squelette jquery.js.html + +// Ajoute a la volee scripts a le squelette jquery.js.html // http://doc.spip.org/@ajouter_js_affichage_final function ajouter_js_affichage_final($page,$scripts,$inline = false) { if(!$scripts || (!$inline && !preg_match(",\w+\|?,",$scripts)) || ($inline && !preg_match(",^\s*<script.*</script>\s*$,Us",$scripts))) { -- GitLab