[SPIP Zone] [Spip-zone-commit] r18189 - in /_plugins_/_stable_/crayons: crayons.js.html js/crayons.js js/jquery.px.js

Curieux ça : pourquoi "Mi" ?
Normalement, la taille d'un "em" c'est la largeur d'un "M", non ?
Ou alors il y a une référence plus subtile..

On 1/26/08, fil@rezo.net <fil@rezo.net> wrote:

Author: fil@rezo.net
Date: Sat Jan 26 10:06:50 2008
New Revision: 18189

Log:
comme MSIE ne sait pas toujours donner sa fontSize en pixels, on insere un <span> avec les lettres 'Mi', et on regarde la largeur du bloc

Added:
    _plugins_/_stable_/crayons/js/jquery.px.js
Modified:
    _plugins_/_stable_/crayons/crayons.js.html
    _plugins_/_stable_/crayons/js/crayons.js

Modified: _plugins_/_stable_/crayons/crayons.js.html

--- _plugins_/_stable_/crayons/crayons.js.html (original)
+++ _plugins_/_stable_/crayons/crayons.js.html Sat Jan 26 10:06:50 2008
@@ -19,6 +19,8 @@

[(#CHEMIN{js/jquery.form.js}|pack_cQuery)]

+[(#CHEMIN{js/jquery.px.js}|pack_cQuery)]
+
[(#CHEMIN{js/crayons.js}|pack_cQuery)]

[(#CHEMIN{js/resizehandle.js}|pack_cQuery)]

Modified: _plugins_/_stable_/crayons/js/crayons.js

--- _plugins_/_stable_/crayons/js/crayons.js (original)
+++ _plugins_/_stable_/crayons/js/crayons.js Sat Jan 26 10:06:50 2008
@@ -105,10 +105,10 @@
         'w': $(this).width(),
         'h': $(this).height(),
         'wh': window.innerHeight,
- 'em': $(this).css('fontSize'),
+ 'em': $(this).px('fontSize'), // eviter un bug MSIE sur fontSize
         'class': me.className,
         'color': $(this).css('color'),
- 'font-size': $(this).css('fontSize'),
+ 'font-size': $(this).px('fontSize'),
         'font-family': $(this).css('fontFamily'),
         'font-weight': $(this).css('fontWeight'),
         'line-height': $(this).css('lineHeight'),

Added: _plugins_/_stable_/crayons/js/jquery.px.js

--- _plugins_/_stable_/crayons/js/jquery.px.js (added)
+++ _plugins_/_stable_/crayons/js/jquery.px.js Sat Jan 26 10:06:50 2008
@@ -0,0 +1,17 @@
+(function($){
+ $.fn.px = function(prop) {
+ var val;
+ if($.browser.msie) {
+ $('<span>Mi<\/span>')
+ .appendTo(this[0])
+ .each(function(){
+ val = parseInt($(this).width()) + 'px';
+ })
+ .remove();
+ } else {
+ val = this.css(prop);
+ }
+ return val;
+ };
+
+})(jQuery);

_______________________________________________
Spip-zone-commit@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-zone-commit

Curieux ça : pourquoi "Mi" ?
Normalement, la taille d'un "em" c'est la largeur d'un "M", non ?

oui j'ai commencé avec M, et c'était trop petit :slight_smile:

Ou alors il y a une référence plus subtile..

Je compte sur des gens comme toi pour remettre un M avec le bon
calcul. L'idée c'est d'obtenir la fontSize, en regardant la largeur
(ou hauteur) d'une lettre.

-- Fil

Et pourquoi ne pas passer par les CSS ?
Je propose juste un petit changement :

+(function($){
+ $.fn.px = function(prop) {
+ var val;
+ if($.browser.msie) {
+ $('<span><\/span>')
                         .css({'display': 'block','width': '1em'})
+ .appendTo(this[0])
+ .each(function(){
+ val = parseInt($(this).width()) + 'px';
+ })
+ .remove();
+ } else {
+ val = this.css(prop);
+ }
+ return val;
+ };
+
+})(jQuery);

Vu que j en'utilise pas crayon c'est purement théorique.

.Gilles

On 1/26/08, Gilles Vincent <gilles.vincent@gmail.com> wrote:

> --- _plugins_/_stable_/crayons/js/jquery.px.js (added)
> +++ _plugins_/_stable_/crayons/js/jquery.px.js Sat Jan 26 10:06:50 2008
> @@ -0,0 +1,17 @@
> +(function($){
> + $.fn.px = function(prop) {
> + var val;
> + if($.browser.msie) {
> + $('<span>Mi<\/span>')
> + .appendTo(this[0])
> + .each(function(){
> + val = parseInt($(this).width()) + 'px';
> + })
> + .remove();
> + } else {
> + val = this.css(prop);
> + }
> + return val;
> + };
> +
> +})(jQuery);
>
> _______________________________________________
> Spip-zone-commit@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-zone-commit
>

Et pourquoi ne pas passer par les CSS ?
Je propose juste un petit changement :

Oui c'est parfait !

Vu que j en'utilise pas crayon c'est purement théorique.

Dans le mille :slight_smile: