Legacy Trying to make Enlarge checkbox persistent

Status
Not open for further replies.

Rick

Customer
I am trying to make the Enlarge function persistent using cookies and javascript.

I have modified the body statement in the dbtech_gallery template to:

<body onload="DBTech_Gallery.check_enlarge();">

I have also modified/added some code to gallery.js
Code:
this.toggle_enlarge=function(small_w,large_w)
{
   if(fetch_object('gallery_enlarge_toggle').checked)
      {
      createCookie('fsd_enlarge', 'true', '365');
      document.getElementById("full_image").style.width=large_w+"px";
      document.getElementById("gallery_enlarge_toggle").checked = true;
      }
   else
      {
      createCookie('fsd_enlarge', 'false', '365');
      document.getElementById("full_image").style.width=small_w+"px";
      document.getElementById("gallery_enlarge_toggle").checked = false;
      }
};


this.check_enlarge=function()
{
   var enlarge = readCookie('fsd_enlarge');

   if (enlarge === 'true')
      {
      document.getElementById("full_image").style.width=large_w+"px";
      document.getElementById("gallery_enlarge_toggle").checked = true;
      }
   else
      {
      document.getElementById("full_image").style.width=small_w+"px";
      document.getElementById("gallery_enlarge_toggle").checked = false;
      }
};

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 var 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;
}

The code correctly updates the cookie and the Enlarge toggles as expected.
The problem I am having is that the "onload" in the body statement, doesn't
seem to toggle it to the correct state when a new page is loaded if the cookie
is set. I am not getting any errors though. I thought that someone with more
javascript experience might be able to tell me what I am doing wrong or why
it doesn't work correctly.

Thank you for reading!
Rick
 
Upvote 0
This suggestion has been closed. Votes are no longer accepted.
Add some debug output to your readCookie function, that's most likely the problem.
 
Thank you for your help!

In my test code I used an alert function in the check_enlarge function and it does
properly report the cookie state.

Code:
   if (enlarge === 'true')
      {
   alert("large");
      document.getElementById("full_image").style.width=large_w+"px";
      document.getElementById("gallery_enlarge_toggle").checked = true;
      }
   else
      {
   alert("small");
      document.getElementById("full_image").style.width=small_w+"px";
      document.getElementById("gallery_enlarge_toggle").checked = false;
      }

However, it doesn't check the checkbox and perform the toggle if needed.
 
Now I think I see the problem. small_w and large_w are not defined in the
check_enlarge function. Is there a way to get this info to pass to it from the
onload command?
 
update: I added this line as the last line of dbtech/gallery/modules/gallery/actions/view_image.php
It is right after the code to build the dbtech_gallery_view_image[_vb]
Code:
vB_Template::preRegister('dbtech_gallery',array('main_image' => $main_image));
I then changed the body code in dbtech_gallery template to:
Code:
<body <vb:if condition="$preload_images">onLoad="preload();"</vb:if> onload="DBTech_Gallery.check_enlarge({vb:raw image_data.box_new_width}, {vb:raw image_data.box_full_width});">
I am still getting null results for the vb:raw values....
Any ideas? Thank you!
 
Last edited:
I can't see anything immediately wrong, and this is really beyond what we're able to assist with unfortunately :(
 
Status
Not open for further replies.
Top