Hope this helps
// $Id $
Drupal.behaviors.textResize = function(context) {
var resizeScope = 1.1;
// Which div or page element are we resizing?
if (text_resize_scope) { // Admin-specified scope takes precedence.
if ($('#'+text_resize_scope).length > 0) {
var element_to_resize = $('#'+text_resize_scope); // ID specified by admin
}
else if ($('.'+text_resize_scope).length > 0) {
var element_to_resize = $('.'+text_resize_scope); // CLASS specified by admin
}
else {
var element_to_resize = $(text_resize_scope); // It's just a tag specified by admin
}
}
else { // Look for some default scopes that might exist.
if ($('DIV.left-corner').length > 0) {
var element_to_resize = $('DIV.left-corner'); // Main body div for Garland
}
else if ($('#content-inner').length > 0) {
var element_to_resize = $('#content-inner'); // Main body div for Zen-based themes
}
else if ($('#squeeze > #content').length > 0) {
var element_to_resize = $('#squeeze > #content'); // Main body div for Zen Classic
}
}
// Set the initial font size if necessary
if ($.cookie('text_resize') != null) {
element_to_resize.css('font-size', parseFloat($.cookie('text_resize')) + 'px');
//alert( "Should be size: " + $.cookie('text_resize'));
}
else {
//alert('Couldn\'t find text_resize cookie.');
}
if (text_resize_line_height_allow) {
//alert('line height adjustment allowed! The current line-height is '+parseFloat(element_to_resize.css('line-height'), 10));
// Set the initial line height if necessary
if ($.cookie('text_resize_line_height') != null) {
element_to_resize.css('line-height', parseFloat($.cookie('text_resize_line_height')) + 'px');
}
}
// Changer links will change the text size when clicked
$('a.changer').click(function() {
resize(this);
});
function resize (changer) {
// Set the current font size of the specified section as a variable
var current_font_size = parseFloat(element_to_resize.css('font-size'), 10);
// Set the current line-height
var current_line_height = parseFloat(element_to_resize.css('line-height'), 10);
// Pre define vars
var new_font_size = false;
var new_line_height = false;
var allow_change = false;
var reset_size_max = false
var reset_size_min = false;
var reset_size_null = false;
// javascript lets us choose which link was clicked, by ID
if (changer.id == 'text_resize_increase') {
font_increase();
}
else if (changer.id == 'text_resize_decrease') {
font_decrease();
}
else if (changer.id == 'text_resize_reset') {
set_cookie_sizes(null, null);
reset_size_null = true;
}
// jQuery lets us set the font size value of the main text div
if (allow_change == true) {
return set_font_size(new_font_size, new_line_height);
} else if (reset_size_null == true) {
return set_font_size(null, null)
} else if (reset_size_min == true) {
return set_font_size(text_resize_minimum, text_resize_line_height_min);
} else if (reset_size_max == true) {
return set_font_size(text_resize_maximum, text_resize_line_height_max);
}
function font_increase () {
new_font_size = current_font_size * resizeScope;
new_line_height = current_line_height * resizeScope;
// Allow resizing as long as font size doesn't go above text_resize_maximum.
if (new_font_size <= text_resize_maximum) {
//alert(new_font_size +' > '+ text_resize_maximum);
set_cookie_sizes(new_font_size, new_line_height);
allow_change = true;
}
else {
set_cookie_sizes(text_resize_maximum, text_resize_line_height_max);
reset_size_max = true;
}
}
function font_decrease () {
new_font_size = current_font_size / resizeScope;
new_line_height = current_line_height / resizeScope;
if (new_font_size >= text_resize_minimum) {
// Allow resizing as long as font size doesn't go below text_resize_minimum.
set_cookie_sizes(new_font_size, new_line_height);
allow_change = true;
}
else {
// If it goes below text_resize_minimum, just leave it at text_resize_minimum.
set_cookie_sizes(text_resize_minimum, text_resize_line_height_min);
reset_size_min = true;
}
}
function set_cookie_sizes(text_size, line_height) {
$.cookie('text_resize', text_size, { path: '/' });
if (text_resize_line_height_allow)
$.cookie('text_resize_line_height', line_height, { path: '/' });
}
function set_font_size (font_size, line_height) {
// add + px if input is different than null
if (font_size != null && line_height != null) {
font_size = font_size + 'px';
line_height = line_height + 'px';
}
element_to_resize.css('font-size', font_size);
if (text_resize_line_height_allow)
element_to_resize.css('line-height', line_height + 'px');
return false;
}
}
}
Comments
Comment #1
attheshow commentedSorry, we'll need some clarification on what improvements you've made and why you think they're better. What were you trying to accomplish when you modified the code?
Also, here's how to make patches:
http://drupal.org/patch/create
Comment #2
Ganganation commentedFunctional I did not really change anything. I attempted to make it a more flexible, understandable & editable JS file for later purposes.
Like adding more css classes. If you like the idea, I will make an patch.
It's all tested and it works: http://partoer.amdev.nl/
Comment #3
attheshow commentedSince no additional functionality is providing here, marking as won't fix.