Index: text_resize.js
===================================================================
--- text_resize.js	(revision 182)
+++ text_resize.js	(working copy)
@@ -1,101 +1,142 @@
 // $Id $
-Drupal.behaviors.textResize = function(context) {
-  // 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');
-  }
-  if (text_resize_line_height_allow) {
-    // 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() {
-    // Set the current font size of the specified section as a variable
-    var currentFontSize = 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);
-    // javascript lets us choose which link was clicked, by ID
-    if (this.id == 'text_resize_increase') {
-      var new_font_size = currentFontSize * 1.2;
-      if (text_resize_line_height_allow) { var new_line_height = current_line_height * 1.2; }
-      // Allow resizing as long as font size doesn't go above text_resize_maximum.
-      if (new_font_size <= text_resize_maximum) {
-        $.cookie('text_resize', new_font_size, { path: '/' });
-        if (text_resize_line_height_allow) { $.cookie('text_resize_line_height', new_line_height, { path: '/' }); }
-        var allow_change = true;
-      }
-      else {
-        $.cookie('text_resize', text_resize_maximum, { path: '/' });
-        if (text_resize_line_height_allow) { $.cookie('text_resize_line_height', text_resize_line_height_max, { path: '/' }); }
-        var reset_size_max = true;
-      }
-    }
-    else if (this.id == 'text_resize_decrease') {
-      var new_font_size = currentFontSize / 1.2;
-      if (text_resize_line_height_allow) { var new_line_height = current_line_height / 1.2; }
-      if (new_font_size >= text_resize_minimum) {
-        // Allow resizing as long as font size doesn't go below text_resize_minimum.
-        $.cookie('text_resize', new_font_size, { path: '/' });
-        if (text_resize_line_height_allow) { $.cookie('text_resize_line_height', new_line_height, { path: '/' }); }
-        var allow_change = true;
-      }
-      else {
-        // If it goes below text_resize_minimum, just leave it at text_resize_minimum.
-        $.cookie('text_resize', text_resize_minimum, { path: '/' });
-        if (text_resize_line_height_allow) { $.cookie('text_resize_line_height', text_resize_line_height_min, { path: '/' }); }
-        var reset_size_min = true;
-      }
-    }
-    else if (this.id == 'text_resize_reset') {
-      $.cookie('text_resize', null, { path: '/' });
-      if (text_resize_line_height_allow) { $.cookie('text_resize_line_height', null, { path: '/' }); }
-      var reset_size_original = true;
-    }
-    // jQuery lets us set the font size value of the main text div
-    if (allow_change == true) {
-      element_to_resize.css('font-size', new_font_size + 'px'); // Add 'px' onto the end, otherwise ems are used as units by default
-      if (text_resize_line_height_allow) { element_to_resize.css('line-height', new_line_height + 'px'); }
-      return false;
-    }
-    else if (reset_size_min == true) {
-      element_to_resize.css('font-size', text_resize_minimum + 'px');
-      if (text_resize_line_height_allow) { element_to_resize.css('line-height', text_resize_line_height_min + 'px'); }
-      return false;
-    }
-    else if (reset_size_max == true) {
-      element_to_resize.css('font-size', text_resize_maximum + 'px');
-      if (text_resize_line_height_allow) { element_to_resize.css('line-height', text_resize_line_height_max + 'px'); }
-      return false;
-    }
-    else if (reset_size_original == true) {
-      element_to_resize.css('font-size', null);
-      if (text_resize_line_height_allow) { element_to_resize.css('line-height', null); }
-      return false;
-    }
-  });
+if (Drupal.jsEnabled) {
+	$(document).ready(function() {
+		// Which div or page element are we resizing?
+		var trs = text_resize_scope.split(',');
+		text_resize_step = 1 + parseFloat(text_resize_step/100,10);
+		var font_size = ($.cookie('text_resize') != null ? parseInt($.cookie('text_resize'),10) : 0);		
+
+		if(font_size >= text_resize_minimum && font_size <= text_resize_maximum && font_size!=0) {
+			for(i=0;i<trs.length;i++) {			
+				element_to_resize = getResizeScope(trs[i]);
+				
+				element_to_resize.each(function() {
+					initTextElementSize(this,font_size,text_resize_step);
+				});
+			}
+		}
+
+		// Changer links will change the text size when clicked
+		$('a.changer').click(function()	{
+			var click_id = this.id;
+
+			var font_size = $.cookie('text_resize') != null ? parseFloat($.cookie('text_resize'),10) : 0;
+					
+			//calculate the new values
+			if (click_id == 'text_resize_increase') {
+				font_size++;
+			} else if (click_id == 'text_resize_decrease') {				
+				font_size--;				
+			} else {
+				$.cookie('text_resize', 0, { path: '/' });
+				window.location.reload();
+				return false;
+			}
+			
+			if(font_size >= text_resize_minimum && font_size <= text_resize_maximum) {
+				$.cookie('text_resize', font_size, { path: '/' });
+				for(i=0;i<trs.length;i++) {
+					element_to_resize = getResizeScope(trs[i]);
+	
+					element_to_resize.each(function() {
+						resizeTextElement(this,click_id,text_resize_step);					
+					});
+				}
+			}
+		});
+	});
+}
+
+function getResizeScope(text_resize_scope)
+{
+	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
+		}
+	}
+	return element_to_resize;
+}
+
+function resizeTextElement(elem,click_id,text_resize_step)
+{
+		//resize che children elements recursively
+		$(elem).children().each(function() {
+			resizeTextElement(this,click_id,text_resize_step);					
+		});
+
+		var currentFontSize = parseInt($(elem).css('font-size'), 10);
+		var current_line_height = parseInt($(elem).css('line-height'), 10);
+		var newFontSize = 0;
+		if (click_id == 'text_resize_increase') {
+			newFontSize = currentFontSize * text_resize_step;
+			if (text_resize_line_height_allow) {
+				var newLineHeight = current_line_height * text_resize_step;
+			}
+		}else if (click_id == 'text_resize_decrease') {
+			newFontSize = currentFontSize / text_resize_step;
+
+			if (text_resize_line_height_allow) {
+				var newLineHeight = current_line_height / text_resize_step;
+			}
+		}
+		// jQuery lets us set the font size value of the main text div
+		if(newFontSize >= text_resize_min_px && newFontSize <= text_resize_max_px) {
+			$(elem).css('font-size', parseInt(newFontSize) + 'px'); // Add 'px' onto the end, otherwise ems are used as units by default
+			if (text_resize_line_height_allow) { 
+				$(elem).css('line-height', parseInt(newLineHeight) + 'px'); 
+			}
+		}
+}
+
+
+function initTextElementSize(elem,font_size,text_resize_step)
+{    
+		$(elem).children().each(function() {
+			initTextElementSize(this,font_size,text_resize_step);					
+		});
+					
+		var new_font_size   = parseInt($(elem).css('font-size'), 10);
+		var new_line_height = parseInt($(elem).css('line-height'), 10);				
+		
+    if(new_font_size <= text_resize_min_px || new_font_size >= text_resize_max_px)	return;  //do not change elements which are large enough
+    
+    var nfs;
+    
+		while(font_size != 0) {			
+		  
+			nfs = parseInt(font_size > 0 ? new_font_size * text_resize_step : new_font_size/text_resize_step);
+			
+			if(nfs < text_resize_min_px || nfs > text_resize_max_px) {
+			 break; 
+			}
+			
+			new_font_size = nfs;
+			if (text_resize_line_height_allow) {
+				new_line_height = parseInt(font_size > 0 ? new_line_height * text_resize_step : new_line_height/text_resize_step);
+			}	
+						
+			font_size = font_size > 0 ? font_size-1 : font_size+1;
+		}
+				
+		$(elem).css('font-size',  parseInt(new_font_size) + 'px');
+		if (text_resize_line_height_allow) {
+			$(elem).css('line-height', parseInt(new_line_height) + 'px');
+		}				
 }
\ No newline at end of file
Index: text_resize.module
===================================================================
--- text_resize.module	(revision 182)
+++ text_resize.module	(working copy)
@@ -1,4 +1,5 @@
 <?php
+// $Id: text_resize.module,v 1.1.2.7 2009/05/31 04:10:01 attheshow Exp $
 
 /**
  * @file
@@ -28,18 +29,28 @@
   $form = array();
 
   $form['text_resize_scope'] = array(
-    '#type' => 'textfield',
+    '#type' => 'textarea',
+    '#attributes' => array('rows' => 2),
     '#title' => t('Text Resize Scope'),
     '#default_value' => _text_resize_scope(),
-    '#description' => t('Which portion of the body would you like to be resized by the Text Resize block? You may enter either the CSS class attribute, the CSS id attribute, or an HTML tag.<br />For example, if you want all text within &lt;div id="my-container"&gt; to be resized, enter the ID <strong>my-container</strong>.<br />If, on the other hand, you would like all text within the BODY tag to be resized, enter <strong>body</strong>.'),
+    '#description' => t('Which portion of the body would you like to be resized by the Text Resize block? You may enter either the CSS class attribute, the CSS id attribute, or an HTML tag.<br />For example, if you want all text within &lt;div id="my-container"&gt; to be resized, enter the ID <strong>my-container</strong>.<br />If, on the other hand, you would like all text within the BODY tag to be resized, enter <strong>body</strong>. You can enter multiple scopes seperating them by comma. Also you can use JQuery selectors to define the scope.'),
     '#required' => TRUE,
   );
+  
+  $form['text_resize_step'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Text resize step (%)'),
+    '#maxlength' => 2,
+    '#default_value' => _text_resize_step(),
+    '#description' => t('What is the text resize step in %. Default: 10'),
+  );
+
   $form['text_resize_minimum'] = array(
     '#type' => 'textfield',
-    '#title' => t('Default/Minimum Text Size'),
+    '#title' => t('Minimum Text Size'),
     '#maxlength' => 2,
     '#default_value' => _text_resize_minimum(),
-    '#description' => t('What is the smallest font size (in pixels) that your text can be resized to by users?'),
+    '#description' => t('How many times text can be enlarged by "Text resize" step?'),
     '#required' => TRUE,
   );
   $form['text_resize_maximum'] = array(
@@ -47,14 +58,14 @@
     '#title' => t('Maximum Text Size'),
     '#maxlength' => 2,
     '#default_value' => _text_resize_maximum(),
-    '#description' => t('What is the largest font size (in pixels) that your text can be resized to by users?'),
+    '#description' => t('How many times text can be made smaller by "Text resize" step?'),
     '#required' => TRUE,
   );
   $form['text_resize_reset_button'] = array(
     '#type' => 'checkbox',
     '#title' => t('Add Reset Button'),
     '#default_value' => _text_resize_reset_button(),
-    '#description' => t('Do you want to add an extra button to the block to allow the font size to be reset to the default/minimum size set above?'),
+    '#description' => t('Do you want to add an extra button to the block to allow the font size to be reset to normal?'),
   );
   $form['text_resize_line_height_allow'] = array(
     '#type' => 'checkbox',
@@ -62,19 +73,20 @@
     '#default_value' => _text_resize_line_height_allow(),
     '#description' => t('Do you want to allow Text Resize to change the spacing between the lines of text?'),
   );
-  $form['text_resize_line_height_min'] = array(
+  
+  $form['text_resize_min_px'] = array(
     '#type' => 'textfield',
-    '#title' => t('Minimum Line-Height'),
+    '#title' => t('Minimum Text-Size (px)'),
     '#maxlength' => 2,
-    '#default_value' => _text_resize_line_height_min(),
-    '#description' => t('What is the smallest line-height (in pixels) that your text can be resized to by users?'),
+    '#default_value' => _text_resize_min_px(),
+    '#description' => t('Font size limitation to avoid unexpected font sizes'),
   );
-  $form['text_resize_line_height_max'] = array(
+  $form['text_resize_max_px'] = array(
     '#type' => 'textfield',
-    '#title' => t('Maximum Line-Height'),
+    '#title' => t('Maximum Text-Size (px)'),
     '#maxlength' => 2,
-    '#default_value' => _text_resize_line_height_max(),
-    '#description' => t('What is the largest line-height (in pixels) that your text can be resized to by users?'),
+    '#default_value' => _text_resize_max_px(),
+    '#description' => t('Font size limitation to avoid unexpected font sizes'),
   );
   $form = system_settings_form($form);
   // Rebuild the menu after updating the settings.
@@ -147,32 +159,46 @@
   return $text_resize_line_height_allow;
 }
 
-function _text_resize_line_height_min($value = NULL) {
+function _text_resize_min_px($value = NULL) {
   if (is_null($value)) {
-    return _get_text_resize_line_height_min();
+    return _get_text_resize_min_px();
   }
-  variable_set('text_resize_line_height_min', $value);
+  variable_set('text_resize_min_px', $value);
 }
 
 // Get the minimum line height preference specified by the admin
-function _get_text_resize_line_height_min() {
-  $text_resize_line_height_min = variable_get('text_resize_line_height_min', 16);
-  return $text_resize_line_height_min;
+function _get_text_resize_min_px() {
+  $text_resize_min_px = variable_get('text_resize_min_px', 16);
+  return $text_resize_min_px;
 }
 
-function _text_resize_line_height_max($value = NULL) {
+function _text_resize_max_px($value = NULL) {
   if (is_null($value)) {
-    return _get_text_resize_line_height_max();
+    return _get_text_resize_max_px();
   }
-  variable_set('text_resize_line_height_max', $value);
+  variable_set('text_resize_max_px', $value);
 }
 
 // Get the maximum line height preference specified by the admin
-function _get_text_resize_line_height_max() {
-  $text_resize_line_height_max = variable_get('text_resize_line_height_max', 36);
-  return $text_resize_line_height_max;
+function _get_text_resize_max_px() {
+  $text_resize_max_px = variable_get('text_resize_max_px', 36);
+  return $text_resize_max_px;
 }
 
+
+function _text_resize_step($value = NULL) {
+  if (is_null($value)) {
+    return _get_text_resize_step();
+  }
+  variable_set('text_resize_step', $value);
+}
+
+// Get the minimum line height preference specified by the admin
+function _get_text_resize_step() {
+  $text_resize_min_px = variable_get('text_resize_step', 10);
+  return $text_resize_min_px;
+}
+
 /**
  * Implementation of hook_block().
  */
@@ -197,11 +223,12 @@
   drupal_add_css(drupal_get_path('module', 'text_resize') .'/text_resize.css');
   drupal_add_js(drupal_get_path('module', 'text_resize') .'/jquery.cookie.js', 'file');
   drupal_add_js("var text_resize_scope = ". drupal_to_js(_get_text_resize_scope()) .";
+  	var text_resize_step = ". drupal_to_js(_get_text_resize_step()) .";
     var text_resize_minimum = ". drupal_to_js(_get_text_resize_minimum()) .";
     var text_resize_maximum = ". drupal_to_js(_get_text_resize_maximum()) .";
     var text_resize_line_height_allow = ". drupal_to_js(_get_text_resize_line_height_allow()) .";
-    var text_resize_line_height_min = ". drupal_to_js(_get_text_resize_line_height_min()) .";
-    var text_resize_line_height_max = ". drupal_to_js(_get_text_resize_line_height_max()) .";", 'inline');
+    var text_resize_min_px = ". drupal_to_js(_get_text_resize_min_px()) .";
+    var text_resize_max_px = ". drupal_to_js(_get_text_resize_max_px()) .";", 'inline');
   drupal_add_js(drupal_get_path('module', 'text_resize') .'/text_resize.js', 'file');
 }
 
