tags:

views:

33

answers:

2

Hi, I have a javascript function for shrinking images but I dont want the shrinking function to work if an administrator logs in.

Here is part of the code

 function shrinkImages(){
 var i=0, maxWidth;
 //if (/^(?:artistnews|albums|news|exitnews|reviews)$/.test(arg(0))) maxWidth=236;
 if(typeof homepage != 'undefined') maxWidth=530;
 else maxWidth=236;
 var first = getElementsByClassName('first');
 if(first.length>1)
  first = first[0].getElementsByTagName('img');
 var imgs = document.getElementsByTagName('img');
 while(imgs[i]) {
  if(imgs[i].width > maxWidth && imgs[i].name!="shadow") {
   if (has(imgs[i], first) && maxWidth==236) {
    imgs[i].height = Math.round(521 * imgs[i].height / imgs[i].width);
    imgs[i].width = 521;
    i++;
    continue;
   }
   imgs[i].height = Math.round(maxWidth * imgs[i].height / imgs[i].width);
   imgs[i].width = maxWidth;
  }
  i++;
 }
 imgs = null;
+1  A: 

Define a Javascript variable called isAdmin and set it to true when an administrator logs in, then stick this at the beginning of that function...

if(isAdmin) return;
Josh Stodola
Will give it a try, thanks
Nichob
Please, how do i define the javascript variable "isAdmin" for more than one user? Thanks
Nichob
@Nichob I think you are asking way too much in one question here. I am not trying to sound rude or offensive, but do you have any idea what you are doing?
Josh Stodola
@Josh I dont have the idea, I am not a professional in jscript. I had this whole code that I should strink the images uploaded to the site and after doing that, I was told I need to include the admin and 2 other users as an exception for the rule.
Nichob
@Nichob So change the code to not execute for those users...? That has little to do with JScript, and more with your web site authentication. I don't know what else to tell you. I think you are clueless as to how the web site is currently working, and you just want to take a stab at implementing this change. I am afriad it doesn't work that way! And you can't just come to StackOverflow and have somebody else resolve your problem or you will never learn anything!
Josh Stodola
@Josh, Am on it... Thanks
Nichob
A: 
switch(userType || undefined) #Small update
{
   case 'admin':
      //Nothing
   break;
   case 'user':
   case undefined: /*user or unknown*/
      var imgs = document.getElementsByTagName('img');
      for(i=0;i<=imgs.lenght;i++)
      {
          if(imgs[i].width > maxWidth && imgs[i].name!="shadow")
          {
              //ETC, You know the rest
          }
      }
   break;
}

then within your html head do

var userType = 'admin'; // or w.e

And if you only define it for admin and dont define it for anyone else they still will get shrunk down

RobertPitt
Really worked and am very grateful, how can I give you a thumbs up of positive feedback?
Nichob
Just click the up arrow next to my comment, followed by the green Tick, and your very welcome.
RobertPitt