Firefox Compatibility help with script

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Oct 2005
Posts: 240
Reputation: Inny is an unknown quantity at this point 
Solved Threads: 6
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Firefox Compatibility help with script

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

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type='text/javascript'>
  2. <!--
  3. function ResizeThem(){
  4. maxheight=250;
  5. maxwidth= 250;
  6. imgs=document.getElementsByTagName("img");
  7. for (p=0; p<imgs.length; p++) {
  8. if (imgs[p].getAttribute("alt")=="user posted image") {
  9. w=parseInt(imgs[p].width);
  10. h=parseInt(imgs[p].height);
  11. if (parseInt(imgs[p].width)>maxwidth) {
  12. imgs[p].style.cursor="pointer";
  13. imgs[p].setAttribute('title','Reduced Image - Click to see full size');
  14. imgs[p].onclick=new Function("iw=window.open(this.src,'ImageViewer','resizable=1,scrollbars=1');iw.focus()");
  15. imgs[p].height=(maxwidth/imgs[p].width)*imgs[p].height;
  16. imgs[p].width=maxwidth;}
  17. if (parseInt(imgs[p].height)>maxheight) {
  18. imgs[p].style.cursor="pointer";
  19. imgs[p].onclick=new
  20. Function("iw=window.open(this.src,'ImageViewer','resizable=1,scrollbars=1');iw.focus()");
  21. imgs[p].width=(maxheight/imgs[p].height)*imgs[p].width;
  22. imgs[p].height=maxheight;}}}}
  23. ResizeThem()
  24. //-->
  25. </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"

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function ImageExpander(oThumb, sImgSrc)
  2. {
  3. // store thumbnail image and overwrite its onclick handler.
  4. this.oThumb = oThumb;
  5. this.oThumb.expander = this;
  6. this.oThumb.onclick = function() { this.expander.expand(); }
  7.  
  8. // record original size
  9. this.smallWidth = oThumb.offsetWidth;
  10. this.smallHeight = oThumb.offsetHeight;
  11.  
  12. this.bExpand = true;
  13. this.bTicks = false;
  14.  
  15. // self organized list
  16. if ( !window.aImageExpanders )
  17. {
  18. window.aImageExpanders = new Array();
  19. }
  20. window.aImageExpanders.push(this);
  21.  
  22. // create the full sized image.
  23. this.oImg = new Image();
  24. this.oImg.expander = this;
  25. this.oImg.onload = function(){this.expander.onload();}
  26. this.oImg.src = sImgSrc;
  27. }
  28.  
  29. ImageExpander.prototype.onload = function()
  30. {
  31. this.oDiv = document.createElement("div");
  32. document.body.appendChild(this.oDiv);
  33. this.oDiv.appendChild(this.oImg);
  34. this.oDiv.style.position = "absolute";
  35. this.oDiv.expander = this;
  36. this.oDiv.onclick = function() {this.expander.toggle();};
  37. this.oImg.title = "Click to reduce.";
  38. this.bigWidth = this.oImg.width;
  39. this.bigHeight = this.oImg.height;
  40.  
  41. if ( this.bExpand )
  42. {
  43. this.expand();
  44. }
  45. else
  46. {
  47. this.oDiv.style.visibility = "hidden";
  48. this.oImg.style.visibility = "hidden";
  49. }
  50. }
  51. ImageExpander.prototype.toggle = function()
  52. {
  53. this.bExpand = !this.bExpand;
  54. if ( this.bExpand )
  55. {
  56. for ( var i in window.aImageExpanders )
  57. if ( window.aImageExpanders[i] !== this )
  58. window.aImageExpanders[i].reduce();
  59. }
  60. }
  61. ImageExpander.prototype.expand = function()
  62. {
  63. // set direction of expansion.
  64. this.bExpand = true;
  65.  
  66. // set all other images to reduce
  67. for ( var i in window.aImageExpanders )
  68. if ( window.aImageExpanders[i] !== this )
  69. window.aImageExpanders[i].reduce();
  70.  
  71. // if not loaded, don't continue just yet
  72. if ( !this.oDiv ) return;
  73.  
  74. // hide the thumbnail
  75. this.oThumb.style.visibility = "hidden";
  76.  
  77. // calculate initial dimensions
  78. this.x = this.oThumb.offsetLeft;
  79. this.y = this.oThumb.offsetTop;
  80. this.w = this.oThumb.clientWidth;
  81. this.h = this.oThumb.clientHeight;
  82.  
  83. this.oDiv.style.left = this.x + "px";
  84. this.oDiv.style.top = this.y + "px";
  85. this.oImg.style.width = this.w + "px";
  86. this.oImg.style.height = this.h + "px";
  87. this.oDiv.style.visibility = "visible";
  88. this.oImg.style.visibility = "visible";
  89.  
  90. // start the animation engine.
  91. if ( !this.bTicks )
  92. {
  93. this.bTicks = true;
  94. var pThis = this;
  95. window.setTimeout(function(){pThis.tick();},25);
  96. }
  97. }
  98. ImageExpander.prototype.reduce = function()
  99. {
  100. // set direction of expansion.
  101. this.bExpand = false;
  102. }
  103. ImageExpander.prototype.tick = function()
  104. {
  105. // calculate screen dimensions
  106. var cw = document.body.clientWidth;
  107. var ch = document.body.clientHeight;
  108. var cx = document.body.scrollLeft + cw / 2;
  109. var cy = document.body.scrollTop + ch / 2;
  110.  
  111. // calculate target
  112. var tw,th,tx,ty;
  113. if ( this.bExpand )
  114. {
  115. tw = this.bigWidth;
  116. th = this.bigHeight;
  117. if ( tw > cw )
  118. {
  119. th *= cw / tw;
  120. tw = cw;
  121. }
  122. if ( th > ch )
  123. {
  124. tw *= ch / th;
  125. th = ch;
  126. }
  127. tx = cx - tw / 2;
  128. ty = cy - th / 2;
  129. }
  130. else
  131. {
  132. tw = this.smallWidth;
  133. th = this.smallHeight;
  134. tx = this.oThumb.offsetLeft;
  135. ty = this.oThumb.offsetTop;
  136. }
  137. // move 5% closer to target
  138. var nHit = 0;
  139. var fMove = function(n,tn)
  140. {
  141. var dn = tn - n;
  142. if ( Math.abs(dn) < 3 )
  143. {
  144. nHit++;
  145. return tn;
  146. }
  147. else
  148. {
  149. return n + dn / 10;
  150. }
  151. }
  152. this.x = fMove(this.x, tx);
  153. this.y = fMove(this.y, ty);
  154. this.w = fMove(this.w, tw);
  155. this.h = fMove(this.h, th);
  156.  
  157. this.oDiv.style.left = this.x + "px";
  158. this.oDiv.style.top = this.y + "px";
  159. this.oImg.style.width = this.w + "px";
  160. this.oImg.style.height = this.h + "px";
  161.  
  162. // if reducing and size/position is a match, stop the tick
  163. if ( !this.bExpand && (nHit == 4) )
  164. {
  165. this.oImg.style.visibility = "hidden";
  166. this.oDiv.style.visibility = "hidden";
  167. this.oThumb.style.visibility = "visible";
  168.  
  169. this.bTicks = false;
  170. }
  171.  
  172. if ( this.bTicks )
  173. {
  174. var pThis = this;
  175. window.setTimeout(function(){pThis.tick();},25);
  176. }
  177. }

normally you would write a thumbnail for this code like so

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. a href="spike.jpg" onclick="this.href = 'javascript:void(0);';">
  2. <img src="spike_thumb.jpg" title="click to expand." style="float:right;" onclick="new ImageExpander(this, 'spike.jpg');">
  3. </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

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. imgs[p].onclick=new
  2. 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 Quick reply to this message  
Join Date: Oct 2005
Posts: 240
Reputation: Inny is an unknown quantity at this point 
Solved Threads: 6
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Firefox Compatibility help with script

 
0
  #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 Quick reply to this message  
Join Date: Mar 2008
Posts: 24
Reputation: HenryGR is an unknown quantity at this point 
Solved Threads: 4
HenryGR's Avatar
HenryGR HenryGR is offline Offline
Newbie Poster

Re: Firefox Compatibility help with script

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

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <a href="spike.jpg" onclick="this.href = 'javascript:void(0);';">
  2. <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');">
  3. </a>
You keep going, have a Nice day!
Henry.

Before printing this message, make sure is necessary.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 240
Reputation: Inny is an unknown quantity at this point 
Solved Threads: 6
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Firefox Compatibility help with script

 
0
  #14
Apr 22nd, 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 Quick reply to this message  
Join Date: Oct 2005
Posts: 240
Reputation: Inny is an unknown quantity at this point 
Solved Threads: 6
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Firefox Compatibility help with script

 
0
  #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 Quick reply to this message  
Join Date: Oct 2005
Posts: 240
Reputation: Inny is an unknown quantity at this point 
Solved Threads: 6
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Firefox Compatibility help with script

 
0
  #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 Quick reply to this message  
Join Date: Oct 2005
Posts: 240
Reputation: Inny is an unknown quantity at this point 
Solved Threads: 6
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Firefox Compatibility help with script

 
0
  #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 Quick reply to this message  
Join Date: Sep 2005
Posts: 1,082
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Firefox Compatibility help with script

 
0
  #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 Quick reply to this message  
Join Date: Oct 2005
Posts: 240
Reputation: Inny is an unknown quantity at this point 
Solved Threads: 6
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Firefox Compatibility help with script

 
0
  #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 Quick reply to this message  
Join Date: Oct 2005
Posts: 240
Reputation: Inny is an unknown quantity at this point 
Solved Threads: 6
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Firefox Compatibility help with script

 
0
  #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 Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC