Usability enhancement: font size and CSS: a a a

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Post Reply
User avatar
Kosse
Posts: 1066
Joined: Thu 9. Sep 2004, 12:08
Location: Brussels, Belgium
Contact:

Usability enhancement: font size and CSS: a a a

Post by Kosse »

Hi all,

this is not really new but I've used it in my two last projects (http://www.srdu.be) and Liro just asked me how did I manage to put the famous aaa (increase-decrease font size). I replied the PM and thought it could be usefull to publish it here too (though I have the feeling that I've read it before in the forum but don't remember where and a search didn't give results... :oops: ):

It's based on:
- adding some lines to the frontend.js
- duplicating your frontend.css in two other files (frontend_a.css and frontend_aa.css)
- the html code for displaying the functionnality
- putting 2 lines of code in your header (in your template).
- images for the aaa.

So, here it goes:

1. frontend.js (in phpwcms_templates/inc_js/frontend.js)


Add this (at the end of the file for example) to your frontend.js:

Code: Select all

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
2. Duplicate your frontend.css and create two other files (for example frontend_a.css --> bigger and frontend_aa.css --> biggest).
Change the values of ALL css where font-size is used (typically the h1, h2, etc., the p tag, and so on...)
I use to increase everything by 2 px or .2em in the frontend_a.css and 4 px in the frontend_aa.css.


3. Displaying the feature: add this where you want the aaa to display in your page:

Code: Select all

<a onclick="setActiveStyleSheet('default'); return false;" href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('_a','','picture/menu/_a_.gif',0)"><img src="picture/menu/_a.gif" name="_a" alt="Normaal" title="Normaal" border="0"></a><a onclick="setActiveStyleSheet('a'); return false;" href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('_aa','','picture/menu/_aa_.gif',0)"><img src="picture/menu/_aa.gif" name="_aa" alt="Groter" title="Groter" border="0"></a><a onclick="setActiveStyleSheet('aa'); return false;" href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('_aaa','','picture/menu/_aaa_.gif',0)"><img src="picture/menu/_aaa.gif" name="_aaa" alt="Grootste" title="Grootste" border="0"></a><br>
I created 6 images to use:
a, the default font size (named it _a.gif and _a_.gif for the mouse hover gif)
a, bigger font size (named it _aa.gif and _aa_.gif for the mouse hover gif)
a, biggest font size (named it _aaa.gif and _aaa_.gif for the mouse hover gif)

:!: Be carefull, I put my images in picture/menu, you can change that of course. You can use the same images I created, no problem. (other example in http://www.mjlaloy.be)
:!: Replace the ALT and TTITLE attributes with your own language (dutch in this exmaple)

4. Adding 2 lines in your template, in your header:

Code: Select all

<link rel="alternate stylesheet" type="text/css" href="phpwcms_template/inc_css/frontend_a.css" title="a"/>
<link rel="alternate stylesheet" type="text/css" href="phpwcms_template/inc_css/frontend_aa.css" title="aa"/> 
Be sure to upload frontend_a.css and frontend_aa.css ;)

Voilà, I hope that this is usefull for you too.
PS: I know that you can increase/decrease font sizes by using your browser but A LOT of people don't ;)

Cheers
User avatar
Fulvio Romanin
Posts: 394
Joined: Thu 4. Dec 2003, 11:12
Location: Udine, Italy
Contact:

Post by Fulvio Romanin »

uh, stupid question: why simply not modify stuff setting a variable instead of a complete new css?
Completeness is reached through subtraction, not through addition
User avatar
Kosse
Posts: 1066
Joined: Thu 9. Sep 2004, 12:08
Location: Brussels, Belgium
Contact:

Post by Kosse »

A simple css switch has been implemented by OG, based on sessions:
http://www.phpwcms.de/forum/viewtopic.p ... highlight=

But never worked neatly with me, IE and FF had different reactions.
As for the variables... What do you mean :?: Sorry didn't get you... (I'm slow, you know that ;)

I just replace the css values in my css file, takes me about 10 minutes per stylesheet. :P

Off course handling the size of text through ...mmmm say the conf.template_default.inc.php would be nice... but is it worth all the trouble?

Cheers
Post Reply