Thanks for this great module,

Do you think it would be possible to set two or three different classes / id's inside Text Resize Scope field, for example separated by commas ?! That would be re-sized together..

Comments

dlsmore’s picture

I also would love this feature to be added! It seems like the changes would be easy to make, although I am not a php coder so I'm not sure how it would actually be done...

Can anyone suggest how to make this change?

dlsmore’s picture

Ok, turns out it was easier than I expected. Just some minor modifications to sites/all/modules/text_resize/text_resize.js

I don't know how to make patches and whatnot, but here's the modified code:

// $Id: text_resize.js,v 1.1.2.8.2.6 2010/12/29 23:14:13 attheshow Exp $
(function ($) { // JavaScript should be compatible with other libraries than jQuery
  Drupal.behaviors.textResize = { // D7 "Changed Drupal.behaviors to objects having the methods "attach" and "detach"."
    attach: function(context) {      
      var element_to_resize = [];      
      // Which div or page element are we resizing?
      if (text_resize_scope) { // Admin-specified scope takes precedence.
	var text_resize_scope_array = text_resize_scope.split(", ");
	for each (var term in text_resize_scope_array) {
          if ($('#'+term).length > 0) {
            element_to_resize.push($('#'+term)); // ID specified by admin
          }
          else if ($('.'+term).length > 0) {
            element_to_resize.push($('.'+term)); // CLASS specified by admin
          }
          else if ($(term).length > 0) {
            element_to_resize.push($(term)); // It's just a tag specified by admin
          }
	}
      }
      else { // Look for some default scopes that might exist.
        if ($('DIV.left-corner').length > 0) {
          element_to_resize.push('DIV.left-corner'); // Main body div for Garland
        }
        else if ($('#content-inner').length > 0) {
          element_to_resize.push('#content-inner'); // Main body div for Zen-based themes
        }
        else if ($('#squeeze > #content').length > 0) {
          element_to_resize.push('#squeeze > #content'); // Main body div for Zen Classic
        }
      }

      // Set the initial font size if necessary
      for each (var element in element_to_resize) {
        if ($.cookie('text_resize') != null) {
          element.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.css('line-height', parseFloat($.cookie('text_resize_line_height')) + 'px');
          }
        }
      }

      // Changer links will change the text size when clicked
      $('a.changer').click(function() {       
	for each (var element in element_to_resize) {
    	  // Set the current font size of the specified section as a variable
          var currentFontSize = parseFloat(element.css('font-size'), 10);
          // Set the current line-height
          var current_line_height = parseFloat(element.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.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.css('line-height', new_line_height + 'px'); }
            //return false;
          }
          else if (reset_size_min == true) {
            element.css('font-size', text_resize_minimum + 'px');
            if (text_resize_line_height_allow) { element.css('line-height', text_resize_line_height_min + 'px'); }
            //return false;
          }
          else if (reset_size_max == true) {
            element.css('font-size', text_resize_maximum + 'px');
            if (text_resize_line_height_allow) { element.css('line-height', text_resize_line_height_max + 'px'); }
            //return false;
          }
          else if (reset_size_original == true) {
            element.css('font-size', null);
            if (text_resize_line_height_allow) { element.css('line-height', null); }
            //return false;
          }
  	}
      });
    }
  };
})(jQuery);

Now you can input multiple CSS ids/classes into the scope field (comma-separated), and they will all be changed at the same time.

W.M.’s picture

Thanks dlsmore, I will test the suggested modifications in the near future

attheshow’s picture

Here are instructions on how to create a patch:
http://drupal.org/patch/create

W.M.’s picture

I have tried this but it looks like it is not working as specified..

Tyler the Creator’s picture

StatusFileSize
new10.85 KB

Hey, I believe that I've managed to fix #2's code. Let me know if this works..

si.mon’s picture

Status: Active » Needs review
StatusFileSize
new10.49 KB

Hey, I've managed to apply tpeppers patch and it seems to work.
I also changed the way the selectors are used. With the attached patch, classic jquery selectors can be used as for instance:
#main, .node-page p

Could someone take a look at this ?

si.mon’s picture

StatusFileSize
new10.67 KB

Woops, wrong patch sorry !
Fixed patch attached.

mrpauldriver’s picture

I am struggling to this working.

Can a patch be made available for 1.8?

socialnicheguru’s picture

Patch in #8 does not apply

git apply text_resize-js-7.x-1.7_1.patch
text_resize-js-7.x-1.7_1.patch:10: trailing whitespace.
attach: function(context) {
text_resize-js-7.x-1.7_1.patch:11: trailing whitespace.
var element_to_resize = [];
text_resize-js-7.x-1.7_1.patch:23: trailing whitespace.
var text_resize_scope_array = text_resize_scope.split(", ");
text_resize-js-7.x-1.7_1.patch:24: trailing whitespace.
for (i=0; i text_resize-js-7.x-1.7_1.patch:25: trailing whitespace.
if ($(text_resize_scope_array[i]).length > 0) {
fatal: corrupt patch at line 192

socialnicheguru’s picture

#2 does work

si.mon’s picture

Issue summary: View changes
StatusFileSize
new10.37 KB

Created a new patch file which should work.
I would really like to see this commited, could someone review this ?
Thanks :)

si.mon’s picture

Title: Please make it possible to define multiple identifiers inside Text Resize Scope field » Defining multiple selectors inside Text Resize Scope field
Version: 7.x-1.7 » 7.x-1.8
jannis’s picture

just about to post my own patch -- tried your patch in #12 -- all works well with v1.8 here. Nice work and thanks!

si.mon’s picture

Thanks for the feedback !
Could some else test it so we can change the status to RTBC ?

Tyler the Creator’s picture

Tested #12 with ids, classes and elements and everything worked as planned.

si.mon’s picture

Great thanks #16
Could you change this issue to RTBC ?

Tyler the Creator’s picture

Status: Needs review » Reviewed & tested by the community

Patch #12 tested by multiple users and looks good.

dcampos’s picture

Only the reset button needed some work.

I created some fields to enter the default values of line-height and font-size, separating it from minimum size field.

dcampos’s picture

Now the patch I've talked at #19

rcodina’s picture

Status: Reviewed & tested by the community » Needs work

@dcampos, reroll patch please, it needs to cleanly apply to dev branch. Thanks!

rcodina’s picture

I have rerolled patch to apply to dev, please review it.

rcodina’s picture

Status: Needs work » Needs review
rcodina’s picture

Sorry, patch on #22 doesn't correclty apply. Try this new one.

rcodina’s picture

Tyler the Creator’s picture

Status: Needs review » Reviewed & tested by the community

Blast from the past! I just tested this patch on a new site and it all works. Would be nice to get this committed one day.

Patch on #24 works with 7.x-1.9 and 7.x-1.x-dev.

Tyler the Creator’s picture

Version: 7.x-1.8 » 7.x-1.9
Tyler the Creator’s picture

Status: Reviewed & tested by the community » Needs work

Just realized that the patch removes the persistency of the resize when changing pages/reloading. Will have to look into seeing where that code it overwritten.

Tyler the Creator’s picture

Status: Needs work » Reviewed & tested by the community

Sorry for the spam... just realized that the cookie storing is now part of the config -_-;