Showing posts with label Blogger. Show all posts
Showing posts with label Blogger. Show all posts

04 April 2011

Qué hay de nuevo viejo?

Parece que Blogger se está poniendo las pilas...


y ahora con esto que llaman "vistas dinámicas"...


A ver si me auto-aplico estas novedades como revulsivo, porque después de casi un año de bloguear "por obligación" en el curro, me está entrando el gusanillo de volver a postear también aquí, en mi pobre y pseudo-abandonado blog...

P.D. Además ahora la "vista previa" de los post es mucho más decente!

20 October 2009

Blogger header with random background images

This post is a translation/summary of my original post in Spanish.

I will explain how to get a different random image as background image of the Blogger header. Searching a little bit on Internet I found 2 variants for achieving it, both with Javascript and CSS:

  • Defining for the header a CSS style (with a background image), and when the page is loaded, using Javascript for redefining the style (changing the image). This implies accessing to header's elements (through ID, objects, attributes...).
  • Assigning to the header a "new CSS style", and when the page starts loading, using Javascript for generating the "new CSS style" with the new background image.
I chose the second one for my solution. What we need:
  • Some knowledge about CSS and Javascript.
  • A background image for the header already set, and the rest of images with the same dimensions.
  • Some kind of hosting service in order to put the images (and a small Javascript file).
  • Free access to these images (and the file) trough URL like:
    • http://server/my/images/image0.jpg
    • http://server/my/images/image1.jpg
    • ...
How to proceed:
  • Publish our images.
  • Generate a Javascript file (I named it mylib.js) and publish it too. This file with the following content:
var NUMBER_OF_IMAGES = 5;

function createClassRandomImage() {
imgId
= Math.floor(Math.random() * NUMBER_OF_IMAGES);
document.write(
'<style type="text/css">\n');
document.write(
' .random_image { background-image: url("http://server/my/images/image' + imgId + '.jpg"); }\n');
document.write(
'<\/style>\n');
}

createClassRandomImage();

  • Inside Blogger template, add before the end of the HEAD the following line in order to load the Javascript file:
...
]]>
</b:skin>

<script src='http://server/my/images/mylib.js' type='text/javascript'/>

</head>
<body>
...

  • Also inside Blogger template (with widgets expanded), search the following piece of code, and edit it adding a new "class" attribute and removing the URL of the original image. That is, from this:
...
<div expr:style='&quot;background-image: url(\&quot;&quot; + data:sourceUrl + &quot;\&quot;); &quot;
+ &quot;background-position: &quot;
+ data:backgroundPositionStyleStr + &quot;; &quot;
+ data:widthStyleStr
+ &quot;min-height: &quot; + data:height + &quot;px;&quot;
+ &quot;_height: &quot; + data:height + &quot;px;&quot;
+ &quot;background-repeat: no-repeat; &quot;' id
='header-inner'>
...

  • to this:
...
<div class='random_image' expr:style='&quot;background-image: &quot;
+ &quot;background-position: &quot;
+ data:backgroundPositionStyleStr + &quot;; &quot;
+ data:widthStyleStr
+ &quot;min-height: &quot; + data:height + &quot;px;&quot;
+ &quot;_height: &quot; + data:height + &quot;px;&quot;
+ &quot;background-repeat: no-repeat; &quot;' id
='header-inner'>
...

  • Save the modifications... and it should work :)
In this case, there are configured 5 images (variable named NUMBER_OF_IMAGES inside Javascript file). In order to configure more it's necessary just editing this file and publishing new images in the same way.

11 October 2009

Imagen de fondo aleatoria en la cabecera de Blogger

Siguiendo con la lista de cambios que llevo haciendo en diseño del blog esta nueva temporada, ahora he añadido el que la imagen de la cabecera del blog cambie aleatoriamente cada vez que se visita el blog o se accede a un post concreto. Y por si a alguien le interesa, voy a explicar la forma en que lo he hecho.

Buscando un poco en Internet para ver cómo lo habían hecho otras personas (no necesariamente con Blogger) me encontré con dos opciones. En las dos opciones intervienen tanto CSS como Javascript. Éstas son:

  • Predefinir con CSS un estilo (con una imagen de fondo) para la cabecera, y al cargar la página, mediante Javascript, redefinir ese estilo (para cambiar la imagen) accediendo a los elementos de la cabecera (a partir de identificadores, objetos, atributos, valores...).
  • Asignar a la cabecera un estilo inexsistente, y al cargar la página, mediante Javascript, generar un trozo de código CSS que defina ese estilo con una imagen aleatoria cada vez.
Yo me he basado en la segunda, que a mi juicio resulta mucho más sencilla y más "limpia".

Lo que necesitamos a priori es:
  • Saber un poco de CSS y Javascript.
  • Que el blog tenga ya una imagen de fondo en la cabecera, y que las imágenes que vayamos a usar tengan esas mismas dimensiones.
  • Disponer de un espacio público en Internet donde alojar las imágenes (y un pequeño fichero Javascript que facilitará el trabajo).
  • Que las imágenes (y el fichero Javascript) sean accesibles a través de URLs del estilo:
    • http://servidor/mis/imagenes/imagen0.jpg
    • http://servidor/mis/imagenes/imagen1.jpg
    • ...
Para el tema del alojamiento yo he usado una carpeta pública de DropBox, ya que por ejemplo hacerlo con PicasaWeb sería más complicado por el tema de los nombres de las imágenes y las URLs que tienen asociadas.

Entonces, la forma de proceder es la siguiente:
  • Publicar las imágenes que queramos.
  • Generar un fichero Javascript (yo lo he llamado mylib.js) y publicarlo también. El fichero Javascript con el siguiente contenido:
var NUMBER_OF_IMAGES = 5;

function createClassRandomImage() {
imgId
= Math.floor(Math.random() * NUMBER_OF_IMAGES);
document.write(
'<style type="text/css">\n');
document.write(
' .random_image { background-image: url("http://servidor/mis/imagenes/imagen' + imgId + '.jpg"); }\n');
document.write(
'<\/style>\n');
}

createClassRandomImage();

  • En la plantilla HTML de Blogger añadir antes del final del HEAD la siguiente línea para cargar el fichero Javascript:
...
]]>
</b:skin>

<script src='http://servidor/mis/imagenes/mylib.js' type='text/javascript'/>

</head>
<body>
...

  • También en la plantilla HTML de Blogger (expandiendo los widgets), buscar el siguiente trozo de código, y editarlo añadiendo un atributo class y quitando la url de la imagen original, para pasar de esto:
...
<div expr:style='&quot;background-image: url(\&quot;&quot; + data:sourceUrl + &quot;\&quot;); &quot;
+ &quot;background-position: &quot;
+ data:backgroundPositionStyleStr + &quot;; &quot;
+ data:widthStyleStr
+ &quot;min-height: &quot; + data:height + &quot;px;&quot;
+ &quot;_height: &quot; + data:height + &quot;px;&quot;
+ &quot;background-repeat: no-repeat; &quot;' id
='header-inner'>
...

  • a esto:
...
<div class='random_image' expr:style='&quot;background-image: &quot;
+ &quot;background-position: &quot;
+ data:backgroundPositionStyleStr + &quot;; &quot;
+ data:widthStyleStr
+ &quot;min-height: &quot; + data:height + &quot;px;&quot;
+ &quot;_height: &quot; + data:height + &quot;px;&quot;
+ &quot;background-repeat: no-repeat; &quot;' id
='header-inner'>
...

  • Guardar los cambios... y ya debería funcionar :)
En este caso hay configuradas 5 imágenes (variable NUMBER_OF_IMAGES del fichero Javascript). Para configurar más o menos imágenes simplemente hay que variar ese número y añadir las imágenes junto con las otras... sin tener que tocar nada más en la plantilla del blog.

17 September 2009

Barra de navegación en Blogger

Aprovechando el empuje de haber retomado el blog estoy haciendo algunos cambios en la plantilla. Lo primero ha sido añadir una "barra de navegación" o "barra de menú" debajo de la cabecera del blog.

Aunque pueda parecer complicado es mucho más fácil de lo que parece. Buscando un poco en Internet encontré este artículo donde está explicado de una forma bastante directa y sencilla.

Es necesario hacer dos cosas básicamente:

  • Añadir los links: Esto se hace desde la edición de la plantilla, en la sección de editar los elementos de la página. Hay que añadir un gadget de tipo HTML/Javascript justo debajo de la cabecera. Y el contenido de ese gadget será una lista de links HTML de toda la vida.
  • Darles la apariencia de menú: Una vez se han añadido los links, hay que editar el HTML de la página desde la sección correspondiente. Se tiene que añadir en la parte donde se definen los estilos CSS el código CSS necesario para hacer bonitos los links que hemos añadido antes.
Y ya está. Como digo, parece complicado pero no lo es.

También he aprovechado para cambiar la cabecera del blog en sí, pero este nuevo diseño es temporal... estamos trabajando en ello :)