User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 375,222 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,193 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 2903 | Replies: 24 | Solved
Reply
Join Date: Oct 2005
Posts: 236
Reputation: Inny is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 5
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Firefox Compatibility help with script

  #11  
Apr 18th, 2008
I want to change Tactics, I want to alter this code

<script type='text/javascript'>
<!--
function ResizeThem(){
maxheight=250;
maxwidth= 250;
imgs=document.getElementsByTagName("img");
for (p=0; p<imgs.length; p++) {
if (imgs[p].getAttribute("alt")=="user posted image") {
w=parseInt(imgs[p].width);
h=parseInt(imgs[p].height);
if (parseInt(imgs[p].width)>maxwidth) {
imgs[p].style.cursor="pointer";
imgs[p].setAttribute('title','Reduced Image - Click to see full size');
imgs[p].onclick=new Function("iw=window.open(this.src,'ImageViewer','resizable=1,scrollbars=1');iw.focus()");
imgs[p].height=(maxwidth/imgs[p].width)*imgs[p].height;
imgs[p].width=maxwidth;}
if (parseInt(imgs[p].height)>maxheight) {
imgs[p].style.cursor="pointer";
imgs[p].onclick=new
Function("iw=window.open(this.src,'ImageViewer','resizable=1,scrollbars=1');iw.focus()");
imgs[p].width=(maxheight/imgs[p].height)*imgs[p].width;
imgs[p].height=maxheight;}}}}
ResizeThem()
//-->
</script>

So that it still reduces the images, but instead of opening them in a new window, they expand (floating) in the same window instead, Using the Code below.
I need to assign the reduced images as "ImageExpander"

function ImageExpander(oThumb, sImgSrc)
{
    // store thumbnail image and overwrite its onclick handler.
    this.oThumb = oThumb;
    this.oThumb.expander = this;
    this.oThumb.onclick = function() { this.expander.expand(); }
    
    // record original size
    this.smallWidth = oThumb.offsetWidth;
    this.smallHeight = oThumb.offsetHeight; 
 
    this.bExpand = true;
    this.bTicks = false;
    
    // self organized list
    if ( !window.aImageExpanders )
    {
        window.aImageExpanders = new Array();
    }
    window.aImageExpanders.push(this);
 
    // create the full sized image.
    this.oImg = new Image();
    this.oImg.expander = this;
    this.oImg.onload = function(){this.expander.onload();}
    this.oImg.src = sImgSrc;
}
 
ImageExpander.prototype.onload = function()
{
    this.oDiv = document.createElement("div");
    document.body.appendChild(this.oDiv);
    this.oDiv.appendChild(this.oImg);
    this.oDiv.style.position = "absolute";
    this.oDiv.expander = this;
    this.oDiv.onclick = function() {this.expander.toggle();};
    this.oImg.title = "Click to reduce.";
    this.bigWidth = this.oImg.width;
    this.bigHeight = this.oImg.height;
    
    if ( this.bExpand )
    {
        this.expand();
    }
    else
    {
        this.oDiv.style.visibility = "hidden";
        this.oImg.style.visibility = "hidden";
    }
}
ImageExpander.prototype.toggle = function()
{
    this.bExpand = !this.bExpand;
    if ( this.bExpand )
    {
        for ( var i in window.aImageExpanders )
            if ( window.aImageExpanders[i] !== this )
                window.aImageExpanders[i].reduce();
    }
}
ImageExpander.prototype.expand = function()
{
    // set direction of expansion.
    this.bExpand = true;
 
    // set all other images to reduce
    for ( var i in window.aImageExpanders )
        if ( window.aImageExpanders[i] !== this )
            window.aImageExpanders[i].reduce();
 
    // if not loaded, don't continue just yet
    if ( !this.oDiv ) return;
    
    // hide the thumbnail
    this.oThumb.style.visibility = "hidden";
    
    // calculate initial dimensions
    this.x = this.oThumb.offsetLeft;
    this.y = this.oThumb.offsetTop;
    this.w = this.oThumb.clientWidth;
    this.h = this.oThumb.clientHeight;
    
    this.oDiv.style.left = this.x + "px";
    this.oDiv.style.top = this.y + "px";
    this.oImg.style.width = this.w + "px";
    this.oImg.style.height = this.h + "px";
    this.oDiv.style.visibility = "visible";
    this.oImg.style.visibility = "visible";
    
    // start the animation engine.
    if ( !this.bTicks )
    {
        this.bTicks = true;
        var pThis = this;
        window.setTimeout(function(){pThis.tick();},25);    
    }
}
ImageExpander.prototype.reduce = function()
{
    // set direction of expansion.
    this.bExpand = false;
}
ImageExpander.prototype.tick = function()
{
    // calculate screen dimensions
    var cw = document.body.clientWidth;
    var ch = document.body.clientHeight;
    var cx = document.body.scrollLeft + cw / 2;
    var cy = document.body.scrollTop + ch / 2;
 
    // calculate target
    var tw,th,tx,ty;
    if ( this.bExpand )
    {
        tw = this.bigWidth;
        th = this.bigHeight;
        if ( tw > cw )
        {
            th *= cw / tw;
            tw = cw;
        }   
        if ( th > ch )
        {
            tw *= ch / th;
            th = ch;
        }
        tx = cx - tw / 2;
        ty = cy - th / 2; 
    }
    else
    {
        tw = this.smallWidth;
        th = this.smallHeight;
        tx = this.oThumb.offsetLeft;
        ty = this.oThumb.offsetTop;
    }   
    // move 5% closer to target
    var nHit = 0;
    var fMove = function(n,tn) 
    {
        var dn = tn - n;
        if ( Math.abs(dn) < 3 )
        {
            nHit++;
            return tn;
        }
        else
        {
            return n + dn / 10;
        }
    }
    this.x = fMove(this.x, tx);
    this.y = fMove(this.y, ty);
    this.w = fMove(this.w, tw);
    this.h = fMove(this.h, th);
    
    this.oDiv.style.left = this.x + "px";
    this.oDiv.style.top = this.y + "px";
    this.oImg.style.width = this.w + "px";
    this.oImg.style.height = this.h + "px";
 
    // if reducing and size/position is a match, stop the tick  
    if ( !this.bExpand && (nHit == 4) )
    {
        this.oImg.style.visibility = "hidden";
        this.oDiv.style.visibility = "hidden";
        this.oThumb.style.visibility = "visible";
 
        this.bTicks = false;
    }
    
    if ( this.bTicks )
    {
        var pThis = this;
        window.setTimeout(function(){pThis.tick();},25);
    }
}

normally you would write a thumbnail for this code like so

a href="spike.jpg" onclick="this.href = 'javascript:void(0);';">
        <img src="spike_thumb.jpg" title="click to expand." style="float:right;" onclick="new ImageExpander(this, 'spike.jpg');">
    </a>

Example of the code above here

http://www.webreference.com/programm.../ImageView.htm

I know I need to Alter this line in the first code both times

imgs[p].onclick=new
Function("iw=window.open(this.src,'ImageViewer','resizable=1  ,scrollbars=1');iw.focus()");

but im not sure how.
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
Reply With Quote  
Join Date: Oct 2005
Posts: 236
Reputation: Inny is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 5
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Firefox Compatibility help with script

  #12  
Apr 21st, 2008
How can parse an img url as query string to insert an image into a window on another domain?
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
Reply With Quote  
Join Date: Mar 2008
Location: Madrid - Spain
Posts: 20
Reputation: HenryGR is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 3
HenryGR's Avatar
HenryGR HenryGR is offline Offline
Newbie Poster

Re: Firefox Compatibility help with script

  #13  
Apr 21st, 2008
If you have the image on a server (whichever), just place the url on the "a" tag...

<a href="spike.jpg" onclick="this.href = 'javascript:void(0);';">
        <img src="http://www.myserver.com/images/spike_thumb.jpg" title="click to expand." style="float:right;" onclick="new ImageExpander(this, 'http://www.myserver2.com/images/spike.jpg');">
    </a>
You keep going, have a Nice day!
Henry.

Before printing this message, make sure is necessary.
Reply With Quote  
Join Date: Oct 2005
Posts: 236
Reputation: Inny is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 5
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Firefox Compatibility help with script

  #14  
Apr 21st, 2008
Sorry, I have confused this topic by suggesting an entirely different code.
It is the first code i posted that I wish to use, parsing the image url to a custom page on a new server.
please disregard post #11
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
Reply With Quote  
Join Date: Oct 2005
Posts: 236
Reputation: Inny is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 5
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Firefox Compatibility help with script

  #15  
Apr 22nd, 2008
The first code opens a new window, I want to use a custom window on another domain.
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
Reply With Quote  
Join Date: Oct 2005
Posts: 236
Reputation: Inny is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 5
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Firefox Compatibility help with script

  #16  
Apr 24th, 2008
Bump! does anyone understand me?
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
Reply With Quote  
Join Date: Oct 2005
Posts: 236
Reputation: Inny is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 5
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Firefox Compatibility help with script

  #17  
Apr 24th, 2008
can I rework the code to load the full size image in a hidden floating div above the page instead?
just add a close button to the div?
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
Reply With Quote  
Join Date: Sep 2005
Posts: 611
Reputation: digital-ether will become famous soon enough digital-ether will become famous soon enough 
Rep Power: 5
Solved Threads: 38
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Practically a Master Poster

Re: Firefox Compatibility help with script

  #18  
Apr 25th, 2008
Originally Posted by Inny View Post
How can parse an img url as query string to insert an image into a window on another domain?


You can't access the DOM of a window on another domain opened by your domain. This is a restriction that prevents XSS (cross/same domain policy)

If you own the other domain, then you can have PHP display the image by crafting a URL that tells it the image to display and dimensions.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote  
Join Date: Oct 2005
Posts: 236
Reputation: Inny is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 5
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Firefox Compatibility help with script

  #19  
Apr 25th, 2008
can I rework the code to load the full size image in a hidden floating div above the page instead?
just add a close button to the div?
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
Reply With Quote  
Join Date: Oct 2005
Posts: 236
Reputation: Inny is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 5
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Firefox Compatibility help with script

  #20  
Apr 26th, 2008
Bump!
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 3:34 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC