PDA

View Full Version : Making Document Text Sizer Persistant



T313C0mun1s7
04-06-2005, 05:50 PM
In regards to Document Text Sizer by Taewook Kang
http://www.dynamicdrive.com/dynamicindex9/textsizer.htm

I am using (a version) of this script for accessibility to change the text size of the content div of my webpage. You can see it in action at:
http://www.keeptechworking.com

Of course every time a visitor returns or visits a new page it is reset and any changes need to be reapplied. I know there must be a way to make this persistent, but not being a developer I don't know how to do it. Anybodyís help with this would be greatly appreciated.

The way I envision it, any visit where the control goes unused would have no effect. However, whenever a person used the control it would set or modify a cookie that maintains the changed text size on all other pages within my domain for this and all future sessions. That is unless they delete the cookie. ;)

Thank you very much for any assistance you can provide.

mwinter
04-06-2005, 06:35 PM
I am using (a version) of this script for accessibility to change the text size of the content div of my webpage.Users can use their built-in resizing options. Opera and Firefox both provide powerful resizing functionality. However, for IE users to use the Text Size menu option successfully, you must refrain from specifying font sizes using pixels (or points). Use percentages instead. Moreover, if you don't make the font size so small in the first place, they won't need to make it larger, will they? ;)

To directly address your query, persistence is very possible. However, I'd prefer you to at least think over the above before resorting to a script.

Mike

T313C0mun1s7
04-06-2005, 06:56 PM
Sure there are many views on this, and many browsers have also tried to address the issue. That has nothing to do with my question.

The fact is that many older people have the double issue of not understanding the technology they are using to make these changes and therefore need the control to be very obvious (as in on the page they are viewing) to find it, and poorer that average vision. Plus, differences between DPI of the MAC and the PC platforms as well as resolution make any attempt to set a large enough text size impossible. What might be pleasing size wise to me at 1600x1200 would be so large as to change the page formatting to be unusable to others at 640x320 (and yes they are still about there.)

I am sorry if I seem a bit short about this, but I have spent the last three days looking for the answer to this, and in forum after forum I just keep finding people telling others why they should change what they are trying to do. The fact is what you suggest is not any better; it just shifts the inherent problems to different areas. Plus, being on owner and administrator of a few forums myself I am a bit over sensitve to 1) people who post without answering the original topic of the thread 2) people who hijack others threads. I don't mean to upset or offend you, but I am just looking for an aswer, not a prolinged disscussion on why what I want to do is wrong.

What I am doing is based on the different browsers defaults. I view each page in many different browsers using the defaults. The users who donít know how to configure the browser should have a pleasant experience. Those like yourself that do know how to set the browsers display up the way you like may possibly experience some issues with the display. I am sorry if that happens, but you know how to fix it, and it is your own fault for changing it.

My attempt to use this text size script is not so that I make my page more fun for those who want to play with the style sheet. It is just to allow someone who finds the text uncomfortable to read for an extended period a chance to make a quick and persistent change for there own comfort.

mwinter
04-09-2005, 10:30 PM
Thanks you, but I did not ask for preacing.Well, you're about to get a little more in a moment but in any case, I am sure you appreciate that I don't know what you've considered and I'm not about to hand out inappropriate solutions when there are better alternatives.

By the way, why are you so concerned about accessibility when your site it totally useless without client-side scripting support? That would seem to be a bigger issue to me.


Sure there are many views on this, and many browsers have also tried to address the issue. That has nothing to do with my question.I beg to differ. If an existing solution is available, why create a new one? Particularly one which is deficient.


The fact is that many older people have the double issue of not understanding the technology they are using to make these changes and therefore need the control to be very obvious (as in on the page they are viewing) to find it, and poorer that average vision.Which is why the sensible approach is to avoid setting the font size at all. In any case, I'm not going to get into this particular debate. It's been done to death on Usenet. Read through Google's archives if you wish.


Those like yourself that do know how to set the browsers display up the way you like may possibly experience some issues with the display. I am sorry if that happens, but you know how to fix it, and it is your own fault for changing it.Excuse me? No, it is your fault as an author for thinking you know better than your users. Whilst in some cases that may be true, it is no excuse for creating a design which breaks when used with settings that are not default, then passing that off as "their fault". User agents allow adjustments because a user should be able to set preferences that are comfortable for them. It is your job to live with those choices, not blame your visitors for making them.

The following code has not been completely tested. It also relies on two supporting scripts, currently attached as text files. The Hashtable "class" needs to be included first, followed by the cookie object, then the code below.

The cookie code, like the code below is new so it too may suffer from bugs. I also don't like the look of it (I have a thing for code aesthetics), but I'll leave any refactoring for some other time. Note that the bug warnings are precautionary, only: I anticipate no problems, but I can't guarantee none. Anyway, you get what you pay for. :p

Whilst the code is hefty, stripping out comments, whitespace, and unused functions will dramatically reduce file size. The first two can be done mechanically with a tool like JSMin.


var fontSize = (function(global) {
var cookieName = 'fontSize',
cookieLifetime = 7, /* In days. */
cookiePath = '/',
data = new Hashtable(),
defaultOrdinal = 2,
spectrum = ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'],
tags = ['div', 'td', 'p'],
_h, _i;

function Pair(ordinal, literal) {
this.ordinal = ordinal; this.literal = literal;
}
Pair.toString = function() {
return '{ordinal=' + this.ordinal + ', literal=' + this.literal + '}';
};

if(cookie.isSupported()) {
_h = global.onload;
global.onload = function() {
var c = cookie.get(cookieName);

if(c && (c = c.match(/[^,{ ]+=\{[^}]+\}/g))) {
for(var i = 0, n = c.length, l, t, v; i < n; ++i) {
if((v = /([^=]+)=\{ordinal=(\d+), literal=([^}]*)\}/.exec(c[i ]))) {
data.put((t = v[1]), new Pair(v[2], '');
if((l = v[3])) {_i.set(t, l);}
}
}
}
if(_h) {global.onload = _h; global.onload();}
};
}

return (_i = {
decrease : function(target, delta) {var t = data.get(target);
if(!delta || ('number' != typeof delta)) {delta = 1;}
this.set(target, ((t && t.ordinal) || defaultOrdinal) - delta
+ spectrum.length);
},
increase : function(target, delta) {var t = data.get(target);
if(!delta || ('number' != typeof delta)) {delta = 1;}
this.set(target, ((t && t.ordinal) || defaultOrdinal) + delta
+ spectrum.length);
},
set : function(target, value) {
var t = data.get(target) || new Pair(defaultOrdinal, ''),
element;

switch(typeof value) {
case 'number':
value = spectrum[current = value % spectrum.length];
data.put(target, new Pair(value, ''));
break;
case 'string':
data.put(target, new Pair(data.get(target).ordinal, value));
break;
default: return;
}

if(document.getElementById && (element = document.getElementById(target))
&& element.getElementByTagName)
{
cookie.put(cookieName, data.toString(), cookieLifetime, cookiePath);
if(element.style) {element.style.fontSize = value;}
for(var i = 0, m = tags.length, c; i < m; ++i) {
c = element.getElementByTagName(tags[i ]);

for(var j = 0, n = c.length, s; j < n; ++j) {
if((s = c[j].style)) {s.fontSize = value;}
}
}
}
}
});
})(this);The fontSize object has three methods: increase, decrease, and set. All three take two arguments: a target id, and a value. For the first two methods, the value is a delta which defaults to one, and specifies how far along the spectrum of sizes to shift from the current location. The latter method take either a string or a number. A string argument is a literal value to be used to set the font-size style property. A number argument is an absolute position within the spectrum.

When storing values, both the ordinal and any specified literal will be recorded. However, setting an ordinal will erase a literal if one exists. When loading, a literal will take precedence.

Mike